Grasshopper

algorithmic modeling for Rhino

Is it possible to get the name of a component attached to an input of a Python script component?

I would like to be able to parse and concatenate multiple parameter names and their current values to generate file and layer names. It's easy enough to do this with regular components of course. But I'd like to pack it all into one component and have it generate names automatically.

Views: 4116

Replies to This Discussion

Hi,

Here's my attempt at a solution. It doesn't work perfectly because input at y should be 'My super circle' instead of 'c'. Anyone knows how to get the component that contains the param?

forgot the file

Attachments:

Thanks Jason,

Your script is getting the nickname of the output at each input.

Does anyone know how to grab the Nickname of the component? or other properties? Better yet, how do I look up such info myself?

Attachments:

Hi Jonah,

This function will return the connected component and then check component.Name and component.NickName:

https://github.com/mostaphaRoudsari/ladybug/blob/master/src/Ladybug...

Thanks Mostapha,

I obviously don't know how to provide this function with its first parameter. I need to learn the basics I guess... how to pass an int iterator to that first param in your function, for starters. In MaxScript I'm used to

for i = 0 to foo.count do (

getListOfConnectedComponents(i, False)

)

Here I tried:

info = []

for input in list(range(ghenv.Component.Params.Input.Count)):

    for s in list(range(ghenv.Component.Params.Input[input].Sources.Count)):
        print getListOfConnectedComponents(s,False)
        info.append('Input at {0} = {1}'.format(ghenv.Component.Params.Input[input].Name,getListOfConnectedComponents(s,False)))

a = info

Attachments:

Hi Jonah, Check the attachment:

Attachments:

Hi Jonah,

This is a bit redundant, but I simplified my original code based on Mostapha's solution (Thanks!).

info = []

for input in ghenv.Component.Params.Input:
    for s in input.Sources:
        attr = s.Attributes
        if (attr is None) or (attr.GetTopLevel is None):
            pass
        else:
            component = attr.GetTopLevel.DocObject
        info.append('Input at {0} - {1}'.format(input.Name,component.NickName))

a = info

Attachments:

Great solution, just what I need to pass on color shader nicknames onwards as they're "code" is in RGB , which I do not want in my output.

Would it be possible to modify this so it doesnt say "Input at x/y/z - " So its only output is the Nickname in a list?

I dont know Python so I cant do it myself.

I don't have access to rhino right now. My python's not great - but I think i may know this one.

If you have the node working and you realise the nickname is what you would like - i noticed the thread is quite old and your question quite recent, so here's a general effort worth a stab .... 

Without testing I would think

replace : 

 info.append('Input at {0} - {1}'.format(input.Name,component.NickName))

with : 

info.append(component.Nickname)

(python is formatted according to indentation so it is essential to have the correct level of indentation (i.e. blank spaces on left of text - it is personal preference whether users tab to indent or use two spaces - it appears the original writer has used tab) - the phrase i have written above must match the indentation of the 'else' statement 

I'll try to remember to check this at work tomorrow when i have access to rhino. Good luck and crossed fingers 

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