Change String to List

Looking to change the code below to take a list of files in the IN input instead of just the one Project1 file.

Any help would be appreciated. Thanks, Jason

import clr
clr.AddReference(‘ProtoGeometry’)
from Autodesk.DesignScript.Geometry import *
clr.AddReference(“RevitServices”)

import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager

clr.AddReference(“RevitAPI”)
clr.AddReference(“RevitAPIUI”)

import Autodesk
from Autodesk.Revit.DB import *
from Autodesk.Revit.UI import *

doc = DocumentManager.Instance.CurrentDBDocument
uiapp = DocumentManager.Instance.CurrentUIApplication
app = uiapp.Application
uidoc = uiapp.ActiveUIDocument

dataEnteringNode = IN

filepath = r’C:\Users\XXXXX\Desktop\Project1.rvt’

report =
modelPath = FilePath(filepath)

OUT = DocumentManager.Instance.CurrentDBDocument

Assuming you just want to output a list of FilePath objects given a list of strings:

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

filepaths_in = IN[0]

filepaths_out = []
for fp in filepaths_in:
    filepaths_out.append(FilePath(fp))

OUT = filepaths_out

Or a more succinct way of doing this:

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

filepaths_in = IN[0]
OUT = [FilePath(fp) for fp in filepaths_in]
1 Like

I use this personally…

def tolist(obj1):
	if hasattr(obj1,"__iter__"): return obj1
	else: return [obj1]

and then just do this…

myInput = tolist(IN[0])

Or…

myInput = tolist(UnwrapElement(IN[0]))

This ensures the objects are in a list.

1 Like

For some reason I thought strings had an __iter__ property, but that is not the case, so this is the way to do it.

1 Like