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: 5797

Replies to This Discussion

Just as you wrote it, I guess:

Dim component As IGH_Component = TryCast(owner, IGH_Component)
If (component Is Nothing) Then
Print("This should never have happened, but the owner of this script is not a component.")
Return
End If


If (component.Params.Input.Count = 0) Then
Print("The script component needs at least a single input parameter.")
Return
End If

The thing I am not getting is , how to 

recieve them all afterwards. I tried 

Dim param As IGH_Param = component.Params.Input(0)

Dim ighList As List (Of IGH_Param) = param.Sources
Dim inParam As IGH_Param = ighList(0)

Dim names As String = inParam.nickname

A = names

But this just returns (0) of ighList.

Do I have to reference all items by index?

Missing some basics here.

Can somebody give me a hint please?

If you want to output all the names of all the sources of the first input parameter, you'll need to create a list:

Dim names As New List(Of String)

For Each source As IGH_Param in component.Params.Input(0).Sources

  names.Add(source.NickName)

Next

A = names

--

David Rutten

david@mcneel.com

Poprad, Slovakia

Its not really what I am trying to achieve.

I think I have to be more clear.

See, this is what I want:

This is what I meant with same tree structure as the input. 

How is this possible?

Attachments:

You'll need to make a DataTree<string> to store your data in. The following code is untested, but I think it probably works:

DataTree<string> names = new DataTree<string>();

IGH_Param input = Params.Input[0];
foreach (IGH_Param source in input.Sources)
{
  string name = source.NickName;
  IGH_Structure data = source.VolatileData;
  foreach (GH_Path path in data.Paths)
  {
    names.Add(name, path);
  }
}
A = names;

ps. I realizes you're using VB, you can use this page to convert the code.

--

David Rutten

david@mcneel.com

Poprad, Slovakia

Thank you!

p.s.: great page - didn´t know that , thank you again.

I have tried to reconfigure the VB in this example so that I can output data to excel through tttoolbox.

no luck... I'm not very grammatically / script gifted.

I have lines with nicknames ... sometimes a single line sometimes a list of lines..

I want to pass the nickname and line length data of each line to tttoolbox...

Like the entwine data component... but also passing on the nickname data.

Any ideas?

What I am trying, is to get a list of each input component with it's nickName and value output as a list instead of as an array.

I hope I'm making sense.

Actually, All I needed was a simple list out of each nickname connected to the x input.

So I got (nearly) that by removing step 4 "creating the tag string." then I set a to only output the names....

    '3. Get the first input parameter, and collect all source nicknames in a list.
    Dim param As IGH_Param = component.Params.Input(0)
    Dim names As New List(Of String)
    For Each source As IGH_Param In param.Sources
      names.add(source.NickName)
    Next

    '5. Assign the tag to the output A.
    A = names

This still gives me too much output but I can clean it up in grasshopper. Using tree branch and path {0;0} and taking the result into the rows input of tttoolbox

 ... as long as I connect my lines in the same order to the entwine and the VB script I can get a nice output

ok it's not ideal but it works for me just now... I'll have to put comment on the .gh definition to make it clearer

Thanks guys

RSS

About

Translate

Search

© 2024   Created by Scott Davidson.   Powered by

Badges  |  Report an Issue  |  Terms of Service