Issue: EventListener callback is not executed in ScriptEditor

Hi there,

i am experiencing issues with Events in combination with the scriptEditor

I have used the mechanism below to listen to view change events. When I execute the code in the old editor (editPythonScript / runPythonscript ), my events trigger the callback as expected
image

however when I execute the same script in the scriptEditor, the callback is not triggered. The same issue occors for at least the folllowing:

  • Rhino.RhinoDoc.CloseDocument
  • Rhino.RhinoDoc.BeginOpenDocument
  • Rhino.RhinoDoc.EndOpenDocument
  • Rhino.RhinoDoc.InstanceDefinitionTableEvent

hopefully someone can help me out

Thanks,
Tim

import Rhino
import scriptcontext as sc

def callback(sender, e):
    print('view has changed')

if __name__ == '__main__':
    event = Rhino.Display.RhinoView.SetActive
    key = 'AutoLockSheetListener'
    if sc.sticky.has_key(key):
        func = sc.sticky[key]
        event -= func

        del sc.sticky[key]
        print("%s: remove callback" % key)

    else:
        func = callback
        event += func
        sc.sticky[key] = func
        print("%s: add callback" % key)

@timcastelijn

Use Rhino.RhinoApp.WriteLine instead of print.

Currently the print function is only capturing output during script execution. This script runs, signs up the event handlers and then ends.

I’m in the process of improving this so this is a workaround. For reference this is related to this comment

Thank you @eirannejad!

1 Like