Hi there,
I am trying to understand this sample (found at the bottom of this page):
from Rhino import *
from Rhino.Commands import *
from Rhino.UI import *
class MyMouseCallback(MouseCallback):
def OnMouseDown(self, e):
print "active viewport: {0}".format(e.View.ActiveViewport.Name)
def RunCommand():
m_mc = MyMouseCallback()
m_mc.Enabled = True
RhinoApp.WriteLine("Click somewhere in a vieport ...")
return Result.Success
if __name__ == "__main__":
RunCommand()
If I remove the #$@% stars and substitute the full paths, I get (I think):
import Rhino
class MyMouseCallback(Rhino.UI.MouseCallback):
def OnMouseDown(self, e):
print "active viewport: {0}".format(e.View.ActiveViewport.Name)
def RunCommand():
m_mc = MyMouseCallback()
m_mc.Enabled = True
Rhino.RhinoApp.WriteLine("Click somewhere in a viewport ...")
return Rhino.Commands.Result.Success
RunCommand()
First, when running this in the editor, the editor panel disappears when you launch the script (normal) and "Click somewhere in a viewport ..."
is indeed printed to the command line. But, the editor comes back up before you click in a viewport - which is puzzling, as the script hasn’t finished and is still waiting for you to click somewhere.
Then, if I click in a viewport (the first run), it does print the viewport name I clicked in to the command line. If I run it again, the (correct) viewport name gets printed agan, but twice. Run it again, I get three prints. And that continues for as many times as I run it successively during a session, every run one more line is printed.
Now, all I really want is (for example) to select an object, then click in a viewport and be able to get its name or ID as data, then continue on with the script and do other stuff (using the viewport name for some operation later on)…
But, I have no idea how to actually get the viewport name out of the class - yes, it prints, but I need it outside the class elsewhere in the script. I really haven’t got a clue when it comes to classes and event handling… I tried a bunch of stuff, but nothing has worked so far.
Is there anyone that can explain what I need to do so relatively simply? Also, explain why the posted sample itself doesn’t work correctly after the first run?
TIA, --Mitch