I have trouble adding user text consistently to File3dmbObject and write them to a file. For example, the code below tries to add “k” as key and “v” as value to curves and write them to a file. However, some objects in the resulting 3dm file contains user text and some objects do not. I wonder if I missed anything using the File3dm.Write method.
List<LineCurve> lines = new List<LineCurve>();
for(int i = 0;i < 100;i++)
lines.Add(new LineCurve(new Point3d(i, 0, 0), new Point3d(i, 1, 0)));
string filepath = "C:\\temp\\test-bake-file.3dm";
Rhino.FileIO.File3dm f = new Rhino.FileIO.File3dm();
foreach(Curve l in lines)
{
ObjectAttributes att = new ObjectAttributes();
att.SetUserString("k", "v");
f.Objects.AddCurve(l, att);
}
f.Polish();
f.Write(filepath, 5);
Your code appears to work in the current Rhino WIP. I’d report this as a bug, but there isn’t going to be another Rhino 5 service release. So for Rhino 5, I suggest attaching your user text to the geometry.
I’m guessing my issue is similar for Rhino 5 and won’t be addressed, but I’d like to confirm. I am also finding that certain attributes don’t get written to the File3dm, specifically ObjectColor and ColorSource. For example:
Rhino.FileIO.File3dm newFile = new Rhino.FileIO.File3dm();
var att = new ObjectAttributes();
att.Name = "Test";
att.ObjectColor = Color.Red;
att.ColorSource = ObjectColorSource.ColorFromObject;
newFile.Objects.AddCircle(new Circle(5), att);
When I Polish and Write my File3dm, it saves it fine with my object. The object Name attribute is applied, but ObjectColor and ColorSource are not. Adding the same object to the ActiveDoc of the file from which I authoring the new File3dm results in the correct application of object attributes.
Am I missing something, or is this known and being addressed in V6?