Inkscape scripting: how to show / hide a layer and export?

I have a cartoon with multiple layers; among those layers I have a German and an English layer. They have the text in their respective languages. The idea is to hide the German layer and show the English layer and export as an English cartoon or to hide the English layer and show the German layer for a German version of the cartoon. I’d like to script that export.

Here is a part of my SVG file:

         <!-- .... --> 
         <tspan id="tspan3257">I don't think</tspan>
         <!-- ... -->


           <!-- ... -->
           <tspan id="tspan3286">Ich glaube nicht,</tspan> 
           <!-- ... -->

I’ve seen and tried this command (and plenty of variations to it):

inkscape -z --file=cartoon.svg --select=English --verb=LayerHideAll --select=German --verb=LayerShowAll --export-png=cartoon-de.png --export-area-drawing

But I keep getting the English text, probably because when I saved the file, the English layer was visible and the German layer wasn’t.

I’ve also tried selecting the layers by their IDs (in the code above layer3 and layer4, respectively), and selecting the actual <text> elements; I’ve tried various combinations of Inkscape verbs. But no luck either.

How can I script this export, hiding or showing the language layer as needed?
Can I do this with Inkscape verbs or should I work with the XML and try setting the style attribute to display:inline or display:none?


As to why the command-line testing wasn’t working, I believe the answer is that you first need to select an item in the layer (and not the layer itself) to be “in” the layer. After that, the correct verb would be LayerToggleHide. (Not sure if this verb was available when this question was asked.) And, yes, objects can only be selected by ID, and not name.

Furthermore, because there are no LayerHide and LayerShow verbs (why?), to reliably script this you would first need to use LayerHideAll or LayerShowAll to set all layers one way or the other before then using LayerToggleHide to achieve the final result.

I haven’t tested this command-line route so I can’t show a definitive working solution. Instead, after thinking through the command-line route a great deal and realizing how much scripting it would take to make it work for my needs, I decided to just go all-in and write an Inskape extension that handles needs like this. I call it the SLiCk Layer Combinator and it can be found here:

Source : Link , Question Author : Robert , Answer Author : juanitogan

Leave a Comment