Hi everybody, I’ve been having this issue for a while now and with a ton of time debugging I’ve finally induced the error in 3 lines:
`import rhinoscriptsyntax as rs
except Exception as e: print(e)`
the code will execute perfectly in the python script editor command in Rhino, but for some reason when compiled, it will throw the following error:
‘NoneType’ object has no attribute ‘Objects’
I’ve tried printing type(rs) and it returns module so I have no idea why it is giving an error saying NoneType. My speculation is that this error diagnosis is incorrect, I’m not sure this is a type of error that would be normally handled by python.
Also by the way, I’ve gotten other rs commands to work, but in the script I developed that has a lot of work into it, this sort of command is pretty crucial.
Any suggestions? Seems like rhinoscriptsyntax is not imported correctly… but why
How are you compiling this?
you might get rid of the problem by removing the try/except block alltogether.
rs.AddCurve() raises it’s own exceptions if 1. The curve cannot be created and 2. If it could not be added to the document. Something like this should be equal and run after compilation:
import rhinoscriptsyntax as rs
new_curve_id = rs.AddCurve(((1,2,3),(1,2,4)))
if not new_curve_id: raise Exception("Your error text")
btw. it might be better if you pass the points as list but this is not related to the problem.
The above posted script is not my script but rather something I wrote up to induce the same error I am coming across. The reason I incorporated the try/except blocks was because Rhino does not print Error messages when the script is compiled in a plugin. The try/except and print(e) is the only way I could debug an error that occurs when the script is compiled, but not when the script is ran through the editor.
In my actual script, I get an error at the rs.AddCurve line, although there is no output because the script will not run.
OK. In all the scripts i´ve written and compiled using the Rhino Script compiler, i never used pythons built in exception mechanism but my own error handling. All the errors print if the checks for them have been properly added. Apart from this, Rhino Python seems to swallow some errors in delegates even when the script runs from the editor.
There is a small discussion about it here.
Well I dont think the rs.AddCurve is even getting executed (in order to give the non existent curve) otherwise that seems like a good idea. Its just strange why if its the same script, it can run in the editor but not as a plugin.
I checked that link, but not quite sure what you mean by swallowing errors in delegates.
- Could it be possible that that compiler incorporates an older version of the rhinoscriptsyntax module than the one that is imported in the editor? or at the very least a different version?
Unlikely but you might find out if the proper module is called by adding a temporary custom print message to it. The
rs.AddCurve() method is located in the
curve.py module which is saved here:
Note that you have to change
USERNAME in the above path and before running your script or plugin command, open the python editor and choose “Reset script engine” from the tools menu. Otherwise the loaded module is re-used and the temorary print message is not fired.
Alright, so, that helped a lot thanks. Im getting closer. I found the source of " ‘NoneType’ object has no attribute ‘Objects’ " and as expected, its in the AddCurve function. What it is is scriptcontext.doc.Objects. For some reason scriptcontext is defined as a module but scriptcontext.doc is a ‘NoneType’ and does not have the attribute Objects.
Here is a copy of my scriptcontext module:
# scriptcontext module
import RhinoPython.Host as __host
'''The Active Rhino document (Rhino.RhinoDoc in RhinoCommon) while a script
is executing. This variable is set by Rhino before the exection of every script.
doc = None
'''Identifies how the script is currently executing
1 = running as standard python script
2 = running inside grasshopper component
3... potential other locations where script could be running
id = 1
'''A dictionary of values that can be reused between execution of scripts
sticky = dict()
def escape_test( throw_exception=True, reset=False ):
"Tests to see if the user has pressed the escape key"
rc = __host.EscapePressed(reset)
if rc and throw_exception:
raise Exception('escape key pressed')
The default error handler called by functions in the rhinoscript package.
If you want to have your own predefined function called instead of errorhandler,
replace the scriptcontext.errorhandler value
and indeed there is the statement ‘doc=None’ where the comment says it is set by Rhino before execution (see above). Any idea why this wouldnt be setting in a plugin?
*Also by the way would you mind telling me the html for python code?? thanks
The forum doesn’t primarily use html to format text. See this post for finding out how to format python code: Category definition for Scripting
Hey really appreciate the help guys, this has been an issue bothering me for awhile although ive only recently gotten back at it.
Sort of a last ditch attempt, but I wasnt able to find a solution and downloaded the updated version of the compiler and it works! Possibly a bug somebody discovered in the past I guess.
Thanks for the help
Good, i remember there have been some changes in the compiler related to scriptcontext. The problem description is somewhere in the compiler thread.