Allow several -i (--export-id=ID) options

Bug #171476 reported by Guettli-users
52
This bug affects 14 people
Affects Status Importance Assigned to Milestone
Inkscape
Triaged
Wishlist
Unassigned

Bug Description

Dear Inkscape Developer,

it would be nice, if you could give several -i
(--export-id=ID) options:

inkscape -j -i id1 -i id2 ... -export-png test.png \
         test.svg

Up to now (0.43) only the last id gets exported:

===> inkscape -j -i haende -i kreis_gruen -e test.png \
     service-hand.svg
Exporting only object with id="kreis_gruen"; all other
objects hidden
Background RRGGBBAA: ffffff00
Area 232,493:402,349:443,449:613,348 exported to 211 x
211 pixels (90 dpi)
Bitmap saved as: test.png

nightrow (jb-benoit)
Changed in inkscape:
importance: Undecided → Wishlist
Ryan Lerch (ryanlerch)
Changed in inkscape:
status: New → Confirmed
su_v (suv-lp)
tags: added: cli
jazzynico (jazzynico)
Changed in inkscape:
status: Confirmed → Triaged
Revision history for this message
Manuel López-Ibáñez (manuellopezibanez) wrote :

This is the only thing that remains to be able to export layers selectively to make animations for presentations. See bug #170901. However, the man page and --help output could be clearer by mentioning that the ID of layers is "layerN" where N=1,2,... is the layer number.

Revision history for this message
Ketil Malde (ketil-ii) wrote :

Fore presentation, I generally make a layered figure, and generate individual slides by making various layers visible. Last time, I wrote a small script to do this automatically, using xmlstarlet. For instance, this command

    xmlstarlet ed -P -N svg=http://www.w3.org/2000/svg -u '//*/svg:g[@id="layer1"]/@style' -v display:inline figure.svg > slide-1.svg

will generate slide-1.svg from figure.svg by setting layer1 visible. (I generally save from Inkscape with all layers invisible, but you can hide layers similarly, by setting style to display:none. I then generate pdfs with inkscape, e.g.

   inkscape -A slide-1.pdf slide-1.svg

Revision history for this message
Nikhil (answerquest) wrote :

Use case: SVG (or PDF imported to inkscape) has 10 layers/groups one on top of the other. In inkscape GUI, I can turn on the Groups panel, de-select 7 of the groups (I think the PDF import makes it groups and not layers.. anyways it doesn't matter to the CLI) and keep just 3 visible. That's what I want. I export this to PNG/SVG/etc . Now, I have a big bunch of such files coming from the same source, all having same id nomenclatures internally. Here is my command for extracting one id:

inkscape -z -i g2846 -j -D -d 300 test3.pdf -e 3.png

I want three groups/layers combined, in their original order, and all the others hidden, just like I had done in the GUI.

inkscape -z -i g12,g90,g2846 -j -D -d 300 test3.pdf -e 3.png

presently he CLI reads the list as one, searches for it and errors out.

Parsing the string by commas shouldn't be difficult. But I guess the challenge is in laying them on top of each other while preserving their positions, and sending the combined result to output. Right now I have to specify -D, for --export-area-drawing to keep all the extracts in their right positions (anyone wishing to show progressive layering in a presentation or animation will need the same). We could configure it such that -D is assumed if more than one id is given.

Revision history for this message
Nikhil (answerquest) wrote :

Hello again, I was able to create a merged png from the individual layers' png's that I extracted from my PDF, using Imagemagick:
    $ convert -page +0+0 1.png \
    -page +0+0 2.png \
    -page +0+0 3.png \
    -layers merge +repage layers_merge.png

Reference documentation: http://www.imagemagick.org/Usage/layers/#merge
I'm not sure how things would happen with other formats, but with rasters, this seems quite doable.

Revision history for this message
Michele Locati (mlocati) wrote :

I'm using the most recent inkscape version on Windows 64 bit.

Executing `inkscape.com --version` gives me this:
  Inkscape 1.0.2 (e86c870879, 2021-01-15, custom)
      Pango version: 1.48.0

Reading the documentation, it seems that we can export more than one object by separating IDs with semicolons (see https://inkscape.org/doc/inkscape-man.html#i-ID---export-id-OBJECT-ID-OBJECT-ID )

Let's assume we have a file named input.svg with this contents:

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<svg
   xmlns="http://www.w3.org/2000/svg"
   version="1.1"
   viewBox="0 0 100 50"
>
  <g id="rectangle">
    <rect x="0" y="0" width="50" height="50" />
  </g>
  <g id="circle">
    <circle cx="75" cy="25" r="25" />
  </g>
</svg>

The following commands work as expected:

inkscape.com --export-filename=rectangle.svg "--export-id=rectangle" --export-id-only input.svg

inkscape.com --export-filename=circle.svg "--export-id=circle" --export-id-only input.svg

But when I specify more than one ID, inkscape can't find the objects (except the first one):

inkscape.com --export-filename=both.svg "--export-id=circle;rectangle" --export-id-only input.svg
InkFileExportCmd::do_export_svg: Object rectangle not found in document, nothing to export.

inkscape.com --export-filename=both.svg "--export-id=rectangle;circle" --export-id-only input.svg
InkFileExportCmd::do_export_svg: Object circle not found in document, nothing to export.

To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Duplicates of this bug

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.