jgraph / drawio-desktop

Official electron build of draw.io
https://www.diagrams.net
Apache License 2.0
47.88k stars 4.82k forks source link

Export selected layers from CLI #405

Closed kkredit closed 3 months ago

kkredit commented 3 years ago

One can export a diagram with particular layers active by manually modifying the active layers in the editor and exporting. I'm requesting the ability to specify which layers to export via a command line option. Something like --layers=0,1 or --layers=Background,Foreground.

stale[bot] commented 3 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. See the FAQ for more information.

ebousse commented 2 years ago

Copy of my duplicate issue #737:

Is your feature request related to a problem? Please describe.

When writing a report or when making slides, I often need to include different variants of the same diagram (eg. a "simple" one, then a more "complex" one). To store all variants of a diagram in the same draw.io file, I tend to use the layers feature, where each layer adds new elements to a "base" diagram (eg. enabling a layer can make a "simple" diagram into a "complex" one).

However, when lots of layers are stored in the same draw.io file, it quickly become tedious to manually disable/enable layers and make an export (eg. as PNG or PDF) for each variant. For instance, I have a figure where I have 7 layers, with one new variant per enabled layer, thus 7 variants to export.

Describe the solution you'd like

Adding a simple command line option to select which layers must be enabled for a given export would allow people in my case to write a small script to automatically export all required variants of a given draw.io figure containing layers.

For instance, drawio diagram.drawio --export --format png --layers 1,3,7 --output diagram137.png could create the file diagram137.png which would only contain the content of layers 1,3 and 7 of diagram.drawio.

Describe alternatives you've considered An "advanced" menu in the GUI could maybe give the possibility to select layers to export, but that would still make it tedious to export each required variant one by one.

Additional context Here is an animation showing what I mean by "multiple variants" of a figure, where each enabled layer gives a new and more complex variant:

layers

wzab commented 1 year ago

Is it possible to activate or deactivate a layer from the plugin? May be a plugin could read a list of desired layers from an additional file (or from argument) activate them, and deactivate others before exporting?

At the moment I use a workaround. It is a Python scipt that modifies the XML file with the drawing. It finds the nodes corresponding to the layers like:

        <mxCell id="1" value="Layer_0" parent="0"  />
        <mxCell id="gR8EvOqMRdBkM8fqJK-y-1" value="Layer_1" parent="0"  />
        <mxCell id="gR8EvOqMRdBkM8fqJK-y-2" value="Layer_2" parent="0"  />

and adds them the attribute "visible" set to "0" for an invisible layer or to "1" for a visible layer.

        <mxCell id="1" value="Layer_0" parent="0" visible="1" />
        <mxCell id="gR8EvOqMRdBkM8fqJK-y-1" value="Layer_1" parent="0" visible="1" />
        <mxCell id="gR8EvOqMRdBkM8fqJK-y-2" value="Layer_2" parent="0" visible="0" />

After that, the modified file is exported from CLI as usual. I attach my script: drawio_select_layers.zip.

There is one problem. The bounding box with --crop is set according to the visible layers only. Therefore there should be a background rectangle covering the whole drawing area placed on the lowest layer which should be always visible. The demo of using the script to produce the overlayed images in the beamer presentation is available in my repository.

jikuja commented 3 months ago

I did not test this yet but I think 20.6.0 added requested feature

kkredit commented 3 months ago

I tested it and it works great. Thank you for updating this issue with the resolution, @jikuja!