Python loop/append list level help

Hi All,

I’m working on a script to cycle through a folder of rvt files, open them and extract data.
Some code that has been posted on here has helped alot but I have hit the limit of my python knowledge.

Currently to test I have 3 revit files in a folder. The problem i’m having is with my code in the ExportFunction()

Its is opening the models and extracting the information, but it is combining the information from all models opposed to creating new sublists for each model.
List[1][0] = List[2][0] = List[3][0]

Any help would be much appreciated

Cheers,
Josh

it is looking likely that you are trying to open the files then export from them?

You need to utilise a python function return to be able

Side Note: If you are after extracting information from the newly opened document file then your document in the export function is incorrect as it is utilizing the already opened document and you need to input your “Opendocumentfile”(eg your new doc) into the export function. Line 94 will not be required either.

eg

def ExportFunction(inputdoc):
doc = inputdoc
//rest of your code

return [model_cat, anno_cat, ana_cat, internal_cat]

then you modify the exportfunction() line(105) to be

 datax.append(ExportFunction(doc))

Yeh I want to open each file one by one and upon each open extract all the elements for each type of category. Then pass that outside of the python node and manipulated the data and then export to excel for each file.

I just realised I am currently collecting all the used categories in each model and passing that out of the python node. I was then using the ‘all elements of category’ node outside of the python node. I need to push this inside the python node.

@Brendan_Cassidy Thanks for the assistance above

I have a feeling what I posted above was actually working. The data I elements I was using for checking did actually exist in both models facepalm

I’ve simplified the code heavily though as I didn’t really need to break it down by category.

You still need to rethink your code because if you are getting information from a revit file that was not opened when you opened dynamo then you do not use “DocumentManager.Instance.CurrentDBDocument” to get the element information.

You have to use the document from “app.OpenDocumentFile” and plug this as the document for any information you need to extract.

@Brendan_Cassidy i’m not getting any information from files that aren’t opened by dynamo

The function is running from within this loop which opens each file which is in input

I would suggest you look at the data output from dynamo and to have manually a check of a couple of the revit files you are opening. As you may fine that the data output is excatly the same for each revit file when it should be different(quantity, element ids, etc).

DocumentManager.Instance.CurrentDBDocument - Get has access to the revit file you had opened prior to opening dynamo and associates that document(revit Project) to this.

OpenDocumentFile is a background process and therefore you need to input this doc to get the categories you want via the exportfunciton

This will change it as follows:
image

Also your “Revit.Elements.category” command will be doing a similar approach to the documentmanager and only getting information from the revit file that was opened prior to opening dynamo. This will mean that it should be changed from a dynamo method to a more native revit way via FilteredElementCollector.

Therefore it would like like the folowing:
“FilteredElementCollector(doc)
.OfClass( FamilyInstance ).OfCategory( BuiltInCategory.OST_Planting )
.WhereElementIsNotElementType().ToElements()”

Some example python code for element collectors can be found here https://github.com/Amoursol/dynamoPython/tree/master/revitAPI

1 Like