Script trigger - Python vs C#


#1

Hello,

At the moment I am doing a research for a script and I have a question how can I tell Rhino to trigger a script after I press specific commands.
For example.:
I press Move, select the objects, click the first point, click second point and then script starts.

I want to achieve to record modelling steps in a list that later can be modified and called.

Andras


(Giulio Piacentino) #2

Hi Andras

what you are asking is rather convoluted. Something in this direction can be achieved by using RhinoCommon, and listening to events. It is not trivial and you might find areas where the command does not give enough information back about what it performed. However, if you are really looking into it, check:

  • RhinoDoc.AddRhinoObject,
  • RhinoDoc.BeforeTransformObjects,
  • RhinoDoc.DeleteRhinoObject,
  • RhinoDoc.ReplaceRhinoObject,
  • RhinoDoc.UndeleteRhinoObject,
  • RhinoDoc.UndeleteRhinoObject,
  • RhinoDoc.SelectObjects,
  • RhinoApp.EscapeKeyPressed,
  • RhinoApp.OnKeyboardEvent,

Giulio

Giulio Piacentino
for Robert McNeel & Associates
giulio@mcneel.com


#3

Hi Giulio,

Thaks for the reply. I will have a look. At the moment I learn Python as a starting point once it will be more clear I will do some experiments with C# as well.


#4

Hi Giulio,

Thanks for the answer. Back to the topic. I have realised that on the development site a Python icon has been added next to the “Write Rhino plugins & Grasshopper components” but only C# is available for Rhino Common. Does it means that Python is available inside C# code, so for example Python scripts can be triggered by a button that has been coded in C# or the above mentioned “RhinoApp.SelectObjects” is suitable to trigger a Python script?

Andras


(Giulio Piacentino) #5

Yup, that’s possible. There is even no need for C# just to bind to the events above, they are also available to Python. Still, if you want, you can use it. From C#, you can also run Python script, so also the other part of the answer is true. See the static Rhino.Runtime.PythonScript.Create() method.


#6

Thanks. In this case does the script has to run continuously?

For example; How can achieve to click on a cube (with user text: “editable”) and grips(control nodes) will automatically appear to edit the cube. As far as I know script run once the user hits the run command. Can I achieve it with Python as well?


(Giulio Piacentino) #7

I would not recommend doing this in Python. I think a fully-flagged plug-in would be much better suited. The plug-in would register for the Selection event when it’s started.