Closed bengolder closed 13 years ago
from scriptcontext import doc
Is not a good thing to do in a separate module. Modules in python are loaded and executed once. This means that the doc variable will point to the correct doc the first time the module is run, but may be pointing to an incorrect doc when the module is run in the future. I would recommend always calling scriptcontext.doc instead.
Thanks Steve.
also, I probably could have avoided this by calling RhinoDoc.ActiveDoc
instead of scriptcontext.doc
in my separate modules.
I would avoid RhinoDoc.ActiveDoc if possible and always use scriptcontext.doc. Mac Rhino is a multi-doc application and the ActiveDoc can switch.
Thanks Steve! will keep that in mind.
Variable assignment (document switching) is something that should not be sticky between sessions in any way. Also, I just tried the steps described above now and nothing happens, so a first guess would be that the crash depends later from additional side effects in the script... it might be in different places.
Did you manage to isolate the provoking part in the script? If not, can you check if, after reducing the script to a minimum set of operations and restarting Rhino, the crash disappears?
before I could find the steps to recreate it, I tried another reinstall of grasshopper in order to resolve it. That worked. I can switch target docs again.
Now I'll see if I can break it again.
I think I broke something. If I open rhino 5 and grasshopper (after a fresh reinstall of both and a reboot), get out a new ghpython component and try to switch the target doc, Rhino crashes.
This started happening after I did the following:
I created a module (I'll call it
module1
) to be imported by the ghpython script. In this module I had a line like this:I assumed that when I imported the module, it would use the same target
doc
as set by the ghpython component, but it does not. Instead each imported module targets only the gh doc, not the rhino doc.So then I tried something that seems to have broken the ghpython component. In the imported module, I removed the line containing
from scriptcontext import doc
. But within the module, I had functions that still made use of a module-level global variable calleddoc
that was not assigned within that module. So I tried to pass thedoc
object from the ghpython script into the module like so (as seen in the ghpython script):The script ran once, correctly using the rhino doc as the target doc for both myfunction as well as in the ghpython script. Then Rhino crashed, and I haven't been able to set the target doc without crashing Rhino since.
I'm curious how and if I really broke something that could not be fixed with a reinstall and a reboot.
Thanks.