ObjectTable.Add Method (GeometryBase geom, ObjectAttributes attr)
http://developer.rhino3d.com/api/RhinoCommon/html/M_Rhino_DocObjects_Tables_ObjectTable_Add_1.htm
for Geometry Type TextEntity the Attr will not be taken care of
ObjectAttributes attr = new ObjectAttributes();
attr.ColorSource = ObjectColorSource.ColorFromObject;
attr.ObjectColor = Color.FromArgb(0, 200, 0); // some green
attr.SetUserString("myKey", "someFancyValue");
Plane pl = Plane.WorldXY;
double txt_height = 20;
TextEntity txt = new TextEntity
{
Plane = pl,
Text = "Hello Attributes",
Justification = TextJustification.MiddleCenter,
FontIndex = doc.Fonts.FindOrCreate("Arial", false, false),
TextHeight = txt_height
};
// Add ---> attr with no effect
if (doc.Objects.Add(txt, attr) == Guid.Empty)
return Result.Failure;
Transform xForm = Transform.Translation(0,txt_height * 1.2,0);
pl.Transform(xForm);
txt.Plane = pl;
// AddText --> attr as expected
if (doc.Objects.AddText(txt,attr) == Guid.Empty)
return Result.Failure;
Adding a TextEntity with Add - Attributes will not be used.
Adding a TextEntity with AddText - Attributes will affect the Object
.
.
.
work arround
protected Guid AddToRhinoDoc(RhinoDoc doc, GeometryBase geo, ObjectAttributes attr)
{
Guid id = Guid.Empty;
TextEntity txt = geo as TextEntity;
if (null != txt)
{
id = doc.Objects.AddText(txt, attr);
}
else
{
id = doc.Objects.Add(geo, attr);
}
}