abey79 / vpype

The Swiss-Army-knife command-line tool for plotter vector graphics.
https://vpype.readthedocs.io/
MIT License
687 stars 61 forks source link

Preserve layer names #28

Closed ithinkido closed 4 years ago

ithinkido commented 4 years ago

At the moment vpype preserves the layer structure which is a great feature. I use Inkscape plotter extension for sending plots to an HP plotter. I really appreciate the ability to send multi-pen plots with this extension. To use this feature it is necessary to define the layers with names like pen1, pen2.....etc. This is a super useful feature for me that means I can set up multi-colour plots, hit send and I do not have to worry about changing pens mid plot. I am very grateful for the line sort and line merge feature in vpype for optimising paths. The difference is huge on many plots. My issue is that when I import a svg into vpype that I have set up in the correct pen layers for optimising then the layer structure is preserved , but the layers are renamed as 1, 2 , 3,...… etc instead of remaining as pen1, pen2, pen3.....etc

image

abey79 commented 4 years ago

The reason why layer naming is based on numbers is that Axidraw's official tools require layer names to begin with number to handle multi-colour plots. Besides, I would like to stay away from maintaining layer naming throughout vpype's pipeline because there are many ways for layer the be created, modified, merged, etc. and, from the CLI UX perspective, maintaining layer labels would be the worst headache for, I believe, little benefit.

My suggestion would be to add a --layer-label PATTERN option to the write command. By default, PATTERN would be %d, but you could set it to Pen\ %d instead to have layer names Pen 1, Pen 2,... (I've escaped the space with \ because you would have to do that in a terminal). Would that be ok for you?

Note that the numbering would be based on whatever currently is in vpype's pipeline, which again can be affected by many commands beside read (which, by the way, is often left entirely unused). Since read tries to honour the numbering of the input layer labels, it should work as expected in your case though.

ithinkido commented 4 years ago

I see what you mean if you are merging layers etc, then the naming gets tricky. Using a pattern layer name would not be a good solution for me as I might need to import only a 4-5 layers from a total of 8. In such a case the result would not necessarily be covered depending on the layer structure. I would find a preserve layer name option ( not default) more useful. This would allow the axi plotters and layer generators to work as usual with the current code setup and anyone else with specific needs to maintain the setup work already done.

abey79 commented 4 years ago

I might need to import only a 4-5 layers from a total of 8

I'm not sure I understand. Your input SVG only has some layer named Pen 1, etc. but not all of them? Wouldn't it make sense to get rid of those layers upfront or, alternatively, within vpype with the ldelete command?

ithinkido commented 4 years ago

The layers are named pen1 through to pen8 . If I only import layer pen1, pen6, and pen7 from my design to optimize the paths, rotate, center or perform another operation then I would not be able to use a pattern layer naming system to give the layers new names once done, it would be back to manually renaming them each time so that they remain in the layer format ( pen....) and order as originally setup.

abey79 commented 4 years ago

Oh, you have one file per layer? Is there a reason for that? I'd say workflow with a single, multi-layer file works better with vpype.

ithinkido commented 4 years ago

No, I am using a single multi layer file. The layers and named pen1, pen2....etc and i would like to find a way to preserve that

abey79 commented 4 years ago

I'm confused now. Do you mean that your multi-layer file could contain non-consecutive layer names only, e.g. a 3-layer file with Pen 2, Pen 3, Pen 7? Is that right?

As it stands, the read command honour the numbering. I've made a 3-layer test file test_2_3_7.svg.zip with the following layer names:

image

Then vpype read test_2_3_7.svg show yields the following:

image

Notice that vpype's layer numbers match the input file's numbering. With my proposed changed, the following command would achieve what you are requesting:

vpype read test_2_3_7.svg [optimisation commands...] write --layer-label Pen\ %d output.svg

Specifically, the output file would have 3 layers, named Pen 2, Pen 3, Pen 7, corresponding exactly to those of the input file.

ithinkido commented 4 years ago

Ok I had not quite understood that part. I thought that using Pen\ %d would generate a consecutive seriers of pen layers, ie 2, 3 ,4.....etc. If it retains the original numbering and adds the "pen" back then that will work for Inksape to plot with. Thanks for showing me this.

abey79 commented 4 years ago

Let's keep it open until it's done :)

abey79 commented 4 years ago

Closed with 07819e71348004ef5130d5f93b7a6c527aa9d666