I have a script that adds text on top of objects in layouts. It can put a text with object name, material name, material notes or any user text. Text placement is based on the center of the object, translated to layout space.
Only problem is that each text will overwrite existing text. For example, if I already have a text with the object name and then want to add the material, it goes directly on top of the name text.
I could write some complicated script to get the bounding boxes of existing text and shift a new text if it will overlap, but was wondering if there is a more elegant way to do this.
Hi @GaryC,
one way would be to add information to each text object which connects it with the object it was derived from. Assigning Attribute UserText seems perfect for this.
Below is a simplified example script and document which contains 3 named curves. Run the script, select all curves and press Enter. It will add text objects containing only the curve object’s names.
The script then asks for a selection again, select all curves and it will detect if a text object exist, it deletes the text object and adds a new one containing object name and layer name.
Gary_OverwriteText.3dm (43.7 KB)
Gary_OverwriteText.py (2.7 KB)
does that help ?
_
c.
Thanks @clement
Well that’s one option. And I like the use of user text to identify existing items. But I was hoping to leave the existing text in place. Basically another tag with different info for the same object, offset slightly below the tag already in place.
For example, one tag might be the name of the object and the other might be the render material.
As I said, I can probably figure out code to check the location of existing tags and make sure I don’t place another tag on top, but was wondering if there was some smarter way to do this.
Hi @GaryC,
it could be done as in my example without deleting existing text objects, eg. add the UserText to all your text (tag) objects containing the object’s id. Then use FindByUserString
to find all text objects for the object you’re adding another text tag to. Get all their insertion points (or the bbox center) and append another tag below the lowest one. If an object has no text tag, use the bbox center.
Downside of this is, you’ll might run into trouble if the amount of text tags gets longer and you’ll want to prevent duplicated tags. If you have one text per object, you can add new lines to it and control that the info inside the text has no duplicated entries.
_
c.