Scripts that will run good as scripts fail when compiled

unhandled

#1

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.

Thanks,

Dan


(Dale Fugier) #2

@DavidRutten @stevebaer, any help here would be appreciated.


#3

Hi @stevebaer @DavidRutten @dale

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.

Thanks,

Dan

TestFailure.py (560 Bytes)
TestFailure.3dm (66.9 KB)


(Dale Fugier) #4

Hi Dan,

Thanks, I’ve logged the issue.

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


#5

Hi @dale @stevebaer @DavidRutten

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!!

Thanks,

Dan


#6

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.

Thanks,

Dan

TestFailure.py (622 Bytes)

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.


#7

Not sure if anyone cares, but I found another case where opening a file in a Python script works as a script but fails when compiled.

Dan


#8

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


(Giulio Piacentino) #9

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!

Giulio

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


#10

Hi Guilio,

Here is a snippet that will fail once compiled:

filter = "Rhino 3D Models (*.3dm)|*.3dm;|All Files (*.*)|*.*;||"
folder = "C:\\Cad\\"
strFilename = rs.OpenFileName("Select a file to view", filter, folder)
rs.DocumentModified(False)
rs.Command("_-Open " + chr(34) + strFilename + chr(34) + " _Enter", False)

Changing the command to “import” will work once compiled:

filter = "Rhino 3D Models (*.3dm)|*.3dm;|All Files (*.*)|*.*;||"
folder = "C:\\Cad\\"
fileName = rs.OpenFileName("Select a File to View", filter, folder)
rs.DocumentModified(False)
rs.Command("_-Import " + chr(34) + fileName + chr(34) + " _Enter", False)

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.

Thanks,

Dan


#11

Hi Giulio,

You might want to take a look at this too:

rs.DocumentModified(False)
rs.Command("_-New _None ", False)

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.

Dan


#12

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.

Printer_cmd.py (439 Bytes)

T


(Giulio Piacentino) #14

@stevebaer you had some plans on revising the compiler, right?


(Steve Baer) #15

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


#19

Hi stevebaer,
I have the same problem with the compiler, like i post here: Help! Rhino Script Compiler works error
I also need your support. Thank you.


(Sean L) #20

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.