ITM Hanger modification in Revit

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?

Class_Handout_FAB322869_Travis_Voss.pdf (1.7 MB)

Hanger Script (From .pdf).dyn (54.4 KB)

Hi @ryoungerK49U2

Could you share a sample RVT file so that other forum members can help you more easily?

I can not link the .rvt as the file is too large but attached is the .pdf I am working from and a screen shot of the test model.

Attached is also a sample of my .dyn so far.

Here is a list of add-ons I am using.

Hi,

Here is an example

ITM Hanger modification

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
2 Likes

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?

I think the code works with any hanger.

My python block is using CPython3 and is saying there is an error on line 34.

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.

1 Like

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.

Thank you I am really struggling here its my first real project in dynamo.

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“.

Not sure if i understand the problem.

Nothing has to happen after you hit select.
You only need to select the Elements and then click run afterwards.

Or did you do that?

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.

Post a sample RVT with three hangers and your current DYN and I’ll have a look at it.

I only get a 10mb upload my sample RVT is to large. Attached to this response is my .dyn Thanks again for the help!

Hanger Script.dyn (9.3 KB)

  1. Open detached
  2. Purge everything you can
  3. Delete all materials and assets
  4. Delete all views but one 3D view
  5. Purge unused again
  6. Save as a new file

If it is still too large to post, use a 3rd party service like Dropbox, google drive, box, onedrive, wetransfer, etc..

1 Like