Tell running Rhino application to execute script


#1

Hey everybody!

I have written a little Python script in the embedded script editor. Now I am looking for some windows console commands to:

  • start Rhino with a certain 3dm file/ open a certain file in running Rhino
  • tell the running Rhino application to execute the previously created Python script

I have already come across the /runscript command but I didn’t get all of the information I need.

The purpose is that some other software produces input data which the Rhino Python script should process and therefore both, the loading of the file and the script execution should be automated.

Thanks in advance,
Raphael


(Wim Dekeyser) #2

Couldn’t you ‘fake’ this by having the other software overwrite your Rhino template file?
I didn’t fully understand if the script also is changed every time but, regardless, you could also overwrite a single script that you have set to load when Rhino starts (Options > RhinoScript > Startup).


#3

Thanks for your answer, but as Rhino shall remain running the solution with only running the script when Rhino starts does not really solve my problem.

To clarify the usage:

Another software produces an IGES file containing 3d data. The Python script calculates the intersection points of some ray with the 3d data and saves the intersection coordinates and normal vectors in that poins into some txt file (or processes them in another way).

As the IGES files are generated automatically, I am looking for a way to also automatically open the file in Rhino and run the Python script whithout any user interaction.


#4

I dont know if this is possible with scripting but if you create a plugin that check’s a directory every 5 - 10 secs, and if there are changes open the file and run the python script…

Else you have to do it manually… open the file and run the scipt.


#5

Ok, if there is really no way to use Rhino as some server for my requests, I will have to stick with that.

Thanks


(Wim Dekeyser) #6

I wouldn’t jump to that conclusion :smile:. It’s just a matter of getting someone who knows about this to answer.
Perhaps @dale can provide a pointer?


#7

I think you can make it automaticly with python or rhinoscript so you only have to click one button.


#8

The problem is that everything should work completely automated, without pushing any button, so after a new IGES or 3dm file has arrived, my pythonscript should trigger and process the data.


#9

Ok, if there is really no way to use Rhino as some server for my requests, I will have to stick with that.

You have not understood what @jordy1989 thinks…
Programing/Run Your script as loop and not close Rhino
Automatic Startup Your script in Rhino…

Which system do you work 32 or 64 bit ?


#10

I think I did understand what jordy meant, that’s why i wrote “i will have to stick with that” :smile:
I just thought it would be more elegant to start the script only when needed and not looping all day long (or checking for new data after some sleep)

I have a 64bit system


#11

I remember it used to be possible, here how it was up to Rhino 4:

http://wiki.mcneel.com/developer/automation

Is this dead?


#12

If you create a windows application you can use this yes.
It is not for python scripting because you still have an eternal loop then.


#13

Not, is not dead, i’m use this external ACX access. (That’s a very good interface in Rhino)


#14
  1. Download and install from here: https://www.autoitscript.com/site/autoit/downloads/

Download attached file ArrivedFiles.zip (1.0 KB) ArrivedFiles.zip (979 Bytes) ArrivedFiles.zip

2.Install Autoit --> Scite with option Edit Script !!! !!! not Run Script

3.On your desktop create directory named IGS_Files

4.Put there few IGS files (For first test small files !!!)

5.Start Rhino

  1. Unzip ArrivedFiles.zip, open Scite Editor and load extracted file ArrivedFiles.au3 (Source code)

  2. Press F5 or run script from scite menu --> Tools --> Go

What happens ?
External program is started
Every 20 minutes is checked whether new files arrived in folder IGS_Files
Files older than 20 minutes are ignored !!!
If new file arrived, command is executed, in my example, command Import IGS is used
If sixteen(16) clock is reached, script quit automatically
Exit script manual with RMB over Icon in systray

If everything works test your script
Give your script a command alias and change line like this

$r.Command("YourAlias", False)

Edit:
Or Pythonscript: Make that Your Pythonscript is on search patch and add this as command

$r.Command("-_RunPythonScript (Samples.MyPythonScript.py)")  ;;;Not tested

At the end of your script --> do not forget to delete all objects from document !!!

If everything works
You can compile this script as exe file. Ctrl + F7 or menu --> Tools --> Compile

Do not use Obfuscator ore UPX, otherwise your antivirus program will explode

Finally,
use at your own risk, I do not give liability

Quick tested in Rhino4,
I do not know if LastCommandResult() returns a value when used aliased script

So finito end midday meal…


#15

Wow, thanks a lot for this detailed description!!!

I will try it out as soon as possible.


#16

First sorry for my bad English. (Google translater is my friend)

OK,
Here was a little logical bug
I have added two more lines
ArrivedFiles.zip (1.0 KB)
New:
First loop import file that are no older than 20 minutes.
(But “DAY” is not checked, so remove files from previous day)
Next loop imports file that are no older than 20 minutes + Running time from previous loops.
After all loop’s finished, rhino.interface is destroyed, script will pause’s for 20 minutes.
After pause, for next loop new reference to running Rhino will be created, but in this case not ideal.

I have new modified old script, in this case, the object will accessed remain permanently in one same Rhino process.
ArrivedFiles_1.zip (1.0 KB)


(Dale Fugier) #17

Rhino can be automated, externally using ActiveX.

http://4.rhino3d.com/5/rhinoscript/introduction/external_access.htm

Here are a couple of examples that demonstrate this using VBScript.

https://github.com/mcneel/rhinoscript/blob/master/TestRhino5Automation.vbs
https://github.com/mcneel/rhinoscript/blob/master/BatchRender.vbs
https://github.com/mcneel/rhinoscript/blob/master/RhinoRender.vbs]

I don’t know if standalone Python supports ActiveX. But using VBScript, you can launch Rhino and have it run a Rhino.Python script.


#18

Hi Dale, I was trying this automation example: https://github.com/dalefugier/SampleCsAutomation
When trying to create an instance of Rhino it hangs. Task Manager is showing the process Rhino.exe, but from the description it appears to be the WIP. After some time it gives up trying. Do you have an idea how to get it to work?

Thanks,
Jess


Headless Rhino
(Dale Fugier) #19

Well the command is trying to create a Rhino5x64.Application object and (from your screen capture) Rhino 6 is loading which is a problem. Looks like the WIP installer is hosing COM entries in the Registry that were added by the Rhino 5 installer.

http://mcneel.myjetbrains.com/youtrack/issue/RH-31297

To fix, run REGEDIT and navigate to this key:

HKEY_CLASSES_ROOT\CLSID{D760652E-E256-4064-B308-08CE0711ADF5}\LocalServer32

Modify the entry to point to the Rhino 5 x64 executable.


#20

Thanks Dale!
I was using the interface in the meantime and think I’ll stick with that :wink:
Jess