Reputation: 81
I'm trying to write a Python script within Dynamo for Revit that places FamilyInstances given a family symbol, an insertion point, rotation angle, and work plane.
So far, my script works as expected with the exception that it places every FamilyInstance multiple times in the same location and I can't work out why. The symbol and reference plane are singular objects (they stay the same for every placed instance) while the insertion points and rotation angles change for every new instance. I'm using a zip
to return tuples of these, and then iterating over them to place the new family instances:
import clr
clr.AddReference('RevitNodes')
import Revit
clr.ImportExtensions(Revit.GeometryConversion)
from Revit.Elements import *
clr.AddReference('System')
from System.Collections.Generic import *
clr.AddReference('RevitAPI')
from Autodesk.Revit.DB import *
clr.AddReference('RevitServices')
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager
doc = DocumentManager.Instance.CurrentDBDocument
uiapp = DocumentManager.Instance.CurrentUIApplication
app = uiapp.Application
#The inputs to this node will be stored as a list in the IN variables.
dataEnteringNode = IN
symbol = UnwrapElement(IN[0])
refPlane = UnwrapElement(IN[1])
locations = []
for i in IN[2]:
locations.append(UnwrapElement(i).ToXyz())
referenceDirections = []
for i in IN[3]:
referenceDirections.append(UnwrapElement(i).ToXyz())
out = []
symbol.Activate()
reference = Reference(refPlane)
TransactionManager.Instance.EnsureInTransaction(doc)
for location, direction in zip(locations, referenceDirections):
new = doc.Create.NewFamilyInstance(reference,location,direction,symbol)
out.append(new)
TransactionManager.Instance.TransactionTaskDone()
#Assign your output to the OUT variable.
OUT = out
After running the script, the out
variable returns the correct number of element ids (same as the input), while the actual elements created in Revit are a multiple of that number. What am I missing?
Upvotes: 0
Views: 23