Pick new host rebar


pick new host rebar?

Hello! Here is the anwer:

http://www.revitapidocs.com/2018.1/79da5994-50ed-171f-adf2-9a6550c898db.htm

Can you help me creat node?

It depends on how much help you need.

You need two inputs, let’s name them rebarElement and hostElement

Then between transaction start and commit write something like this:

rebarElement.SetHostId(doc, hostElement.Id)

1 Like


Can you help me write this node?

If you need help to review something wrong in your code, you will find here how to paste what you have done so far:

I tried to do the same thing as pvhuyg and it seems that my Dynamo script can’t access the attribute SetHostID
It also couldn’t get the ID of the desired host element with “hostElement.id”

Is there anything im missing out in the Code?

Edit/Update 1: i found out the element im trying to feed into the Python Script is a RebarInSystem class not the RebarClass. Unfortunately the RebarInSystem class does not provide a SetHostId Method. Still trying to figure out to make it work :confused:

# Phython-Unterstützung aktivieren und DesignScript-Bibliothek laden
import clr
clr.AddReference('RevitAPI')
import Autodesk
from Autodesk.Revit.DB import *
import System

clr.AddReference('RevitNodes')
import Revit
clr.ImportExtensions(Revit.Elements)

clr.AddReference('RevitServices')
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager
doc = DocumentManager.Instance.CurrentDBDocument
TransactionManager.Instance.EnsureInTransaction(doc)


# Die Eingaben für diesen Block werden in Form einer Liste in den IN-Variablen gespeichert.
rebarElement = UnwrapElement(IN[0])
hostElement = UnwrapElement(IN[1])

# Code unterhalb dieser Linie platzieren

if IN[2]==True:
	rebarElement.SetHostID(doc,hostElement)
	
	OUT = hostElement
else:
	OUT = "not run"
	
TransactionManager.Instance.TransactionTaskDone()
# Weisen Sie Ihre Ausgabe der OUT-Variablen zu.

Try rebarElement.SetHostId(doc, hostElement) instead.

1 Like

Thank you @MartinSpence that solved my Problem

Excellent :ok_hand:

hi Martin is there a way to loop through a list of elements (rebars)

Try a for loop

An example for getting the host element Id’s for several rebarElements and storing them in the hostId Array this way:

...
rebarElements = UnwrapElement(IN[0])

hostId = []

for rebarElement in rebarElements:
	hostId.append(rebarElement.GetHostId())
	
OUT = hostId

...
1 Like

thanks you, but is any idea why i am getting empty list :confused:

comments to your script:

  • U can only assign one host element to a rebar element
  • the second for loop (the inner one) is not necessary as it only changes the hostelement to first one of ur input list and overwrites it with the next one. So every rebar would have the last Element in the list as HostElement
  • u dont need to do list.append for setting a new host. This was only necesary in my example for storing the actual HostId’s in a list.

For setting new Host element to multiple rebars I made this routine, which will only work for assigning a single host element to multiple rebar elements :

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

clr.AddReference('RevitNodes')
import Revit
clr.ImportExtensions(Revit.Elements)

clr.AddReference('RevitServices')
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager
doc = DocumentManager.Instance.CurrentDBDocument
TransactionManager.Instance.EnsureInTransaction(doc)

rebarElements = UnwrapElement(IN[0])
hostElement = UnwrapElement(IN[1])

if IN[2]==True:
	for rebarElement in rebarElements:
		rebarElement.SetHostId(doc,hostElement.Id)
	
	OUT = (IN[2],rebarElements,hostElement)
else:
	OUT = (IN[2],"","")
	
TransactionManager.Instance.TransactionTaskDone()

If u want to assign multiple rebar elements to multiple rebar elements u will have to work with proper list structure or doing it with the script above step by step for each host element.