I am attempting to make a dynamo script that can modify selected (itm) hangers and then adjust length of rod in a model. Does anyone have any ideas or advice? I am pretty sure that I will need a python script for modifying an itm in revit but am pretty useless at python?
import clr
import sys
import System
#
clr.AddReference('ProtoGeometry')
from Autodesk.DesignScript.Geometry import *
import Autodesk.DesignScript.Geometry as DS
#import Revit API
clr.AddReference('RevitAPI')
import Autodesk
from Autodesk.Revit.DB import *
import Autodesk.Revit.DB as DB
#import transactionManager and DocumentManager (RevitServices is specific to Dynamo)
clr.AddReference('RevitServices')
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager
doc = DocumentManager.Instance.CurrentDBDocument
toList = lambda x : x if hasattr(x, "__iter__") and not isinstance(x, (str, System.String)) else [x]
#Preparing input from dynamo to revit
lstelems = toList(UnwrapElement(IN[0]))
length_rod = IN[1] * 3.28084 # convert meter to feet
#Do some action in a Transaction
TransactionManager.Instance.EnsureInTransaction(doc)
for elem_part in lstelems:
rod_info = elem_part.GetRodInfo()
rod_info.CanRodsBeHosted = False
rod_info.SetRodLength(0, length_rod)
TransactionManager.Instance.TransactionTaskDone()
new_rod_lenght = rod_info.GetRodLength(0) * 0.3048
OUT = lstelems , new_rod_lenght
Thats amazing. You made more progress in a few days than I have in a few weeks. The only step left would be to adapt the code to work on our libraries correct? Or am I misunderstanding something?
You donât have an object at that point. The instance which you are asking to âGetRodInfoâ from doesnât exist.
Context is a must for debugging. What is line 34 in your code? Assuming itâs the same as Cyril posted it is possible that you have provided a ânullâ or âempty listâ into the Python node. Clear those out.
Can you confirm what inputs you have coming into IN[0] of the python node? My gut tells me you have something other than a hanger selected at some point, but we need the larger context leading into the Python node to confirm.
You havenât selected hangers with the select model elements nodes.
Hit the button that says âselectâ on the first Select Model Element node and pick a hanger. Then do so again for the second. Then run the graph again and see if the Python gives a better result.
The issue there is when I hit select absolutely nothing happens in dynamo or revit. For some reason the select button doesnât seem to do anything. It seems to be âgreyed outâ.
If I click on select and then click an element nothing loads. The select button appears to be dead. I donât know why it wont let me select an element? Iâve never had this issue before.