Running Scripts with multiple Models open

I’ve got a batch exporter tool that allows users to export PDF & DWG of selected sheets (very similar to DiRoots ProSheets but we need a bit more file name customisation than they offer), however I’ve noticed that if multiple models are open within the same instance of Revit, the script cannot always point to the current document, instead defaulting to the document used for the first run of the script.

Below is the sheet collection sector of the script for the Data-Shapes UI. I’m guessing I need to specify the document using the Document.Current node, but I’m not sure how to factor that into the script.
Can anyone help?

You are correct in that Dynamo only runs in the document it was opened in. While the API allows you to modify specified documents, most nodes do not. Anything that is written without a document input is set to run on the current document only. To get around this you’ll have to write your own code for specified documents (or find a custom package that already does what you want).

1 Like

@dan.buckingham The Dynamo Python Primer has a section on opening Revit files here:
https://dynamopythonprimer.gitbook.io/dynamo-python-primer/4-revit-specific-topics/opening-and-closing-external-files

1 Like

I think you could utilize Dynamo Player instead of Dynamo, as I believe the document changes more readily there.

1 Like

Thanks for the suggestions, I probably should have added that this script is to be run via a custom extension created through pyRevit, so it will be run directly from the Revit toolbar. I’d rather avoid dynamo player if possible as the majority of my users aren’t familiar with it.

I’ll have a dig around the python primer and some other custom nodes.

Thanks!

I’d imagine that each time the user hits run it would launch anew then, but likely that’s something to confirm on the PyRevit forums.