I think I found a bug in C# for text entities…var dimStyle = te.DimensionStyle;…when I try to get the dimension style for any text entity I always get default -1. I have tried multiple dimension styles and but it doesn’t change and is always default -1. Could you guys take a look, thanks
This works:
#! python 3
import Rhino
def print_dimstyle_name():
rc, objref = Rhino.Input.RhinoGet.GetOneObject(
"Select text", False, Rhino.DocObjects.ObjectType.Annotation)
if rc != Rhino.Commands.Result.Success:
return
text = objref.Geometry()
if not isinstance(text, Rhino.Geometry.TextEntity):
print("Not a text object.")
return
style = text.DimensionStyle
print("Dimension style: {0} (index {1})".format(style.Name, style.Index))
print_dimstyle_name()
– Dale
Thanks for the reply Dale, it does work correctly my problem was caused because I was duplicating the text entity and I’m pretty sure that was making the dimension style default -1.
TextEntity work = te.Duplicate() as TextEntity ?? te;
Yes, that’s it — duplicating is the cause.
AnnotationBase.DimensionStyle can only find the real style by walking up to a parent RhinoObject and looking the style up in that object’s document. Duplicate() intentionally returns parentless geometry, so there is nothing to walk up to, and the property falls back to the system default style — name “Default”, index -1.
The style assignment isn’t actually lost, though: work.DimensionStyleId is still correct after duplication. You just need to re-attach the style yourself:
TextEntity work = te.Duplicate() as TextEntity;
work.ParentDimensionStyle = doc.DimStyles.Find(work.DimensionStyleId, true);
// work.DimensionStyle is now the real style
Or skip the annotation property and look the style up by id directly.
Same thing happens with DuplicateGeometry(), TextEntity.Create(), geometry coming out of Grasshopper, and annotations read from a File3dm — all parentless. This is how it has worked since V6, not something new in 8 or 9.
– Dale