Quantcast
Channel: Scripting - McNeel Forum
Viewing all articles
Browse latest Browse all 5938

BeforeTransformObjects event never called in CPython on mac

$
0
0

Hi? Please see the code below.
When I run the script with the command !-RunPythonScript, it worked.
But after removing the first line to declare using CPython ( #! python 3 ), it failed.
Is overriding BeforeTransformObjects not allowed anymore or is it a bug?

#! python 3

import Rhino
import scriptcontext as sc

class TransformEventHandler():
def init(self):
self.is_attached = False

def onTransform(self, sender, e):
    print('onTransform test')
    print(sender)
    print(e)

def attach(self):
    if not self.is_attached:
        Rhino.RhinoDoc.BeforeTransformObjects += self.onTransform
        self.is_attached = True

def detach(self):
    if self.is_attached:
        Rhino.RhinoDoc.BeforeTransformObjects -= self.onTransform
        self.is_attached = False

def TestSampleEventHandler():
key = ‘transform_event_handler’
handler = sc.sticky.pop(key, None)
if handler:
handler.detach()
handler = None
print(’ SampleEventHandler disabled’)
else:
handler = TransformEventHandler()
sc.sticky[key] = handler
handler.attach()
print(’ SampleEventHandler enabled’)

if name == ‘main’:
TestSampleEventHandler()

1 post - 1 participant

Read full topic


Viewing all articles
Browse latest Browse all 5938

Trending Articles