Moving an object by center point to an object.bounds.center
-
Hi
I'm wondering if it's possible to move a "entity.add_text" object that I have added to the scene, to the center of a group in the scene, so that the center of the add_text object is in the center of the group ?
Any hints are welcome. I can add the text object to the center of the group, but it is aligned to the top-left corner of the text object, not the center
Thanks
Jorgensen -
The groupg's bounding box (bounds) has max and min XYZs. Find those and use something to find the mid-way between them (= the center)...
Assuming that your group is named 'group'...
...
max=group.bounds.max; min=group.bounds.min
mid_point=Geom::Point3d.linear_combination(0.5,max,0.5,min)
...
Unfortunately plain text is left justified. However you could place some 3D-text centred - see my TextTag stuff for clues -
I guess the whole point is to understand whether there is a way to know 'in advance' the size of a text (based on string and font) so that it can be positioned accurately in the model at creation.
On my side I did not find a way to do that.
-
Hi TIG and Fredo
Thanks for your input.
I'm thinking about to try and use 3dtext instead. But until further I'll have a workaround where I modify the position by x,y, z axis. This is not perfect, because the texts don't have the same width.
Thanks
Jorgensen
Advertisement