Reload document in the same dyn file for using datas from the 1st python script to the 2nd one

Hi All,

Is it possible to reload document in the same dyn file to get datas from the 1st python script needed to run the 2nd python script?

In my case I want to get the container host datas generated in the first file (rebar creation) to be able to copy them to others elements (in the same file) without need to create 2nd file ?

here the 2nd script for copying rebar containers
import sys
import clr
import System

from System.Collections.Generic import IList, List 

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

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

clr.AddReference('RevitServices')
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager

doc = DocumentManager.Instance.CurrentDBDocument

all_Shafts = FilteredElementCollector(doc).OfCategory(BuiltInCategory.OST_GenericModel).WhereElementIsNotElementType().ToElements()

# get the remainder rebar hosts.
New_rebar_hosts = all_Shafts[1:]


# Get rebar containers.
first_rebarHostData = RebarHostData.GetRebarHostData(all_Shafts[0])
first_containersInHost = first_rebarHostData.GetRebarContainersInHost()
old_containerIds = List[ElementId]([c.Id for c in first_containersInHost])

# Get levels for remainder rebar hosts.
levels = []
for host in New_rebar_hosts:
    level = doc.GetElement(host.LevelId)
    levels.append(level)
    
TransactionManager.Instance.EnsureInTransaction(doc)
new_containerIds = []
for l in range(0, len(levels)):
    t = XYZ(0, 0, levels[l].Elevation)
    containerId = ElementTransformUtils.CopyElements(doc, old_containerIds, t)
    new_containerIds.append(containerId)

new_containers = []
for i,j in zip(range(0, len(new_containerIds)), range(0, len(New_rebar_hosts))):
    temp = []
    for id in new_containerIds[i]:
        container = doc.GetElement(id)
        container.SetHostId(doc, New_rebar_hosts[j].Id)
        temp.append(container)
    new_containers.append(temp)
TransactionManager.Instance.TransactionTaskDone()

OUT = new_containers

Thanks.

If you get the document somewhere in the first python node you can just output it and feed it to the second node. Is that what you’re looking for?

1 Like

@Nick_Boyts
Sorry for this stupid question
I was totally distracted and it escaped me that I can output the document in the 1st script and use it in the 2nd as an input, and that solve my issue.

Thanks.