1 year ago

#89384

test-img

Pervez

How to convert units for all tags in a SVG using Inkscape Command Line or Python 3?

I use mm as my unit while creating SVG drawings in INKSCAPE and for a program I'm working on, I need units of all the shapes to be converted to pts

Is there any way to convert the units of every xml tag in the SVG from mm to pt most preferably using Python3 else Inkscape Command Line

(i.e.) Convert the below SVG

<svg
   width="108mm"
   height="108mm"
   viewBox="0 0 108 108"
   version="1.1"
   id="svg5"
   inkscape:version="1.1.1 (3bf5ae0d25, 2021-09-20)"
    @@ -38,46 +38,46 @@
     inkscape:label="Layer 1"
     inkscape:groupmode="layer"
     id="layer1"
     transform="translate(-52.715782,-77.867737)">
    <g
       id="g738">
      <circle
         style="fill:#000000;stroke-width:0"
         id="path53"
         cx="106.71578"
         cy="131.86774"
         r="54" />
      <circle
         style="fill:#ffffff;stroke-width:0"
         id="path179"
         cx="106.71578"
         cy="131.86774"
         r="17.5" />
      <circle
         style="fill:#ffffff;stroke-width:0"
         id="circle261"
         cx="106.71578"
         cy="92.367737"
         r="8" />
      <circle
         style="fill:#ffffff;stroke-width:0"
         id="circle263"
         cx="106.71578"
         cy="171.36774"
         r="8" />
      <circle
         style="fill:#ffffff;stroke-width:0"
         id="circle722"
         cx="131.86774"
         cy="-146.21579"
         r="8"
         transform="rotate(90)" />
      <circle
         style="fill:#ffffff;stroke-width:0"
         id="circle724"
         cx="131.86774"
         cy="-67.215782"
         r="8"
         transform="rotate(90)" />
    </g>
  </g>

to

<svg
   width="306.1422pt"
   height="306.1422pt"
   viewBox="0 0 306.1422 306.1422"
   version="1.1"
   id="svg5"
   inkscape:version="1.1.1 (3bf5ae0d25, 2021-09-20)"
    @@ -38,46 +38,46 @@
     inkscape:label="Layer 1"
     inkscape:groupmode="layer"
     id="layer1"
     transform="translate(-149.4307914463,-220.72778068705)">
    <g
       id="g738">
      <circle
         style="fill:#000000;stroke-width:0"
         id="path53"
         cx="302.501885777"
         cy="373.798889191"
         r="153.0711" />
      <circle
         style="fill:#ffffff;stroke-width:0"
         id="path179"
         cx="302.501885777"
         cy="373.798889191"
         r="49.606375" />
      <circle
         style="fill:#ffffff;stroke-width:0"
         id="circle261"
         cx="302.501885777"
         cy="261.83020568705"
         r="22.6772" />
      <circle
         style="fill:#ffffff;stroke-width:0"
         id="circle263"
         cx="302.501885777"
         cy="485.76756419099996"
         r="22.6772" />
      <circle
         style="fill:#ffffff;stroke-width:0"
         id="circle722"
         cx="373.798889191"
         cy="-414.47058912349996"
         r="22.6772"
         transform="rotate(90)" />
      <circle
         style="fill:#ffffff;stroke-width:0"
         id="circle724"
         cx="373.798889191"
         cy="-190.5332164463"
         r="22.6772"
         transform="rotate(90)" />
    </g>
  </g>

Note that in the given example (Consisting only of circles) the conversion took place at the following attributes

width, height, viewBox, transform(), r, cx and cy

A general solution that works on all shapes and path xml tags is required

Edit : Note that no scaling is done here. (i.e.) 108mm = 306.1422pt and so on.

Thanks in Advance

python-3.x

svg

command-line

inkscape

unit-conversion

0 Answers

Your Answer

Accepted video resources