Upload multiple rvts files

Good morning everyone.
I will greatly appreciate your support.
I am trying to be able to load all the RVT files from my root folder to my current REVIT document, I have no idea if there is any node that allows me to perform such an action or maybe someone knows of some code in python that I can use,
I leave a reference image on what I try to do.
Thank you.

Yes Revit API supports linking revit models I think. Genius Loci likely has some nodes in this space, give it a check.

Something like this might work for you.

The Morpheus package Contians the Link Original, and other linking option nodes.

Python Script - by Jonathan ATGER & Nicklas Østertgaard
# part of the code originally created by Nicklas Østertgaard  nvo@bimshark.com / nvo@shl.fk  and/or Augusto Goncalves (AEC Devblog)
# Workset management, loop, pin and site location settings by Jonathan ATGER (jonathan.atger@yahoo.fr)

import clr

# Import ToDSType(bool) extension method
import Revit

# Import DocumentManager and TransactionManager
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager
from System.Collections.Generic import *

# Import RevitAPI
import Autodesk
from Autodesk.Revit.DB import *

import sys
pyt_path = r'C:\Program Files (x86)\IronPython 2.7\Lib'
import System

doc = DocumentManager.Instance.CurrentDBDocument

# Start Transaction

# number of elements
try :
	numworksets = len(IN[1])
except :	
	if IN[1] : numworksets = 1
	else : numworksets = 0

if isinstance (IN[0], str) : 
	numlinks = 1
else :
	try : numlinks = len(IN[0])
	except : 
		try : numlinks = len([IN[0]])
		except :numlinks = 0

#check list lengths
if numlinks != numworksets :
	listlength = False
else : 
	listlength = True

def linkmodel (fpath, options, doc, pin) :
	# Create the Revit Link Type
	mp = ModelPathUtils.ConvertUserVisiblePathToModelPath(fpath)
	lnkOp = RevitLinkOptions(options)
	loadedLnkType = RevitLinkType.Create(doc, mp, lnkOp)
	# Create the Revit Link Instance
	global lnkInstance 
	lnkInstance = RevitLinkInstance.Create(doc, loadedLnkType.ElementId, ImportPlacement.Origin)
	#Pin link
	lnkInstance.Pinned = IN[2]

	# Number of worksets input and filepaths input are different
	if IN[1] and listlength == False :
		OUT = "The number of worksets doesn't match the number of links"
	# Multiple Worksets input
	elif IN[1] and listlength == True and numlinks !=1 :
		#Get WorksetTable and current workset
		wstable = doc.GetWorksetTable()
		activewsid = wstable.GetActiveWorksetId()
		#Create list for output
		links = []
		for fpath, ws in zip(IN[0], IN[1]) :
			# Get WorksetId
			wssimpleid = ws.Id
			wsid = WorksetId(wssimpleid)
			# Set the workset
			WorksetTable.SetActiveWorksetId(wstable, wsid)
			# Create the Revit Link Type and Link Instance
			linkmodel(fpath,"", doc, IN[2])
			#add created link to output
		#reset current workset	
		WorksetTable.SetActiveWorksetId(wstable, activewsid)
		OUT = links	
	# Single workset input
	elif IN[1] and listlength == True and numlinks == 1 :
		wstable = doc.GetWorksetTable()
		activewsid = wstable.GetActiveWorksetId()
		links = []
		wssimpleid = IN[1].Id
		wsid = WorksetId(wssimpleid)
		WorksetTable.SetActiveWorksetId(wstable, wsid)
		linkmodel(IN[0],"", doc, IN[2])
		WorksetTable.SetActiveWorksetId(wstable, activewsid)
		OUT = links	
	# No worksets input
	elif numlinks != 1 :
		links = []
		for fpath in IN[0] :
			linkmodel(fpath,"", doc, IN[2])
	else :
		links = []
		linkmodel(IN[0],"", doc, IN[2])
    # if error accurs anywhere in the process catch it
    import traceback
    errorReport = traceback.format_exc()
    OUT = errorReport 

# End Transaction
1 Like

Thank you very much for your comment PyXam, it helped me a lot… but I have a particular question.

You need to ensure the object returned by the inout is always a list of files, not a single file.

Adding a ToList method acting on the input should resolve the issue. There are number plus examples in the forum, silo I recommend doing a search and catching the results there.

1 Like

Alot of the nodes in the crumple package have python for the tolist method, try unpacking some of those and see how you go :slight_smile: