Dynamically Associated Text
-
I am trying to figure out the link between a text object and the group, line or face it was associated to when first created. When you add a text object to a group it picks up the group's name as the text field. I found that the text continues to be associated to the object even though the text field is not dynamically associated. When the object moves the text moves with it. I am trying to find a way to have the text dynamically update based on changes to the object, such as group name change or some other attribute.
Any thoughts?
Thanks in advance.
-
I notice using txt.parent returns the Model object rather than the Group object. (I would consider this an API bug.)
I also checked the Group's entities... and it does not consider the Text object to be part of the group.
-
Further checking:
The Text object has no instance variables on the Ruby side.
The Text object has no attribute dictionaries.
It appears that all it's functionality is on the C++ side of the code. It is done by the internal Sketchup Text tool. (Once again a gaping hole in the API.)
You'd have to write your own tool to draw the Text object, make an attribute dictionary for the parent object and add a 'textobject' attribute who's value points at the Text object (a String representation of it's object_id.)
Then you'd have to attach a custom "TextUpdater" Observer (fired by onChangeEntity,) to the parent object (while working around the Entity.parent bug.) The observer would then update the text in the Text object.What a pain in the <bleep>!
-
Thanks Dan. That was my Plan B. Thank you for confirming the pain I am about to go through.
Thanks again for checking.
-
i would like to add to this that the object_id of a Sketchup entity (wether a group, component instance, ...) is not consistent throughout different sketchup sessions.
So you will have to add your own generated id -
Search out my Height above Datum Text Tag code... http://forums.sketchucation.com/viewtopic.php?p=193238#p193238
This tool adds a piece of text at the picked point and later if that text is moved its observer reads its Z value and updates itself automatically. In your case instead of it checking its location have it check the area of a given face [don't use ids as these change session to session instead stamp each bit of text AND it associated face with a guid - perhaps based on the time * rand] and have the face update the text. I already have an 'AreaTag' tool on my 'to-do list' [but currently it's a far off number 9]
Advertisement