Grasshopper

algorithmic modeling for Rhino

Hi,

I Would like to make a VB component in Visual Studio 2008 that moves objects with the Arrow keys and Page Up and Down keys. I made a Form with three text boxes to store the incremented x, y and z values. But tried several methods to capture the KeyDown event, e.g. with Putting next code in the Form1.vb:    

Private Sub Form1_KeyDown1(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles Me.KeyDown
        RaiseEvent ArrowOrPage(Me, e)
    End Sub

Next to the usual code to access Textboxes. I didn't put a WithEvents statement in the Form1Designer.vb, because I figured that KeyDown belongs to the Form actions.

And then in the Grasshopper VB component in the Sub runscript section I put:

AddHandler m_form.ArrowOrPage, AddressOf ArrowOrPage

And in the extra section:

Private Shared m_form As LeftRightUpDown.Form1

Private Sub ArrowOrPage(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs)
    ' the KeyPreview property of the form must be set to true
    Dim p As Double = 1.0
    Dim bHandled As Boolean = False
    Select Case e.KeyCode
      Case Keys.Right
        m_form.TextBox1.Text = m_form.TextBox1.Text + p
        e.Handled = True
      Case Keys.Left
        m_form.TextBox1.Text = m_form.TextBox1.Text - p
        'do other stuff
        e.Handled = True
      Case Keys.Up
        m_form.TextBox2.Text = m_form.TextBox2.Text + p
        'do more stuff
        e.Handled = True
      Case Keys.Down
        m_form.TextBox2.Text = m_form.TextBox2.Text - p
        'do more stuff
        e.Handled = True
      Case Keys.PageUp
        m_form.TextBox3.Text = m_form.TextBox3.Text + p
        'do more stuff
        e.Handled = True
      Case Keys.PageDown
        m_form.TextBox3.Text = m_form.TextBox3.Text - p
        'do more stuff
        e.Handled = True
    End Select
    Me.owner.ExpireSolution(True)

But when I hit an arrow key Rhino crashes :(

Also I am wondering how I can set p as an input, because it is not in the Sub runscript section.

Any help is much appreciated.

Views: 818

Replies to This Discussion

Hans, I'm not ignoring you, but you posted a big problem and I'm very strapped for time at the moment. I do have something which you may find useful, when you crash Rhino, don't dismiss the Error Report window. Instead leave it on the screen and find the RhinoDotNetCrash.txt on your desktop. It will have a call-stack that led up to the crash as well as some info on the actual exception that went unhandled.

Of course you can also choose to add Try...Catch blocks around your code and evaluate your exceptions directly.

--

David Rutten

david@mcneel.com

Poprad, Slovakia

RSS

About

Translate

Search

Videos

  • Add Videos
  • View All

© 2024   Created by Scott Davidson.   Powered by

Badges  |  Report an Issue  |  Terms of Service