How can I set Block Attribute Text via C# / Rhinocommon?
I have multiple layouts with the same Block that represents the layout sheet/label and some text in the label should change according to the layout. I use DocumentUserText and Text Fields for data that is document related, but couldn’t figure out how to make it work for the individual layout data.
I currently get the Block Instance Definition by its name to insert it:
var block = doc.InstanceDefinitions.Find("Block Name");
doc.Objects.AddInstanceObject(block.Index, xform);
It’s pretty straightforward to set the Attribute text of any RhinoObject, including the InstanceObject. Below is my test using a Grasshopper C# component in Rhino 8. Although this should work for Rhino 7 also.
var doc = RhinoDoc.ActiveDoc;
var selected = doc.Objects.GetSelectedObjects(false, false).FirstOrDefault();
selected.Attributes.SetUserString("Key", "Value");