# Upload multiple rvts files

**URL:** <https://forum.dynamobim.com/t/upload-multiple-rvts-files/92900>\
**Category:** Revit\
**Tags:** python, dynamo\
**Created:** [August 16, 2023, 12:18am UTC](https://forum.dynamobim.com/t/upload-multiple-rvts-files/92900 "2023-08-16T00:18:32Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![AM3D.BIM.STUDIO](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/am3d.bim.studio/32/127441_2.png) [@AM3D.BIM.STUDIO](https://forum.dynamobim.com/u/AM3D.BIM.STUDIO)\
**Post date:** [August 16, 2023, 12:18am UTC](https://forum.dynamobim.com/t/upload-multiple-rvts-files/92900/1 "2023-08-16T00:18:32Z")

</div>

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.

 ![CARGAR MULTIPLES ARCHIVOS VINCULADO](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/7/e/7eefca94f912c45435ac3772dcf2389c39926ef7.png)

---

<div class="post-metadata">

**Author:** ![GavinNicholls](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/gavinnicholls/32/190442_2.png) [@GavinNicholls](https://forum.dynamobim.com/u/GavinNicholls)\
**Post date:** [August 16, 2023, 12:26am UTC](https://forum.dynamobim.com/t/upload-multiple-rvts-files/92900/2 "2023-08-16T00:26:15Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![pyXam](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/pyxam/32/163009_2.png) [@pyXam](https://forum.dynamobim.com/u/pyXam)\
**Post date:** [August 16, 2023, 12:52am UTC](https://forum.dynamobim.com/t/upload-multiple-rvts-files/92900/3 "2023-08-16T00:52:03Z")

</div>

Something like this might work for you.

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

 ![image](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/b/6/b60f0c166ff667b2f3c2f1e6c0901ffe671cb4ac.png)

> **Python Script - by Jonathan ATGER & Nicklas Østertgaard**
>
> ```auto
> # 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
> clr.AddReference("RevitNodes")
> import Revit
> clr.ImportExtensions(Revit.Elements)
> 
> # Import DocumentManager and TransactionManager
> clr.AddReference("RevitServices")
> import RevitServices
> from RevitServices.Persistence import DocumentManager
> from RevitServices.Transactions import TransactionManager
> from System.Collections.Generic import *
> 
> # Import RevitAPI
> clr.AddReference("RevitAPI")
> import Autodesk
> from Autodesk.Revit.DB import *
> 
> import sys
> pyt_path = r'C:\Program Files (x86)\IronPython 2.7\Lib'
> sys.path.append(pyt_path)
> import System
> 
> doc = DocumentManager.Instance.CurrentDBDocument
> 
> # Start Transaction
> TransactionManager.Instance.EnsureInTransaction(doc)
> 
> # 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]
> 
> try:
> # 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
> links.append(lnkInstance)
> 							
> #reset current workset	
> WorksetTable.SetActiveWorksetId(wstable, activewsid)
> 		
> #output
> 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])
> links.append(lnkInstance)
> WorksetTable.SetActiveWorksetId(wstable, activewsid)
> OUT = links	
> 		
> # No worksets input
> elif numlinks != 1 :
> links = []
> for fpath in IN[0] :
> linkmodel(fpath,"", doc, IN[2])
> links.append(lnkInstance)
> OUT=links
> 		
> else :
> links = []
> linkmodel(IN[0],"", doc, IN[2])
> links.append(lnkInstance)
> OUT=links
> 	
> except:
> # if error accurs anywhere in the process catch it
> import traceback
> errorReport = traceback.format_exc()
> OUT = errorReport 
> 
> # End Transaction
> TransactionManager.Instance.TransactionTaskDone()
> 
> ```

---

<div class="post-metadata">

**Author:** ![AM3D.BIM.STUDIO](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/am3d.bim.studio/32/127441_2.png) [@AM3D.BIM.STUDIO](https://forum.dynamobim.com/u/AM3D.BIM.STUDIO)\
**Post date:** [August 16, 2023, 5:02pm UTC](https://forum.dynamobim.com/t/upload-multiple-rvts-files/92900/4 "2023-08-16T17:02:26Z")

</div>

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

- The code works very well when I have 2 or more files, but it doesn’t work if I only have 1… why?  
and how could i fix it.  
Thank you.  
 ![CARGAR MULTIPLES ARCHIVOS VINCULADO_2](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/1/6/16388b82381a6bbdc173abb5e7f17dca59fd1e56.png)

---

<div class="post-metadata">

**Author:** ![jacob.small](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/jacob.small/32/161030_2.png) [@jacob.small](https://forum.dynamobim.com/u/jacob.small)\
**Post date:** [August 16, 2023, 5:21pm UTC](https://forum.dynamobim.com/t/upload-multiple-rvts-files/92900/5 "2023-08-16T17:21:50Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![pyXam](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/pyxam/32/163009_2.png) [@pyXam](https://forum.dynamobim.com/u/pyXam)\
**Post date:** [August 19, 2023, 8:14pm UTC](https://forum.dynamobim.com/t/upload-multiple-rvts-files/92900/6 "2023-08-19T20:14:45Z")

</div>

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