Grasshopper

algorithmic modeling for Rhino

Hello...

Is there any way I can access the name a user puts onto a component (via the context menu), and use that at runtime?  This would be a compiled component.

Lets say that the input is a string "hello"  and the user changes the name of the component to "hello."  Can I test if the input string and the name are the same in order to condition the output?

Thanks!
Luis

Views: 6013

Replies to This Discussion

hi luis

maybe look at this
system.ComponentModel.Design.ComponentRenameEventHandler();

-to]
Hello -to],

Interesting, not at all the place I was looking for it. Now, this is a system namespace...I would have guessed this was more a GH_* thing? Ok, well, lets see where this leads! Thanks man!

luis
maybe sth more like this...

public delegate void GH_MenuTextBoxTextChanged(
GH_MenuTextBoxCollection sender,
string iText
)
Hi Luis,

the "name" of an object that the user can change is actually called NickName inside the SDK. All objects on the canvas have the following members which are implemented from IGH_InstanceDescription:

- Name (official name)
- NickName (name displayed in UI, changeable by user)
- Description (brief explanation of what the object does, visible in Tooltips)
- Category (name of the tab that contains the object)
- SubCategory (name of the panel that contains the object)

There's a bunch more, but these are the most important ones.

When you're inside a VB or C# script, there is a member variable called owner of type:
Grasshopper.Kernel.IGH_ActiveObject

IGH_ActiveObject derives from IGH_InstanceDescription, so the NickName of the component itself should be available as follows:
Dim nn As String = owner.NickName


If however you want the nicknames of input parameters, then you have to cast the owner object to a GH_Component. GH_ActiveObject is lower in the inheritance hierarchy and it doesn't know about input and output parameters. So, in order to get the nickname of the first input parameter, do:

Dim cmp As GH_Component = DirectCast(owner, GH_Component)
Dim nn0 As String = cmp.Params.Input(0).NickName



There are events that are raised whenever nicknames change, but I don't think you want to go in that direction.

At any rate, system.ComponentModel.Design.ComponentRenameEventHandler doesn't have anything to do with Grasshopper Components.

--
David Rutten
david@mcneel.com
Turku, Finland
Hello David,
That is excellent! The nickname is exactly what I was looking for. Tested it out on a vb component and it seems to be functioning very well. I was thinking of this for incoming OSC Messages...a user could change the Nickname of the component to the name of the device...if the name of the device from the incoming message matches the nickname, then that data is stored...


Are there any extra considerations when compiling a component with this info you have provided? I could imagine that I would need to set up what the active object is?
For future reference. I was able to get the nickname of the component instance from the base...

in a C# project (_nn is a string):

_nn = base.NickName;


Any hints on adding the functionality of a wifi/receiver input?
hi luis

maybe this time i am right ;)
reflect GH_Receiver (Grasshopper.Kernel.Parameters.GH_Receiver)
to],

I was checking out the receiver component where you specified and it derives from something other than GH_Component...in this case GH_Param. So I would be assuming that I would need to construct it very similarly to this...but I think I would be assuming too much.

David, could we get that functionality in GH_Component (if it does not already exist through overriding)?
True, the Receiver object derives from GH_Param. You can cast objects to parameters in the same way as you'd cast objects to components:

Dim param As IGH_Param = DirectCast(someobjectyouknowforsureisaparameter, IGH_Param)


IGH_Param is a fairly simple object type. GH_Component is much more complex as it contains the component logic plus any (variable) number of input and output parameters.

Most special objects in Grasshopper derive from IGH_Param (TextPanel, GraphMapper, ParamViewer, BarGraph, Slider etc., notable exceptions being Gradient, Legend, Timer and Scribble which are just basically weird).

The Receiver object is nothing more than a Generic Parameter with an overridden display function.

--
David Rutten
david@mcneel.com
Turku, Finland

Hello, 

 

is it possible to inherit the NickName of a param plugged in a custom component then? Do I still have to cast the input parameter where the param is plugged into and then cast it to an IGH_Param or am i just talking nonsense? 

 

Thanks, 

Odysseas

To get the names of the input components nickname:



'access the vb component

Dim cmp As GH_Component = DirectCast(owner, GH_Component)

'access the first parameter input of VB component

Dim param_0 As IGH_Param = DirectCast(cmp.Params.Input(0), IGH_Param)

'access the list of input components

Dim ighList As List (Of IGH_Param) = param_0.Sources
Dim inParam_0 As IGH_Param = DirectCast(ighList(0), IGH_Param)

'prints the nickName of the first input component
Print(inParam_0.NickName)

Hi Dirk,

sorry, is there a question? You don't need this btw: 


  Dim param_0 As IGH_Param = DirectCast(cmp.Params.Input(0), IGH_Param)


Params.Input is already a collection IGH_Param, so you don't have to cast them:


  Dim param_0 As IGH_Param = cmp.Params.Input(0)


--

David Rutten

david@mcneel.com

Poprad, Slovakia

RSS

About

Translate

Search

Photos

  • Add Photos
  • View All

Videos

  • Add Videos
  • View All

© 2024   Created by Scott Davidson.   Powered by

Badges  |  Report an Issue  |  Terms of Service