Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SVG Union of Shapes using javascript or d3 or inkscape script like Inkscape GUI does

I am doing a simple website where I put some graphics. Now I do each diagram using Inkscape. I use Inkscape to make UNION operations between the shapes. Then I save the new diagram, do another union, save, and so on. I need repeat this about 150 times :(

I would like to know if I could do it using javascript or D3 library. Or at least a way that makes Inkscape do it automatically.

In the perfect case, there would be a function:

union(shapeA,shapeB): replace ShapeA and ShapeB by ShapeAunionB

Could you give me any tips about this problem? Any help?

like image 504
Henry Avatar asked Nov 06 '12 13:11

Henry


2 Answers

There is an opensource library: Javascript Clipper

The Javascript Clipper library performs clipping and offsetting for both lines and polygons. All four boolean clipping operations are supported - intersection, union, difference and exclusive-or. Polygons can be of any shape including self-intersecting polygons.

features demo: http://jsclipper.sourceforge.net/5.0.2.2/main_demo.html

enter image description here

like image 157
cuixiping Avatar answered Sep 26 '22 06:09

cuixiping


I have done a script in Python and it calls Inkscape command line, like suggested website by Erik Dahlström explains.

command = "inkscape -f file.svg --verb=EditDeselect --select=shapeA --select=shapeB --verb=SelectionUnion --verb=FileSave --verb=FileClose" os.system(command)
like image 39
Henry Avatar answered Sep 23 '22 06:09

Henry