Mobile app version of vmapp.org
Login or Join
Rambettina927

: Subtract paths, automated (using a script) I have 100+ SVG files, each containing a few closed paths (with Bezier curves), like this: I'd like to do the following: select the first (bottom)

@Rambettina927

Posted in: #IllustratorScripting #Path #Scribus #Script #Svg

I have 100+ SVG files, each containing a few closed paths (with Bezier curves), like this:



I'd like to do the following:


select the first (bottom) path
duplicate it
move the duplicate by an (x, y) amount





subtract the duplicate from the original path.




And save the SVG.

Is there any way I can do this automatically?

Technologies I looked at:


Inkscape - as far as I can see, you can only write scripts in Python that manipulate the SVG node hierarchy directly, can't call the built-in path subtract function.
Illustrator - I tried to record the steps in an Action, but can't seem to be able to select the bottom path automatically, you can only select objects in an Action by name.
Affinity Designer - not scriptable.
CorelDRAW - messed up the width / height of the SVG straight away, didn't look further.
Scribus - superb scriptability with Python, but can't seem to find the Python function for the subtract path operation (all the other steps work).
Clipper library (C++, C# and Delphi) - doesn't support curves, only straight lines + you would need to write the SVG parsing yourself.


I'm looking for a solution using any scriptable vector editing tool, plugin, or programming language + library combo.

10.03% popularity Vote Up Vote Down


Login to follow query

More posts by @Rambettina927

3 Comments

Sorted by latest first Latest Oldest Best

 

@Rambettina927

Maybe whit this solve the problem: two.js.org/

10% popularity Vote Up Vote Down


 

@Hamaas979

In Inkscape, you can also call verbs from commandline.

The only problem is that they don't take parameters (yet) so you can do for instance stuff like

inkscape --select=rect3680 --verb=EditDuplicate --verb=SelectionInset --select=rect3680 --verb=SelectionDiff --verb FileSave --verb FileQuit drawing-2.svg


but the "3. move the duplicate by an (x, y) amount" is actually the hardest part

10% popularity Vote Up Vote Down


 

@Ogunnowo857

You should be able to do this using the Illustrator actions with an odd trick.

This would work assuming the shapes in your files are of a different color as shown in your provided image.


Start recording your action.
Add a rectangle and give it a stroke (You will delete this later)
With your new rectangle still selected click Select -> Next Object Below
Click Select -> Next Object Below several more times
Click Object -> Transform -> Move and set your desired offset
Click the copy button in the move dialog
Click Select -> Same -> Fill & Stroke
Click Subtract in the Pathfinder toolbox
Click Select -> Next Object Above several times
Hit your delete key
Save the document
Stop recording the action


You can then use the batch scripting to run it on all of your files.

10% popularity Vote Up Vote Down


Back to top | Use Dark Theme