It's not possible to get the bounding box of a text object, or convert a text object to path using just the script.
bounding_box() or shape_box() will only return the top left coordinates for text.
It does require a command call.
You do not need to convert the text to path to get the text bounding box from the command call.
A temp file can be used ( although it is not strictly needed for the --query-all option )
The most efficient way is to limit the the number of command calls.
It's quicker for most files to do a single --query-all ( which gets the bbox for all objects ) and put all the results into a dictionary, than it is to make multiple command calls.
Remember that cli bounding boxes are visual ( they include the stroke width, although text generally does not have stroke ) and inkex bounding boxes are geometric ( just the bare path bounding box )
In my extension 'simple registration' there is
def query_all_bbox(self): which puts all cli bounding boxes into a dictionary.
One thing to be aware of, the way Inkscape aligns text is slightly different that pure svg.
If you align a long column of text using the bounding box, you will find that the edge is not perfectly aligned. You can change the baseline setting in the text to correct for this.
I'm looking to get the bounding box of text objects.
.bounding_box() returns none.
Trying to find a way to run 'object to path' but it looks like it's not possible within a script.
Do I need to generate a temp file, fill it with text, run CLI verbs for object_to_path so I can measure it?
Am I missing a simpler approach?
It's not possible to get the bounding box of a text object, or convert a text object to path using just the script.
bounding_box() or shape_box() will only return the top left coordinates for text.
It does require a command call.
You do not need to convert the text to path to get the text bounding box from the command call.
A temp file can be used ( although it is not strictly needed for the --query-all option )
The most efficient way is to limit the the number of command calls.
It's quicker for most files to do a single --query-all ( which gets the bbox for all objects ) and put all the results into a dictionary, than it is to make multiple command calls.
Remember that cli bounding boxes are visual ( they include the stroke width, although text generally does not have stroke ) and inkex bounding boxes are geometric ( just the bare path bounding box )
In my extension 'simple registration' there is
One thing to be aware of, the way Inkscape aligns text is slightly different that pure svg.
If you align a long column of text using the bounding box, you will find that the edge is not perfectly aligned. You can change the baseline setting in the text to correct for this.
The most efficient way
Worked like a charm!