Question regarding RhinoPythonCommands

What could be the reason a python script to be running just fine but after compiling it to a command to not work?

I know I don’t provide any information, but the information would be me sharing the script and I am not allowed.

Just please if anyone else has experienced it, share so I can look into it and fix it.

Thanks.

What I can share is:

This is my command that doesn’t work, the method exists in that same python file.

def RunCommand( is_interactive ):
    method_to_run()
    
    # you can optionally return a value from this function
    # to signify command result. Return values that make
    # sense are
    #   0 == success
    #   1 == cancel
    # If this function does not return a value, success is assumed
    return 0

When I run if from the editor like so, works:

if __name__=="__main__":
    ts = time.time()
    rs.EnableRedraw(False)
    
    method_to_run()
    
    print "Elapsed time is {:.2f}".format(time.time()-ts)

Update:

Something I noticed:
When I click to Reset Python Engine afterwards I get this:

image

then this, after clicking OK:
image

This is line 13:
image

Hi,

I get this all the time and learned to live with it.
The issue seems to be that the scriptcontex is not (properly) loaded or at least scriptcontext.doc is None
As you can see from the traceback, as it has no attribute ModelAbsoluteTolerance

The reason I never tried to find a solution is that I run into this while having multiple instances open and running scripts here and there.
If in your case you are running under ‘normal’ conditions it should not be happening.

I suppose @stevebaer might be able to give some insight why the scriptcontex.doc can end up being None.

-Willem

Hi Ivelin,
You can replace the sc.doc with Rhino.RhinoDoc.ActiveDoc.
Maybe this solves the issue.

1 Like

I can’t. I thought this was fixed so if there is a repeatable case where I can see the scriptcontext becoming “None”, then please send it to me.

1 Like