Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Example of multiple floors creation for a given list of levels
import clr
clr.AddReference('ProtoGeometry')
from Autodesk.DesignScript.Geometry import *
clr.AddReference('RevitAPI')
from Autodesk.Revit.DB import *
clr.AddReference('RevitNodes')
import Revit
clr.ImportExtensions(Revit.GeometryConversion)
clr.ImportExtensions(Revit.Elements)
clr.AddReference('RevitServices')
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager
doc = DocumentManager.Instance.CurrentDBDocument
#Preparing input from dynamo to revit
lines = IN[0].ToRevitType()
floorType = UnwrapElement(IN[1])
levels = IN[2]
isStructural = IN[3]
randomNumbers = IN[4]
boundary = CurveArray()
#Filling the CurveArray
for i in lines:
boundary.Append(i)
#Here we will store the created floors
floors = []
#Do the action in a Transaction
TransactionManager.Instance.EnsureInTransaction(doc)
for level, randomRotation in zip(levels,randomNumbers):
floor = doc.Create.NewFloor(boundary,floorType,UnwrapElement(level),isStructural)
floorOffset = floor.get_Parameter(BuiltInParameter.FLOOR_HEIGHTABOVELEVEL_PARAM)
floorOffset.Set(0)
ElementTransformUtils.RotateElement(doc,floor.Id,Line.CreateBound(XYZ(0,0,0),XYZ(0,0,1)),randomRotation*360)
floors.append(floor)
TransactionManager.Instance.TransactionTaskDone()
OUT = floors
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment