A short post today showing a method to created a floor in Dynamo with an opening inside. It is not possible as of today to create complex floor sketches with Revit API – meaning containing more than one loop.
So instead we are first creating a floor from the first curve loop and then we add an opening to it. Pretty straightforward. The only catch here is to use two transactions per floor. We have to commit a transaction to push newly created floor to the Revit document. Only then we can add an opening to it.
In order to avoid mess I am wrapping everything into a single transaction group. Check the code below and .dyn file at the very end.
The Python node takes two inputs: first one is a list of floor borders, second a list of opening curves.
# Enable Python support and load DesignScript library import clr clr.AddReference("RevitAPI") from Autodesk.Revit.DB import * import Autodesk clr.AddReference("RevitServices") import RevitServices from RevitServices.Persistence import DocumentManager clr.AddReference("RevitNodes") import Revit clr.ImportExtensions(Revit.GeometryConversion) borders = UnwrapElement(IN) holes = UnwrapElement(IN) output= doc = DocumentManager.Instance.CurrentDBDocument tg=TransactionGroup(doc, 'Floors') tg.Start() for b,h in zip(borders,holes): border = CurveArray() for c in b: border.Append(c.ToRevitType()) t0 = Transaction(doc, 'Floor border') t0.Start() floor = doc.Create.NewFloor(border,False) t0.Commit() hole = CurveArray() for c in h: hole.Append(c.ToRevitType()) t1 = Transaction(doc, 'Floor hole') t1.Start() opening = doc.Create.NewOpening(floor,hole,True) t1.Commit() output.append([floor,opening]) tg.Assimilate() # Assign your output to the OUT variable. OUT = output