Grasshopper

algorithmic modeling for Rhino

Is it hard to bake objects that you add UserText into via Grasshopper? Is this possible with a simple addition to your script?

Views: 597

Replies to This Discussion

Hi Chris no it's fairly easy.

myCrv.UserDictionary.Set("myKey",myValue);

RhinoDocument.Objects.AddCurve(myCrv);

That's it basically.

Great! Thanks!

I think I got it. But it only let's me do one Key/Value pair. I tried putting the new code block into a for loop, but I think I'm missing something in the C#, which I am not familiar with. I have no idea what is going-on on this particular line:

string utKey = utKeys.Count > 0 ? utKeys[i % utKeys.Count] : null;

Attachments:

Hi Chris,

i see this is Giulio's script. You can set multiple key/values with it, but just one for each geometry. See the attachement for a working modification of the script.

The above line is getting sure, that a value exists for the current iteration of the loop.

i is the iterator. So the % (Modulo) of i and utKeys.Count gets sure, that the index doesn't get out of range.

the line is a shorthand for if else and basically means the same as:

string utKey;

if(utKeys.Count > 0)

    utKey = utKeys[i%utKeys.Count];

else

    utKey = null;

Attachments:

Thanks again. I didn't realize that you had your own components until later in the day yesterday. I see that yours are locked. Were you referring to a way to do this with your components in the first comment?

Yes. I do not use UserStrings...i do prefer UserDictionary, cause it allows you to store any type of information, not just strings. UserDictionary can't be viewed in Rhino though.

It depends on what you're trying to do. What's the purpose?

I'm using Python inside and outside of Grasshopper. I'm trying to be able to store data in objects in both cases. I can store any data I want as long as I pickle it. Pickling is a way of encoding Python objects into text.

So then UserStrings is the right thing.

RSS

About

Translate

Search

Videos

  • Add Videos
  • View All

© 2024   Created by Scott Davidson.   Powered by

Badges  |  Report an Issue  |  Terms of Service