algorithmic modeling for Rhino
Hi everyone,
can anyone tell me how can I assign a default value to this inputparameter code line:
pManager.AddInterval2DParameter("Domain²", "I", "New domain²", GH_ParamAccess.item)
For the most parameter types I know their default value can be set after the GH_ParamAccess. But I can't get it to work for the two-dimensional domain.
(I always wondered why the Divide Domain² component didn't have a default (wish: u:{0 To 1} v:{0 To 1}), so I'm starting to think this is impossible)
Also I'm wondering what the difference is between (GH_)Interval2D and UVInterval, maybe my mistakes are caused by that.
I created my default two-dimensional domain called "domain2D" using:
Private domain1D As Interval = New Interval(0, 1), domain2D As UVInterval = New UVInterval(domain1D, domain1D)
So now the goal is to get this default to the AddInterval2DParameter line.
I tried:
pManager.AddInterval2DParameter("Domain²", "I", "New domain²", GH_ParamAccess.item, domain2D)
but got the message "Too many arguments to 'Public Function AddInterval2DParameter ... '." I figured it was time to ask...
Is there a way to set this default, and would you teach me it?
Excuse my VB-language ;)
Tags:
It is possible, but you have to add the data yourself, after you create the parameter.
pManager.AddInterval2DParameter(blahblahblah)
Dim param As Param_Interval2D = DirectCast(pManager[0], Param_Interval2D)
param.AddPersistentData.SetPersistentData(New GH_Interval2D(blahblah))
I haven't tried the code, but something along these lines...
--
David Rutten
david@mcneel.com
Great, great! Thanks I'm gonna try. Should have read up on this casting...
Should I just replace my current interval2D parameter line with this one, and substitute my own blahs?
You can keep your original parameter, just be sure to use the correct index when accessing it. Zero is only good if it's the first parameter on your component.
Casting is important to know about, In VB you're typically ok with DirectCast and TryCast.
--
David Rutten
david@mcneel.com
Okay, I got it working:)
Despite the warning in the SDK not to confuse UVinterval and GH_Interval2D, it's confusing (for me).
It turns out the needed GH_Interval2D to use as a default, can be based on a UVInterval (does that count as casting?), and this code is what I ended up using:
pManager.AddInterval2DParameter("Domain²", "I²", "New 2D domain", GH_ParamAccess.item) '/// nothing new here.
'/// declaring a default Domain² for the input.
Dim param As Param_Interval2D = DirectCast(pManager(1), Param_Interval2D) '/// cast to the correct input number, in this case the second input.
param.PersistentData.Append(New GH_Interval2D(New UVInterval(New Interval(0, 1), New Interval(0, 1)))) '/// the new GH_Interval2D is created from a UVInterval!
Minor remarks: I noticed that some Domain² in- or outputs use the character "I", I think using "I²" for all of them would be clearer.
Also I'd really like the DivideDomain² to have this default value. (I have one with an internalised Domain² saved as a UserObject, but I can't remove the original component.. or can I?)
Many thanks for the directions David, though I had the full headless chicken experience for quite a while, I got it done:)
Cheers!
The problem I had in early GH development was thus:
The solution I chose was to demand that all data flowing through Grasshopper wires implements the IGH_Goo interface, which enforces all of the aforementioned behaviours I'm interested in. You can't use System.Boolean, you have to use GH_Boolean instead, which wraps around System.Boolean and provides an implementation of IGH_Goo. Same is true for Int32 -> GH_Integer, String -> GH_String, Brep -> GH_Brep.
I've tried hard to make sure that as a component developer, you almost never have to deal with IGH_Goo, you can always just request the type you care about.
Sometimes the data doesn't come from .NET or the Rhino SDK. For example TwistedBox, Compound transformations and UVInterval are actually defined inside Grasshopper. However the approach is the same. GH_Interval2D is to UVInterval what GH_Integer is to System.Int32
Long story short; UVInterval is the type you want to work with, GH_Interval2D is just a wrapper class which provides the necessary IGH_Goo implementations.
Your code is correct as well:
New GH_Interval2D()
Though I'd probably put it on two lines for readabilities sake:
Dim intuv As New UVInterval(New Interval(0, 1), New Interval(0, 1))
param.PersistentData.Append(New GH_Interval2D(intuv)
--
David Rutten
david@mcneel.com
I'm really very grateful for you taking time to explain this stuff David. You just cleared some more fog for me, hopefully for others too. Still, plenty of fog left to ensure I'll never be bored;) And my appreciation is only growing the more I learn about what it takes to make the grasshopper hop the way it does.
Welcome to
Grasshopper
Added by Parametric House 0 Comments 0 Likes
Added by Parametric House 0 Comments 0 Likes
Added by Parametric House 0 Comments 0 Likes
Added by Parametric House 0 Comments 0 Likes
Added by Parametric House 0 Comments 0 Likes
© 2024 Created by Scott Davidson. Powered by