what I want to do
I’d like to get the xyz position of the (anchor point of) the text objects on a layer.
what I’ve explored
As shown in this notebook :
- I used
rhino3dm.File3dm.Objectsto get theObjectTableof the.3dmfile - iterate the
object table, and check if an object is on the layer storing the text by examining itsFile3dmObject.Attributes.LayerIndex
the obstacle
I couldn’t find a way to get the xyz coordinates of a text object.
For text object, File3dmObject.Geometry returns an AnnotationBase object, which only contains the content of the text, via File3dmObject.Geometry.PlainText attribute, or AnnotationBase.PlainText.
my question
Which type of objects/attributes should I access to get the xyz coordinates of text object on a given layer?
Thanks.
code snippet
layer_idx_of_num = 3
cnt_text = 0
max_num_obj = 3
total_num_text = 0
for idx, obj in enumerate(iter(object_table)):
if (obj.Attributes.LayerIndex == layer_idx_of_num) and (cnt_text < max_num_obj):
print('object ', idx, ' Object : ', obj)
print(' ', idx, ' Geometry : ', obj.Geometry)
print(' ', idx, ' Attributes : ', obj.Attributes)
print(' ', idx, ' Attributes.Id : ', obj.Attributes.Id)
print(' ', idx, ' Attributes.Name : ', obj.Attributes.Name)
print(' ', idx, ' Attributes.LayerIndex : ', obj.Attributes.LayerIndex)
print(' ', idx, ' Attributes.ObjectColor : ', obj.Attributes.ObjectColor)
print(' ', idx, ' Attributes.Visible : ', obj.Attributes.Visible)
print()
# if geom is AnnotationBase, print its PlainText
if isinstance(obj.Geometry, rhino3dm.AnnotationBase):
print(' Geometry.PlainText : ', obj.Geometry.PlainText)
print()
cnt_text += 1
for idx, obj in enumerate(iter(object_table)):
if (obj.Attributes.LayerIndex == layer_idx_of_num):
total_num_text += 1
print('total num of text: ', total_num_text)
output
object 2472 Object : <rhino3dm._rhino3dm.File3dmObject object at 0x000001792661F6F0>
2472 Geometry : <rhino3dm._rhino3dm.AnnotationBase object at 0x000001791FAD9370>
2472 Attributes : <rhino3dm._rhino3dm.ObjectAttributes object at 0x000001791FAD9370>
2472 Attributes.Id : 331127a8-6c28-4a2e-b56b-6d8c0879f793
2472 Attributes.Name :
2472 Attributes.LayerIndex : 3
2472 Attributes.ObjectColor : (0, 0, 0, 255)
2472 Attributes.Visible : True
Geometry.PlainText : 5-5-9
object 2473 Object : <rhino3dm._rhino3dm.File3dmObject object at 0x000001792661C2B0>
2473 Geometry : <rhino3dm._rhino3dm.AnnotationBase object at 0x000001791FAD9370>
2473 Attributes : <rhino3dm._rhino3dm.ObjectAttributes object at 0x000001791FAD9370>
2473 Attributes.Id : 889cae8f-6c0e-4199-b2e2-1852feccefb4
2473 Attributes.Name :
2473 Attributes.LayerIndex : 3
2473 Attributes.ObjectColor : (0, 0, 0, 255)
2473 Attributes.Visible : True
Geometry.PlainText : 2-2-5
object 2474 Object : <rhino3dm._rhino3dm.File3dmObject object at 0x0000017975CA6DF0>
2474 Geometry : <rhino3dm._rhino3dm.AnnotationBase object at 0x000001792661C2B0>
2474 Attributes : <rhino3dm._rhino3dm.ObjectAttributes object at 0x000001792661C2B0>
2474 Attributes.Id : 937bb06e-49ff-4687-8b42-97ea498f93a0
2474 Attributes.Name :
2474 Attributes.LayerIndex : 3
2474 Attributes.ObjectColor : (0, 0, 0, 255)
2474 Attributes.Visible : True
Geometry.PlainText : 8-8-6
total num of text: 72



