Revit 2014 Macros in Ruby

Does it seem like all the cool kids are coding in Ruby these days?

If you want to be cool like them, here is a quick overview on how you can get started creating Revit macros in Ruby, a new feature in the 2014 API. I’m not sure there is anything you can do with Ruby that you can’t do in C#, but according to some people Ruby is more fun.

Advertisements

10 thoughts on “Revit 2014 Macros in Ruby

  1. Hi Harry i have a question i want to make copy of wall into specific distance by using revit macro
    public void MoveWall()
    {
    Document doc = this.ActiveUIDocument.Document;
    //Define a Reference object to accept the pick result.
    Reference pickedRef = null;
    //Pick a Wall
    Selection sel = this.ActiveUIDocument.Selection;
    pickedRef = em as Wall;

    //Pick a pointsel.PickObject(ObjectType.Element, “Please select a wall”);
    Element elem = doc.GetElement(pickedRef);
    Wall wall = el
    XYZ point = sel.PickPoint(“Please pick a point to place wall”);

    Transaction trans = new Transaction(doc);
    trans.Start(“Lab”);
    ElementTransformUtils.copyElement(point, wall.WallType);
    trans.Commit();

    }
    }
    }

    the problem here is in the element transformunits that tells me no overload for copyelement i want to make copy of wall by specific distance how i can make it ?

  2. #region Namespaces
    using System;
    using System.Collections.Generic;
    using System.Diagnostics;
    using Autodesk.Revit.ApplicationServices;
    using Autodesk.Revit.Attributes;
    using Autodesk.Revit.DB;
    using Autodesk.Revit.UI;
    using Autodesk.Revit.UI.Selection;
    #endregion

    namespace CopyWall
    {
    [Transaction(TransactionMode.Manual)]
    public class Command : IExternalCommand
    {
    public Result Execute(
    ExternalCommandData commandData,
    ref string message,
    ElementSet elements)
    {
    UIApplication uiapp = commandData.Application;
    UIDocument uidoc = uiapp.ActiveUIDocument;
    Application app = uiapp.Application;
    Document doc = uidoc.Document;

    // Access current selection

    Selection sel = uidoc.Selection;
    //Define a Reference object to accept the pick result.
    Reference pickedRef = null;

    //Pick a wall

    pickedRef = sel.PickObject(ObjectType.Element, “Please select a wall”);
    Element elem = doc.GetElement(pickedRef);
    Wall wall = elem as Wall;

    //Pick a point
    XYZ point = sel.PickPoint(“Please pick a point to place wall”);

    //Place the new instance of wall
    Transaction trans = new Transaction(doc);
    trans.Start(“Lab”);
    ElementTransformUtils.CopyElement(point, wall.WallType);
    trans.Commit();
    }
    }
    }

    It did not work although using intellisense in making CopyElement
    here is shot of error

  3. If you don’t already have the Revit API help file, I’d recommend downloading it at https://boostyourbim.wordpress.com/2013/02/16/download-links-for-the-revitapi-help-files/

    The documentation for CopyElement shows that it has 3 required inputs

    ElementTransformUtils..::..CopyElement Method
    public static ICollection CopyElement(
    Document document,
    ElementId elementToCopy,
    XYZ translation
    )

    Parameters

    document
    Type: Autodesk.Revit.DB..::..Document
    The document that owns the element.

    elementToCopy
    Type: Autodesk.Revit.DB..::..ElementId
    The id of the element to copy.

    translation
    Type: Autodesk.Revit.DB..::..XYZ
    The translation vector for the new element.

  4. Good info harry, what i knew that i can obtain the elementid of wall through lookup utility but what about translation of xyz i do not know how to make the programme read coordinate and then copy to new coordinate.

  5. i tried the implementation of the method that is provided just error shows up again 😦
    as in the picture

    The purpose of this macro to make copy of wall (similar to offset).

  6. the element id when i looked in revit lookup is a integer number so i put it there before category to make casting is that right or there another different procedure ?

    -about parentheses it wants from me to put it after xyz and before the variable called translationvector ?
    -the invalid expression term highlighting after variable called translation vecto and before parentheses.
    -The semi colon want to be inserted after variable translationvector O_o(surprise!)
    Which in case i put all of this in attempt to correct errors i will cause another many errors.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s