The macro functionality in Revit is incredibly powerful, offering two key advantages. First, macros can be saved directly within the project file. This means that when the file is shared, others can use the pre-written macros without needing to install additional tools. Second, for developing simple functions or conducting feasibility studies, using macros directly is often more straightforward and convenient than working with other IDEs.
Below is an example of a Revit macro written in C#. Simply copy the essential code into ThisDocument, run the macro, and it will assign elevation parameter data from electrical device family instances based on faces visible in the current view. This data is stored in the parameter named Point Height Sharing Parameter for later height annotation.
public void GetHeight()
{
FilteredElementCollector fec = new FilteredElementCollector(Document, ActiveView.Id);
fec.OfCategory(BuiltInCategory.OST_ElectricalFixtures).WhereElementIsNotElementType();
using (Transaction tran = new Transaction(Document, "GetHeight"))
{
tran.Start();
foreach (FamilyInstance fi in fec)
{
var para1 = fi.GetParameters("立面");
var para2 = fi.GetParameters("点位高度");
if (para1.Count > 0 && para2.Count > 0)
{
para2[0].Set(para1[0].AsDouble());
}
}
tran.Commit();
}
}













Must log in before commenting!
Sign Up