Inkscape.org
Beyond the Basics Applying the measurings to a file using scripting
  1. #1
    amir amir @amir

    Is it possible to apply measurements (as I do manually by using the Measurement Tool) to a .svg file in an automated way (e.g. by using a script). What I would like to have to then apply that script to the file, so that when I open it with Inkspace I see already the measurements too (so that I don't have to do it by hand). Is this possible, and when yes how could I do it?

    Many thanks in advance for your time!

  2. #2
    inklinea inklinea @inklinea⛰️

    I am not sure if you can access the built measuring tool via command scripting.

    It is possible to access the 'visualise path' extension.

    inkscape --batch-process --actions="select-by-id:path1004;org.inkscape.visualise.measure_length.noprefs;export-filename:measured.svg;export-do;" drawing.svg

    So for a path id of 'path1004' it will add the path length to the shape.

    Dimensioning also works, but does not add numbers. They can be added by processing the new dimension paths through the script again.

    If you are using linux, its fairly easy to loop through all objects in the document.

    Maybe someone here knows better.

  3. #3
    inklinea inklinea @inklinea⛰️

    This script will add path lengths to all paths present. 

    ******** IT OPERATES ON THE ORIGINAL FILE SO PLEASE USE A COPY ***************

     

    readarray array <<< cut -d ' '  -f 3 <<< $(inkscape --batch-process --actions="select-by-id:$2;select-invert;select-list" $1)
    #echo $(cut -d ' ' -f 1 <<< ${array[1]})

    for i in "${array[@]}"
    do
      echo $(cut -d ' ' -f 1 <<< $i)
      object=$(cut -d ' ' -f 1 <<< $i)
      $(inkscape --batch-process --actions="select-by-id:$object;org.inkscape.visualise.measure_length.noprefs;export-filename:$1;export-do" $1)
    done


     

    Drawingorig
    Drawing
  4. #4
    inklinea inklinea @inklinea⛰️

    It's all very inefficient though. 

    Would be a lot better if done internally using Python.

    To just add measurements to dimensions, would need to use a bash array difference to make a new array after dimensioning, then run the above loop on that array instead.

Inkscape Inkscape.org Inkscape Forum Beyond the Basics Applying the measurings to a file using scripting