Python script placing elements more than once

Hi everyone,

I am currently working on a python script in Dynamo to place families given an insertion point and work plane. My results so far have been promising, but my the script I’m using now has the tendency to sporadically place elements multiple times in the same place and I can’t work out what I’m missing. Here is my script:

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

Any help would be greatly appreciated.

Hey,

It looks fine, so it’s about debugging… Which is probably to do with the data structures… You are only placing 1 family, so that’s not a problem, neither is your reference. So something in your other 2 lists is causing a duplicate. Probably a duplicate location from somewhere.

I would tend to output all your variables and lists to make sure they are aligned, with a simple test file so you can see the strangeness more easily…

Hope that helps,

Mark

Could also be that you’re circumventing element binding, so if you runt he graph twice with the same input you’ll get duplicate instances.

2 Likes

@jacob.small That could very well be the problem. My debugging efforts have shown that the in- and outputs of the script are as expected. Is there a way to make my script respect the element binding?

Check the linked post and my AU class from 2019 for what I know about Element Binding.

2 Likes