Grasshopper

algorithmic modeling for Rhino

Hi,

I am building a customised GH component Visual Studio (vb.net). I have to say that this is my first experience with VS. I already managed to create "standard" components using the GHA assembly wizard (which is really helpful by the way!).  Now, I want to add radio buttons within my component. I started from an existing script which works (using Reflector), and I added those lines : 

Private _group As MenuRadioButtonGroup
Private calculate As List(Of Boolean)

Private Sub _group__valueChanged(ByVal sender As Object, ByVal e As EventArgs)
Me.calculate = DirectCast(sender, MenuRadioButtonGroup).GetPattern
Me.ExpireSolution(True)
End Sub

Protected Overrides Sub OnComponentLoaded()
Me.calculate = Me._group.GetPattern
End Sub

Protected Overrides Sub Setup(ByVal attr As GH_ExtendableComponentAttributes)

...

End Sub

My problem is that MenuRadioButtonGroup type is not recognized. Which extra reference do I have to import ? And where can I find it ?

Also, there a message concerning the 'Protected Overrides Sub OnComponentLoaded()' line : it is not possible to override sub OnComponentLoaded() because it cannot substitute to a sub in a base class. Any idea ?

Views: 1099

Replies are closed for this discussion.

Replies to This Discussion

MenuRadioButtonGroup appears to be something custom. I can't find any record of it online. If you google it this discussion actually comes up second, with something java-ish taking first place.

I'm a bit confused though, are these radio buttons supposed to exist on the Component menu or on the component itself? If they are on the menu, is the menu supposed to close when a new radio button state is selected by the user?

--

David Rutten

david@mcneel.com

Poprad, Slovakia

David,

The buttons are on the component itself. Maybe there is another way to do it, if you have any idea. I'd like to keep using vb.net to do it. I guess it should be possible using System.Windows.Form library ?

Grasshopper is indeed based on winforms, but you should not use winform controls on the canvas. If you want to override the default display and mouse-handling of GH_Component derived classes what you need to do is provide your own Attributes. There is a short topic in the Grasshopper SDK documentation about creating custom attributes however it focuses on overriding floating parameters rather than components.

What you need to do is the following:

  1. Create a new class that derives from Grasshopper.Kernel.Attributes.GH_ComponentAttributes
  2. Override the CreateAttributes method on your GH_Component and assign a new instance of those custom attributes to the m_attributes protected field.

You can now start overriding methods on your custom attributes that will allow you to tweak the layout, display and mouse event handling. This is not trivial, there's a lot of code needed to get it right (especially for components).

If you don't mind violating the license agreement then you can use Reflector or ILSpy to have a look at the classes Grasshopper.Kernel.Special.GH_GradientControl and Grasshopper.Kernel.Special.GH_GradientControlAttributes in Grasshopper.dll. In the ExpressionComponents namespace of Mathematics.gha you will find the Evaluate and Expression objects which are also very informative.

--

David Rutten

david@mcneel.com

Poprad, Slovakia

David,

I already use Reflector, but I think this is far beyond my knowledge. I'll forget radio buttons for a while...

Thanks anyway!

RSS

About

Translate

Search

Videos

  • Add Videos
  • View All

© 2024   Created by Scott Davidson.   Powered by

Badges  |  Report an Issue  |  Terms of Service