algorithmic modeling for Rhino
I would like to integrate user fields or user attributes as Zone, Workpiece list naming, workpiece number, ... do you know if it is possible to do that with bake module ? I know that it is possible with ExcelWrite module, I would like to do the same.
Thank you.
Tags:
There are a couple mechanisms by which you can add data to objects in Rhino once baked. There's "UserText", attached to either the object's attributes or to the object's geometry, as well as a UserDictionary that is more customizable. To configure either from within grasshopper, you'll need to take advantage of some custom scripts. The advantage of using UserText rather than the UserDictionary is that it can be accessed directly in Rhino with standard commands - "SetUserString" and "GetUserString". UserDictionary lets you attach more complex data than strings, but as far as I know cannot be accessed in rhino directly.
Here are some examples in c# of how to access each:
to set user text, attached to an object:
private void RunScript(bool bake, GeometryBase geo, string key, string val, ref object A)
{
geo.SetUserString(key, val);
if(bake){
RhinoDocument.Objects.Add(geo);
}
}
to set user text, attached to an object's attributes:
private void RunScript(bool bake, GeometryBase geo, string key, string val, ref object A)
{
Rhino.DocObjects.ObjectAttributes att = RhinoDocument.CreateDefaultAttributes();
att.SetUserString(key, val);
if(bake){
RhinoDocument.Objects.Add(geo, att);
}
}
to modify an object's userdictionary:
private void RunScript(bool bake, GeometryBase geo, string key, string val, ref object A)
{
geo.UserDictionary.Set(key, val);
if(bake){
RhinoDocument.Objects.Add(geo);
}
A = geo;
}
to retrieve a value from an object's userdictionary:
private void RunScript(GeometryBase x, string key, ref object A)
{
A = x.UserDictionary[key];
}
See the attached definition for examples of each. Hope that helps!
This would be an interesting add-on to grasshopper or directly built into the next versions, especially when sending pieces to fabrication, certain build shops can use keys and values to pilot their machines.
Thanks Andrew, your examples are great!
Hi Andrew,
I had some time to play with your examples. I am fairly new to C# so I have a question:
If I have multiple attributes for a single geometry, how do I go about in incorporating these keys and values into a single geometry?
At the moment, when I bake the geometry it produces X amount of geometries equal to the X number of attributes.
Thanks!
Nevermind. Found an alternative with Elefront!
Hey Andrew, I have the same question as Ben. Why does it bake as many objects as there was keys/values that were assigned. Can you assign a list of values to a single object?
Thanks!
Ah - I've since fixed this in newer versions of the script.
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