Hi:
When I run this script, if I want to rotate the viewport, I must put the cursor on the “Press J or K” window, or it just iuput string to rhino.
I need wherever my cursor is in rhino, I will rotate the viewport by key “J” or “K”, think you.
import Rhino
import System.Drawing
import System.Windows.Forms
import scriptcontext
class Form1(System.Windows.Forms.Form):
def __init__(self):
self.InitializeComponent()
def InitializeComponent(self):
self._button = System.Windows.Forms.Button()
self.SuspendLayout()
self._button.Location = System.Drawing.Point(150, 67)
self._button.Size = System.Drawing.Size(75, 23)
self._button.TabIndex = 0
self._button.Text = "Done"
self._button.Click += self.ButtonClick
self.ClientSize = System.Drawing.Size(250, 102)
self.Controls.Add(self._button)
self.KeyPreview = True
self.Text = "Press J or K"
self.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedToolWindow
self.KeyDown += self.OnKeyDownEvent
self.Closing += self.OnClosingEvent
self.ResumeLayout(False)
def ButtonClick(self, sender, e):
self.Close()
def OnKeyDownEvent(self, sender, e):
left = e.KeyCode == System.Windows.Forms.Keys.J
right = e.KeyCode == System.Windows.Forms.Keys.K
if left or right:
amount = 0.1
if right: amount = -0.1
viewport = scriptcontext.doc.Views.ActiveView.MainViewport
z = viewport.ConstructionPlane().ZAxis
viewport.Rotate(amount, z, Rhino.Geometry.Point3d.Origin)
scriptcontext.doc.Views.Redraw()
finish = e.KeyCode == System.Windows.Forms.Keys.Escape
finish = finish or e.KeyCode == System.Windows.Forms.Keys.Enter
if finish:
self.Close()
e.Handled = True
def OnClosingEvent(self, sender, e):
Rhino.Input.Custom.GetBaseClass.PostCustomMessage("exit")
f = Form1()
f.Show(Rhino.RhinoApp.MainWindow())
gs = Rhino.Input.Custom.GetPoint()
gs.AcceptCustomMessage(True)
gs.Get()
if not f.IsDisposed:
f.Close()