Grasshopper

algorithmic modeling for Rhino

I have gotten as far as displaying a windows forms dialogue box from a appended menu item. I am not sure how to gather data that is input into the form, and insert that information into the custom component.

Public Sub ShowForm() As Double

Dim myForm As New Form1
myForm.ShowDialog()
Dim input As New Double
If myForm.ApplyBtn.DialogResult = DialogResult.OK Then
input = CDbl(myForm.TextBox1.Text)
Me.ExpireSolution(True)
End If

End Sub

Public Overrides Sub AppendAdditionalMenuItems(menu As Windows.Forms.ToolStripDropDown)
MyBase.AppendAdditionalMenuItems(menu)
Menu_AppendGenericMenuItem(menu, "Tiered Seating Settings", AddressOf Menu_MyCustomItemClicked)
End Sub

Private Sub Menu_MyCustomItemClicked(ByVal sender As Object, ByVal e As EventArgs)
ShowForm()
End Sub

Views: 645

Attachments:

Replies to This Discussion

Dim param As Param_Number = DirectCast(Params.Input(5), Param_Number)
  Dim value As Double = 0.0
  If (param.PersistentDataCount > 0) Then
    value = param.PersistentData.FirstItem(True).Value
  End If

Dim myForm As New Form1
myForm.TextBox1.Text = value.ToString()
If (myForm.ShowDialog() = DialogResult.OK) Then
  If (GH_Convert.ToDouble(myForm.TextBox.Text, value, GH_Conversion.both)|) Then
    RecordUndoEvent("First Row Horiz Distance")

    param.PersistentData.Clear()
    param.PersistentData.Append(New GH_Number(value))
    ExpireSolution(True)
  End If
End If

This is what I'd do. The logic here is:

  1. Get a pointer to the input parameter we're dealing with.
  2. (not shown above) If the input parameter already has incoming wires, don't show the window, but return immediately.
  3. Harvest the current value, so our window displays something meaningful.
  4. Create a new instance of the form.
  5. (not shown) Make sure the form is near the cursor.
  6. Put the current value into the textbox.
  7. Display the form.
  8. If it returns anything other than OK, abort right away.
  9. Try and parse the newly entered text, if it doesn't parse, abort right away.
  10. Record an undo event so the current value isn't lost forever.
  11. Erase the entire persistent data of the input parameter.
  12. Put in the new value.
  13. Trigger a new solution by telling Grasshopper that this component was modified.

--

David Rutten

david@mcneel.com

Poprad, Slovakia

RSS

About

Translate

Search

Photos

  • Add Photos
  • View All

© 2026   Created by Scott Davidson.   Powered by

Badges  |  Report an Issue  |  Terms of Service