bvn-architecture / RevitBatchProcessor

Fully automated batch processing of Revit files with your own Python or Dynamo task scripts!
GNU General Public License v3.0
277 stars 75 forks source link

Saving file after running Scripts #10

Open dhanjeetsah opened 6 years ago

dhanjeetsah commented 6 years ago

Hi,

Thanks for all your effort on the developing this tool and made it publicly available. A large number of people can get benefit from this tool.

I have successfully installed this tool and can see this working well except this tool does not save the RVT file before it closes. Do we have to use another script to save the current document? It would be great to have option in the UI to allow user to save on the current location or save as in the different location. Any help will be appreciated.

Best regards, Dhanjeet

DanRumery commented 6 years ago

[EDIT: to others reading this thread, as it stands RBP requires that you use a Dynamo node from one of the popular packages for Save/Sync in your Dynamo scripts] For python scripts, you can use the Revit API directly to perform Save/Sync or use one of the utility functions that RBP provides (see the FAQ for more information on that)]

Hi Dhanjeet

Thanks for the appreciation, glad you're finding it useful!

I should probably add some useful sample python and Dynamo scripts to the documentation to demonstrate saving the file and other operations. I can do this sometime this week.

If you're familiar with Python you can use the plain Revit API to do the saving / sychronizing. I am sure there are Dynamo nodes to do the same things. But I'll make some documentation for this.

I can certainly add the ability to Save to a new location in the UI. I am hesitant to add a synchronize option in the UI because I don't want users inadvertently committing changes to central models.

Can you let me know of the workflow you desire? Save as new central? Save the local file? Save families to a new location, Synchronize with Central, etc.? I am guessing this is for milestoning tasks and similar...

dhanjeetsah commented 6 years ago

Hi Dan,

Thanks for your quick reply. I am new to Python and it would be great to add a python script to save file after running Task Script. It could be possibly as part of UI or a python script that could be executed as Post Processing. I would prefer to have option in the UI to have option under SAVING - No, Save with Overwrite, Save to Different Location (Browse Button).

I have noticed that while closing file with Batch processor, Revit still throws Save dialogbox and default is " Sending button click to 'No' button...". Can we change this setting to YES in anyway?

For my workflow, I want to open file, run a Dynamo script that delete all views, insert model disclaimer and then save the file. Currently all the process works fine except, it is unable to save file.

DanRumery commented 6 years ago

[EDIT: to others reading this thread, as it stands RBP requires that you use a Dynamo node from one of the popular packages for Save/Sync in your Dynamo scripts] For python scripts, you can use the Revit API directly to perform Save/Sync or use one of the utility functions that RBP provides (see the FAQ for more information on that)]

Ok those UI options sound pretty sensible to me. It may take me a while to have that included in the UI due to time constraints but I'll provide a python task script example of how to perform save operation depending on the file. This python script will execute the Dynamo script. You will just have to change a few variables, namely the Dynamo script file path and the Save folder location.

dhanjeetsah commented 6 years ago

Hi Dan,

I have tried the python script you have provided that runs to open files and close with saving files to required location however, the dynamic script seems not applied on any of the Revit files. I have installed V1.2.8 and below is the log generated by UI. Any help with this?

16:06:01 : Session ID: <2018-07-11T06:06:01.384Z>

16:06:01 : 16:06:01 : Log File: 16:06:01 : 16:06:01 : C:\Users\dhanjeets\AppData\Local\BatchRvt\BatchRvt_20180711_160601_384.log 16:06:01 : 16:06:01 : Task Script: 16:06:01 : 16:06:01 : F:\Workspace\Revit Workspace\Support\Dynamo\Batch Insert Model Disclaimer.py 16:06:01 : 16:06:01 : Show Message Box on Task Script Error is enabled. 16:06:01 : 16:06:01 : Revit Processing mode: 16:06:01 : 16:06:01 : Batch Revit File processing 16:06:01 : 16:06:01 : Reading Revit File list: 16:06:01 : 16:06:01 : C:\Autodesk\Batch\Revitfilelist.txt 16:06:01 : 16:06:01 : Revit Files for processing (2): 16:06:01 : 16:06:01 : C:\Autodesk\Batch\TH TYPE A.rvt 16:06:01 : File exists: YES 16:06:01 : File size: 34.99MB 16:06:01 : Revit version: Autodesk Revit 2017 (Build: 20170118_1100(x64)) 16:06:01 : 16:06:01 : C:\Autodesk\Batch\TH TYPE B.rvt 16:06:01 : File exists: YES 16:06:01 : File size: 36.63MB 16:06:01 : Revit version: Autodesk Revit 2017 (Build: 20170118_1100(x64)) 16:06:01 : 16:06:01 : Starting batch operation... 16:06:01 : 16:06:01 : Processing Revit file (1 of 2) in Revit 2017 session. 16:06:01 : 16:06:01 : C:\Autodesk\Batch\TH TYPE A.rvt 16:06:01 : File exists: YES 16:06:01 : File size: 34.99MB 16:06:01 : Revit version: Autodesk Revit 2017 (Build: 20170118_1100(x64)) 16:06:01 : 16:06:01 : Starting Revit 2017 session... 16:06:01 : 16:06:01 : Monitoring host Revit process (PID: 17340) 16:06:01 : 16:06:19 : - 16:06:20 : - Processing file (1 of 2): C:\Autodesk\Batch\TH TYPE A.rvt 16:06:20 : - 16:06:20 : - The file is a Non-workshared file. 16:06:20 : - 16:06:20 : - Opening file: C:\Autodesk\Batch\TH TYPE A.rvt 16:06:21 : - 16:06:22 : - Task script operation started. 16:06:27 : - 16:06:27 : - This task script is running! 16:06:37 : 16:06:37 : Revit process appears to be busy or unresponsive... 16:06:37 : 16:07:33 : 16:07:33 : '' dialog box detected. 16:07:33 : 16:07:33 : Dialog has the following static control text: 16:07:33 : 16:07:33 : Autodesk.Revit.Exceptions.ArgumentNullException: The input argument "document" of function `anonymous-namespace'::FilteredElementCollector_constructor or one item in the collection is null at line 326 of file d:\r2\2017_px64\source\revit\revitdbapi\gensrc\APIFilteredElementCollectorProxy.cpp. 16:07:33 : 16:07:33 : Sending button click to 'OK' button... 16:07:33 : 16:07:33 : ...sent. 16:07:33 : 16:07:33 : Revit process appeared busy or unresponsive for about 66 seconds. 16:07:33 : 16:07:40 : - 16:07:40 : - Task script operation completed. 16:07:40 : - 16:07:40 : - Closed file: C:\Autodesk\Batch\TH TYPE A.rvt 16:07:40 : - 16:07:40 : - Operation completed.

DanRumery commented 6 years ago

@dhanjeetsah

Hi Dhanjeet

The error message looks like it's happening when you use FilteredElementCollector(doc). Is your script setup correctly?

Can you send me the python script you're trying to use? (Or at least a minimal sample that still causes an error)

DanRumery commented 6 years ago

@dhanjeetsah

It's also possible the error is happening in the Dynamo script... it's definitely related to a missing (active) document. It depends on the script details.

dhanjeetsah commented 5 years ago

Hi Dan,

I have tested with a simple Dynamo Script- Delete 3D Views and used Python Script to execute. It seems working fine and UI does not have any error but still the Dynamo Script is not applied to any of the files. Is it because, Dynamo expect the current document opened in Revit UI rather than the batch script opens document in background? Below is the log and attachding the .py and .dyn file for you to test.

BatchProcess UILog.txt BatchProcessPY&DYN.zip BatchProcessPY&DYN.zip

dhanjeetsah commented 5 years ago

If I am not using Python Script and just using the same DYN script in TASK SCRIPT, it process the Dynamo functions to the all the files though no save option for this instance. I could see the difference that when we use DYN, Revit opens file in UI, dynamo scripts finishes and then closes the file however, after using PY script, Revit does not open files in its UI.

DanRumery commented 5 years ago

@dhanjeetsah

I will do some testing with your sample. You are correct that this python script does not open the Revit document in the Revit UI unlike when using a Dynamo script as a task script directly. I will try a couple of methods...

DanRumery commented 5 years ago

@dhanjeetsah

Ok so you are right, the Dynamo script expects a visible Document in the UI. So there are two solutions:

1) Instead of using the python script, use the Dynamo script directly and use the Document.SaveAs node from Clockwork package 1.31.2

OR

2) Modify the python script with the following:

Output()
Output("This task script is running!")

Output()
Output("Saving as new Central...")

# Save the Revit file to the destination folder.
SaveRevitFile(doc, revitFilePath, SAVE_FOLDER_PATH)

Output()
Output("Saved to: " + str(doc.PathName))

Output()
Output("Activating the document in the UI...")

revit_file_util.OpenAndActivateDocumentFile(uiapp, doc.PathName)

Output()
Output("Executing Dynamo script...")

# Execute the Dynamo script
revit_dynamo_util.ExecuteDynamoScript(uiapp, DYNAMO_SCRIPT_FILE_PATH)

Output()
Output("Re-saving as Central...")

# Re-save the Revit file as central (to the same save folder).
SaveRevitFile(doc, doc.PathName, SAVE_FOLDER_PATH)

You will notice that for this python code, it is saving the file TWICE because it turns out that Revit requires a document path in order to activate the document but we are detaching from central, hence there is no document path to do this until the file is saved as new central. It's a bit ugly but this works. I recommend trying to get option 1) to work :)

Hope it helps!

[EDIT: fixed a typo in this script]

DanRumery commented 5 years ago

Closing this issue because Save/SaveAs functionality is available in Dynamo and in Python, so it's straightforward for the task script to take care of that.

superglenn commented 5 years ago

Would be great to get this built in as part of the UI, I have standard Dynamo scripts that I run. When running them manually and debugging I obviously don't want a save function built into them. It would be great if the UI had a save option so I don't have to modify my standard graphs to batch them,

Thanks!

DanRumery commented 5 years ago

@superglenn

Agree it would be handy to have a save / sync option built into RBP's options. Not sure just yet when I'll have time to work on that but I'll re-open this request. I guess the issue for me is, there are quite a number of ways to configure for saving / syncing.

E.g. for saving the file, does it save over the original, save with the same filename somewhere else, save with a new filename, etc. For syncing to central, what if the script failed somehow, should it still proceed with syncing, if the central file is busy (other user is syncing) should it wait indefinitely, etc. Some options and scenarios to consider...

s-fad commented 4 years ago

Hi there!

Joining to others I would also thank DanRumery for the creation of this must have tool for every Revit user! We were suffering without it for so long that now we can distinctly separate “till RBP-ancient age” and “modern RBP-age” :). It saves so many time! And will save more if it continue to develop. Especially when this issue will b closed. Why? Because most of Revit users are not so good in Dynamo not to mention Python. This vast majority use dyns and less often pys created by someone else. So they cannot add SaveAs right into the TaskSkript.

However, most of them know (have experience or inevitably will get it somewhen) that scripts they found in the www may act in some unexpected way. So it's their responsibility to backup their work b4 the script implementation. So, Dan (if I can address you by name; if it unacceptable - really sorry!), there is no need to worry that users will lost their work... Or, let em only the safest way: only option to save the processed files somewhere else without overwriting original files. If they want to save over the original - they have to modify the task script properly.

You will enlarge your target audience in numbers when the option of saving files by BRP will become available. Until that they have to dig a little into the python or dynamo and implement above mentioned ways with wrapping task script into python script or adding Save functionality into the Dynamo script. And I'd like to mention that I failed with the first way: I've ctrl+c/v the text above into .py file, modified paths and failed with:

20:40:02 : - ERROR: An error occurred while executing the task script! Operation aborted. 20:40:02 : - 20:40:02 : - Exception: [SyntaxError] 20:40:02 : - Could not obtain further exception information.

I am not so good in python and probably did something wrong. Could you please check where am I wrong? DS.py.txt

For now I've done with adding clockwork Document.SaveAs directly into my test dynamo task script but as mentioned above, it's not so convenient to have two scripts for RBP and during edition mode.

Regards, Sergey

DanRumery commented 4 years ago

@s-fad Hi Sergey Firstly thanks for the praise :)

It seems enough people have been asking for this feature that I'll have a play at implementing a built-in Save/Sync mechanism in RBP. I'm fairly busy lately but I think I can make a prototype over the coming weeks.

There will be a few questions surrounding the behaviour. In particular there is no way for RBP to know if a Dynamo script executes successfully or not, so if RBP is to Save/Sync after execution it will be doing it regardless of execution success, which is potentially an issue. Anyway we'll have to think about that once I have prototype to demo.

Note that instead of using a python script you could just use a dynamo script directly as the task script and use a Save/Sync node in your Dynamo script. But I understand you'd prefer not to embed a node in your Dynamo script while testing.

The syntax error appears to be caused by the non-ASCII characters in your script (the letters in your path). I'll see if I can fix that issue. It looks like the script engine needs to support Unicode. I'll keep you posted on that.

clooz8 commented 3 years ago

Hello Dan,

Very excited about this tool. Thank you so much for your time and effort on it!

However, I'm giving it a test run and running into this save issue. I’m trying the Save As workflow and I tested Orchid’s and Clockwork’s SaveAs, but no luck. The Dynamo script works when I run it through Dynamo, but not RBP.

Below is my .dyn script and a portion of the log from the RBP. It seems to hang up in the RBP, but not sure what to do now. I’ve also tried adding a Passthrough node and Save node to save again after the Save As node to see if the .rvt would save, but that didn’t work either. Any help would be greatly appreciated.

Revit Batch Processor v0 2_2021-04-22_11-44-28 2021-04-22 23_27_39-Revit Batch Processor

Regards, Chris

amdghedy commented 2 years ago

This add-in not working for revit 2022 ? Can help plz

notionparallax commented 2 years ago

@amdghedy could you be more specific? This probably deserves its own issue, rather than tagging it onto this one

elevatebim commented 1 year ago

Update June 12 This solution doesn't work consistently in Batch Processor. Though, it works in Dynamo Player. Not sure why the save-as doesn't execute in Batch Processor.

Here's a solution to save your families during batch processing. Add this to the end of your script. The idea is to pass the last piece of the script into the [o|DataStream.Await] node (or the Clockwork Passthrough node also works), which is placed in between the save script that will execute at the very end. The batch processor will automatically close the file. You will need Orchid and Clockwork 2x. Note that if you have a script that adds multiple shared parameters to a family, you may need to chain your scripts together so that the very last parameter is added before the family is saved.

This script was tested in Revit 2021.

It is recommended to save this script to another folder for batch processing only since it is not typically useful to add a save script to the end of your scripts.

image