If I return the x position of an object with the query-x action, then use the returned $value in a new command with the action object-set-attribute:x,$value, the object moves!
Is there any way to make sure these commands use the same units regardless of the document properties?
Dividing the queried x by the document unit and feeding the result to set-attribute works, although if there is a page offset (since multipage svgs were introduced), it has to be added to the result in svg unit (i.e. no unit).
I also found out that the transform-translate action uses the same unit as query, which is great because I actually want to perform translations.
I spoke too fast. Turns out I can't use the query function because it's not just a unit problem. For example, the position of a text object's bounding box will differ depending on the text content, so in my case I need the svg value for x.
ChatGPT showed me this command which seems to work fine, where text453 is my object's id:
xmlstarlet sel -t -v "//*[@id='text453']/@x" drawing.svg
If I return the x position of an object with the
query-x
action, then use the returned$value
in a new command with the actionobject-set-attribute:x,$value
, the object moves!Is there any way to make sure these commands use the same units regardless of the document properties?
The query series - from the command line return the visual bounding box in pixel.
From an extension you would use:
and then
conversion_factor = conversions[self.svg.unit]
from the command line you would probably be better using
inkex
with python ( it does not require inkscape )or you could parse the document with some other xml aware program - you would still use the conversion table
Thanks for your answer.
Do you know which unit is each action using between
query-x
andset-attribute
?I'm not writing a python extension but a bash script and would like to keep it in one file.
set-attribute
writes directly to the attributeso If you just set 20 for example that has no units.
However I would try to parse the file in that case to find the units.
this was the best I was able to do - to return units from an Inkscape .svg file.
xmlstarlet sel -t -v "//*['sodipodi:namedview']/@inkscape:document-units" drawing.svg
Thank you!
Dividing the queried x by the document unit and feeding the result to
set-attribute
works, although if there is a page offset (since multipage svgs were introduced), it has to be added to the result in svg unit (i.e. no unit).I also found out that the
transform-translate
action uses the same unit asquery
, which is great because I actually want to perform translations.Problem double-solved for me.
I spoke too fast. Turns out I can't use the
query
function because it's not just a unit problem. For example, the position of a text object's bounding box will differ depending on the text content, so in my case I need the svg value for x.ChatGPT showed me this command which seems to work fine, where
text453
is my object's id:I've never used chatgpt - what did you use as a question ?
Here's the prompt I used in chatGPT:
Using xmlstarlet on an svg file, how can I query the x position of an object of which I know only the id?