We have a few Python scripts that work well if run as a script but fail if compiled with the RhinoScriptCompiler. FWIW, my script compiler is from Jan 2014. Is there a newer one that I somehow missed?
I can’t post the scripts publicly, but if anyone at McNeel is interested in testing this I can provide the scripts privately.
I have an example of a small script that runs as a script but fails when compiled. I believe the issue has to do with text objects. I will attach the script and a small Rhino file to test with.
All that is happening here is that a file is being opened that has a piece of text named. The script will attempt to find that object using ObjectsByName and then use TextObjectText to retrieve the value.
If you run it as a script it works as expected. If you compile it and run it, the IsText method fails to identify the returned object as text.
I found another case there AddLayer is working in the script but fails when compiled. I realize this is on the issue log, but I thought it can’t hurt to mention this too.
I sure hope we see a resolution to this without having to wait for V6!!
This was a strange one. I was able to get it to work by “importing” a file as opposed to “opening” one. If I opened a file, all methods that started with “Add…” failed, not just AddLayer. By importing the file into a new session that problem went away.
Keep in mind that opening the file worked fine when I ran the script. It was only when compiled did it fail.
I think the real issue here is why the script works good as a script but fails when compiled. If I’m having problems because of poor scripting skills, I would expect the script to fail before it’s ever added to the compilation.
I will attach a small script that will run fine as a script but fail when compiled. Watch the layer pane. If successful a new black layer will be added. If it’s not, then the script failed.
p.s. It might be interesting to note that the small test script I attached a couple of weeks ago also “opens” a file. If you change the “open” to “import” the compiled version works fine.
I can conclusively say that using Rhino.Command("_Open"…) is causing the compiled scripts to fail. Since my last post I’ve run across it 2 more times. Fortunately I’ve been able to substitute Import for Open and worked around this.
Hopefully this information is helpful. Whether the compiler gets fixed or not, it might help others who can’t figure out why their scripts run fine but fail when compiled. In my experience, this is the only issue. I haven’t found any other instance where the compiler caused problems.
Thanks Dan for such a detailed research around this problem. Somebody here at McNeel will definitely be interested in knowing this information. How is the “_Open” command string created? Can you give a small sample? That will help us troubleshoot the compiler code. Thank you again!
Now, with regard to how it fails, I’ve seen some cases where the script just stops at the point where the file is supposed to open, but I’ve seen other cases where it will continue until the first method with the word “Add” (such as AddText).
Hopefully there is some useful information here. I know I went through a lot of frustration until I narrowed this down.
It also behaves differently between a script and a compiled version. In the script, the new file will open without prompting the user to save. In the compiled version it still prompts.
Bumping this thread as I also experience similar issue in v6.0. When a module is compiled, rs.Command() does not execute as intended.
Attached is a sample “Printer” command which executes the “-_Print” command.
It works if you run as a script, but running “Printer” does not execute the scripted commands.
Yes, this is still on my todo list at https://mcneel.myjetbrains.com/youtrack/issue/RH-29456
It is not a 6.0 issue as it is not required for shipping 6 and I’m still not sure if this is a problem with the compiler, Rhino, or both
Hi, wondering if there is any word on this or if someone has uncovered a work-around. In my case I have a command that uses CurveBoolean as part of the logic, so I’m a bit lost on how to make the script work as a plug-in command.