API Tips when using PowerShell and Parameter Sync

While attempting to use the Revit API in the PowerShell scripting functionality, there are a few tips to keep in mind.

#1. Write it first as a macro to debug the code

This will also allow you to receive Intellisense as well. Once in working order, convert it to PowerShell Syntax.


var e = doc.GetElement(eid);
var pntId = ((FamilyInstance)e).GetSubComponentIds().FirstOrDefault(id => doc.GetElement(id).Name.Contains("Point"));
var pnt = doc.GetElement(pntId);
Parameter oHosParameter = e.LookupParameter("eM_Service Name");
Parameter oNestedParameter = pnt.LookupParameter("eM_Service Name");
if (string.IsNullOrEmpty(oNestedParameter.AsString()))
Parameter pntdesc = e.LookupParameter("eM_Point Description");
if (string.IsNullOrEmpty(pntdesc.AsString()))
pntdesc.Set(e.LookupParameter("Family").AsValueString() + e.LookupParameter("Size").AsString());
$doc = $eVolveElement.Document

$Max = $eVolveElement.get_BoundingBox($doc.ActiveView).Max

$Min = $eVolveElement.get_BoundingBox($doc.ActiveView).Min

$eloc = $Max + $Min / 2

$room = $doc.GetRoomAtPoint($eloc)
$roomname = $room.LookupParameter('Name')

return $roomname.AsString()

Always try going higher in the hierarchy

When experiencing seemingly unknown problems, always try to go higher in the hierarchy call being used. An example is below for reference.


Instead of

How did we do?

Powered by HelpDocs (opens in a new tab)