Dynamo Python Resolving a clash

Hello everybody,
i am relatively new to Python and i need some help after investigating hours and hours for a solution.
I try to resolve a clash with a python node in dynamo.
I have a mobile crane(loadable family) which can be controlled with some parameters. The angle of the crane’s arm can be changed via the parameter “Auslegerwinkel”. I achieved a changing of the value with the python code once, but i want to iterate over a loop, change the degree by +1 and check every time, if the change of the angle resolves the clash. If so, the method should stop.
I imported the bimorphnode for using the ElementsIntersect method, but every time I run the script I get the following error:

Type Error: “expected List[Element], got FamilyInstance”

Can someone explain to me, what am I missing here?

Yep you need to provide a .NET list rather than a python list.

So your element lists need to be declared like this to initialize the required type:
elementsListA = List[Element](element1)

Also your element1 etc should be renamed elements1 given its a list! If its not then the above will still fix your problem.

Thank you for your response @Thomas_Mahon
I tried to change the code but now I got another ErrorMessage which confuses me…

Did I something wrong? The first Inmput(Crane) is a nested family and the second one is a simple wall.
Has it something to do with that?

    import sys
sys.path.append(...bimorphNodes\bin')

import clr

clr.AddReference('BimorphNodes')
from Revit import Element

clr.AddReference('RevitAPI')
from Autodesk.Revit.DB import *
from Autodesk.Revit.DB.Structure import *

clr.AddReference('RevitAPIUI')
from Autodesk.Revit.UI import *

clr.AddReference('System')
from System.Collections.Generic import List

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
uiapp = DocumentManager.Instance.CurrentUIApplication
app = uiapp.Application
uidoc=DocumentManager.Instance.CurrentUIApplication.ActiveUIDocument



#Preparing input from dynamo to revit
el1 = UnwrapElement(IN[0])
el2 = UnwrapElement(IN[1])
d = IN[2]
ClashExists = True
Lel1 = List[Element](el1)
"""
Lel2 = List[Element](el2)
if (len(ListElement1) == 0 or len(ListElement2) == 0):
	ClashExists = False
"""
if ClashExists:
	for i in el1[0].Parameters:
		if i.Definition.Name == 'Auslegerwinkel':
			actualValue = i.AsValueString()
	p = el1[0].LookupParameter('Auslegerwinkel')
	TransactionManager.Instance.EnsureInTransaction(doc)
	p.Set(d*3.14159265/180)
	stillClash = Revit.Element.IntersectsElement(Lel1,el2)
	TransactionManager.Instance.TransactionTaskDone()
	
OUT = stillClash

Its most likely an ambiguous reference between Dynamos Revit.Element and the Revit API Element.

Try qualifying the class or using an alias in your import:

elementsListA = List[Autodesk.Revit.DB.Element](element1)

This is best:

clr.AddReference("RevitAPI")
import Autodesk
from Autodesk.Revit.DB import *
from Autodesk.Revit.DB import Element as RevitElement

then its a lot more elegant to declare:

elementsListA = List[RevitElement]()
elementsListA.Add(element1)

or a halfway house, alias the Revit API namespace:
import Autodesk.Revit.DB as RevitDB

elementsListA = List[RevitDB.Element]()
elementsListA.Add(element1)

I implemented your advice but it does not solve the error message

Now I had to add the [0] to the .Add method(line47/48), because without i got always the error “TypeError: expected Element, got List[Object]”
Using the indices for the lists ([0]) the message does not occur anymore. But in the end, there ist still the message from my second post

Or do you have maybe another idea, how to reach my goal of checking a clash everytime I change my parameter?

Oh its because the BimorphNode element expects Dynamo Revit elements not Revit API elements :man_facepalming:

So pass in the wrapped element(s) into your clash list. Also, change the namespace qualification to Revit.Elements.Element

so cool :smiley:

I had a solution, the Output of my Script looked exactly like the Output of your ZeroTouchNode.
Unfortunately, I was so happy about the solution and forgot to save the code… and after some other steps, Dynamo crashed. I made a screenshot of the code but the beginning is missing.
I recreated the code, but the Error Message occured again.
I post here my screenshot.

In the beginning I also changed the lines 4/5 to :

clr.AddReference('BimorphNodes')
from Revit import Element as Bimorph

Then, typing Bimorph. I could directly select the method “IntersectsElement”

Maybe this information is useful:
The input for my script is the Output of the BimorphNode Element.IntersectsElement and I flatten the Element input before.
Here i tried to write the essential lines again, but another Error occured…

It’s done! I think I misunderstood the thing with the namespace. I am not familiar with all the vocabulary, how i mentioned I before I just started coding weeks ago.
So I changed the two lines with the definition of the Line[Element] to Line[Revit.Elements.Element]

Code and screenshot are uploaded too.

Thank you @Thomas_Mahon for your time and help!

import sys
sys.path.append(path....\bimorphNodes\bin')

import clr

clr.AddReference('BimorphNodes')
from Revit import Element as Bimorph

clr.AddReference('RevitAPI')
import Autodesk
from Autodesk.Revit.DB import *
from Autodesk.Revit.DB import Element as RevitElement

clr.AddReference('RevitAPIUI')
from Autodesk.Revit.UI import *

clr.AddReference('System')
from System.Collections.Generic import List

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
uiapp = DocumentManager.Instance.CurrentUIApplication
app = uiapp.Application
uidoc=DocumentManager.Instance.CurrentUIApplication.ActiveUIDocument

el1 = UnwrapElement(IN[0][0]) 
el2 = UnwrapElement(IN[1][0]) 
d = IN[2]
ClashExists = True

elementsListA = List[Revit.Elements.Element]()
elementsListB = List[Revit.Elements.Element]()

elementsListA.Add(IN[0][0])
elementsListB.Add(IN[1][0])

stillClash = Bimorph.IntersectsElement(elementsListA,elementsListB)
OUT = stillClash
"""
#if (len(IN[0]) == 0 or len(IN[1]) == 0):ror
#	ClashExists = False



for i in el1.Parameters:
	if i.Definition.Name == 'Auslegerwinkel':
		actualValue = i.AsDouble()
		
	p = el1.LookupParameter('Auslegerwinkel')
	
	TransactionManager.Instance.EnsureInTransaction(doc)
	while(ClashExists == True):
		actualValue = actualValue + 1
		p.Set(actualValue*3.14159265/180)
		sillClash = Bimorph.IntersectsElement(elementsListA,elementsListB)
		if (len(StillClash) == 0): ClashExists = False
	TransactionManager.Instance.TransactionTaskDone()
	
	
test = FilteredElementCollector(doc).OfCategory(BuiltInCategory.OST_GenericModel).WhereElementIsNotElementType().ToElements()

#Preparing input from dynamo to revit
	"""
2 Likes