Hello everyone,
I try to create a workflow for an automated solving of clashes by moving elements or parts of it.
In my example I have a mobile crane and i can move the “arm” up and down by changing the angle.
With python I created a “While” loop until a boolean variable, indicating whether a clash exists or not, is “False”.
In this loop I change the angle by +1° and set the new value with the Transaction methods. Then, I check again, if a clash occurs.
The angle changes every time, but even if the crane’s arm is higher than the wall, unfortunately, the boolean variable does not change.
My theory is that with x1 = doc.GetElement(ElementId(1248947)).ToDSType(True)
the code select every time the original element and ignore the “new” one with the changed angle.
Can anyone tell me how to tell the script/method, that the selected element has changed parameters and has to be recalculated with different circumstances?
This is the result when I just check if a clash exist
Here, the clash does not exist anymore, but the boolean variable “ClashExists” is still true…
import sys
sys.path.append(....\Dynamo Revit\2.3\packages\bimorphNodes\bin')
import clr
clr.AddReference('ProtoGeometry')
from Autodesk.DesignScript.Geometry import *
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 *
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
#Creating Lists with specific Type for usage BimorphNode
elementsListA = List[Revit.Elements.Element]()
elementsListB = List[Revit.Elements.Element]()
x1 = doc.GetElement(ElementId(1248947)).ToDSType(True)
y2 = doc.GetElement(ElementId(1254250)).ToDSType(True)
elementsListA.Add(x1)
elementsListB.Add(y2)
ListClashExist = []
counter = 1
#Check the clash
stillClash = Bimorph.IntersectsElement(elementsListA,elementsListB)
inter_Element = stillClash['Element[][]'][0][0]
if inter_Element == []:
ClashExists = False
else:
ClashExists = True
#Remove the aboce selected element, having an empty list for the while loop
elementsListA.Remove(x1)
for i in UnwrapElement(x1).Parameters:
if i.Definition.Name == 'Auslegerwinkel':
actualValue_Rad = i.AsDouble()
p = UnwrapElement(x1).LookupParameter('Auslegerwinkel')
while (ClashExists == True):
actualValue_Rad = actualValue_Rad + 3.14159265/180
#Trasnsaction for Revit
TransactionManager.Instance.EnsureInTransaction(doc)
p.Set(actualValue_Rad)
TransactionManager.Instance.TransactionTaskDone()
#Select updated element with changed parameter value
x1new = doc.GetElement(ElementId(1248947)).ToDSType(True)
#add the updated element
elementsListA.Add(x1new)
#Check clash again, but with new element
stillClash = Bimorph.IntersectsElement(elementsListA,elementsListB)
inter_Element = stillClash['Element[][]'][0][0]
if inter_Element == []:
ClashExists = False
#Track the solution of the Intersect method. It should be the wall until the arm is high enough
ListClashExist.append(inter_Element)
# clean the list for the next itaration
elementsListA.Remove(x1new)
#avoid an infinite loop
counter = counter + 1
if counter > 20: break
OUT = ClashExists, stillClash, ListClashExist