Revit API Forum
Welcome to Autodeskā€™s Revit API Forums. Share your knowledge, ask questions, and explore popular Revit API topics.
cancel
Showing results forĀ 
ShowĀ Ā onlyĀ  | Search instead forĀ 
Did you mean:Ā 

Executing Script During Runtime

3 REPLIES 3
Reply
Message 1 of 4
dev7D5E8
226 Views, 3 Replies

Executing Script During Runtime

We have an use case, where we want to run a Grasshopper script using Rhino.InsideRevit automatically.
We can execute the Grasshopper script without any issues by hand, but would want to automatize that step.

We implemented a custom addin to execute a script automatically during Revit's startup. However, we have encountered an issue where not everything is loaded yet during the startup process, leading to some errors. The Grasshopper script is correctly opened, but the execution fails, as multiple components show the following message: "RevitAPI: Writing of Entities of this Schema is not allowed to the current add-in."
This message does not appear, when running the same Grasshopper script by hand. 

We believe that the issue appears as we are calling the script during the start up of Revit and probably not  all components are initialized correctly.

Therefore, our goal is to find a way to execute a script during the runtime of Revit, after the startup and initialization processes have been completed. We are open to any method that achieves this objective. The script does not need to be a Grasshopper script directly as there are ways to open and execute Grasshopper scripts using C# or python as well.

If anyone has insights or suggestions on how to accomplish this, we would greatly appreciate your input. Thank you in advance for your assistance.

Labels (3)
3 REPLIES 3
Message 2 of 4
ricaun
in reply to: dev7D5E8

What are you trying to execute in the startup? The message "RevitAPI: Writing of Entities of this Schema is not allowed to the current add-in." means your plugin is not allowed to change the extensible storage, I suppose you created Schema by Grasshopper script and only can be changed by that.

 

One way to know if the problem is in startup is to use the event ApplicationInitialized, this gonna make sure the other plugins/applications gonna be installed as well.

Or create a basic IExternalCommand to execute the script inside the command.

 

And to execute a script in the runtime you could use the combo Idling Event with ExternalEvent Class.
The Idling gonna ensure that Revit is free to run the script.
The ExternalEvent gonna ensure your code gonna run inside the Revit Context.

 

 

Luiz Henrique Cassettari

ricaun.com - Revit API Developer

AppLoader EasyConduit WireInConduit ConduitMaterial CircuitName ElectricalUtils

Message 3 of 4
dev7D5E8
in reply to: ricaun

We want to automate our process completely without the need for any user input. So we have one script that starts Revit and then we would want to have some solution that automatically executes our Grasshopper script.

The Grasshopper Script converts a Rhino (.3dm) file into a Revit (.rvt) file.
The interesting part is that the script works fine, when executed within Grasshopper started in Rhino.InsideRevit. But not when we try to run the same script via an AddIn, which does the exact same steps, but automated. So I do not understand, why access restrictions about the Schemas would apply here.

As you mentioned we use ApplicationInitialized in the OnStartup method. For that we followed the code of this blog:
thebuildingcoder - automatically-open-a-project-on-startup 
And in the OnApplicationInitialized method we first open a rvt file and then call a method that gets the Grasshopper PlugIn, opens our Grasshopper script, and then runs the Grasshopper Solver.

We also renamed our AddIn, so that it is certainly loaded last, and the Rhino.InsideRevit PlugIn was loaded before.

 


About the combination of Idling Event and ExternalEvent Class, I do not understand this fully.
Should that combination also be started from within OnStartup or is there an option to execute a script automatically in Revit while Revit already runs via the CLI or another scripting language?

 

Could you maybe point me towards an example that shows the usage of the combo of Idling Event and ExternalEvent Class, so I can understand this more clearly.

 

Thank you for your help!

Message 4 of 4
ricaun
in reply to: dev7D5E8

I'm not sure is a good idea to execute a complex script in the ApplicationInitialized or OnStartup, I suppose that's the problem.

 

First, make your automation work when you click on a PushButton with the IExtenalCommand. If you are not able to make work there, is not gonna work using ExternalEvent.

 

I don't have an example with Idling Event and ExternalEvent Class together, only ExternalEvent: https://github.com/ricaun/RevitAddin.ExternalEventExample.

 

Luiz Henrique Cassettari

ricaun.com - Revit API Developer

AppLoader EasyConduit WireInConduit ConduitMaterial CircuitName ElectricalUtils

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Forma Design Contest


Rail Community