I have several shapes and I would like to assign a color to them, so that I can then print them layer by layer.
So I would like to assign “objects” to a (color) group that I could then split into layers in inkscape.
But when I try to make object groups, I can’t really find what I’ve defined in Inkscape.
How can I handle that?
Here is my code Where I assign one shape per group. A circle for the head and a rectangle for the body :
import processing.svg.*;
void setup() {
size(400, 400);
noLoop();
beginRecord(SVG, "filename.svg");
}
void draw() {
// Make the parent shape
PShape alien = createShape(GROUP);
// Make two shapes
PShape head = createShape(ELLIPSE, 0, 0, 50, 50);
PShape body = createShape(RECT, 0, 50, 50, 100);
alien.addChild(head);
alien.addChild(body);
translate(width/2, height/2);
shape(alien);
endRecord();
}
But when I open the svg with Inkscape, I find a circle (head) into the supposed “body group”
What am I missing, is it even possible? I know I can make a workaround by making one svg by layer but I’m just getting started and it’s going to complicate my code where I’m trying to keep it simple and efficient.
Hi,
a little late to the game but I struggled with the same situation where I want different colors in my sketch to be grouped into inkscape layers so I can draw them one by one on my plotter.
I’ve written a WinForms program that does this form me, using a processing svg as input. The output has a layer for each separate color with all paths in that layer with the same color. I used it so I can accurately draw with my collection of fineliners, for portraits and landscapes.
But it can be used with any color palette, to group shapes into layers based on their color so you don’t have to do this manually in Inkscape.
No idea if this will work for anyone else but me, but if you’re interested I can send you the program?
Or alternatively, if you found a library that we can use in processing to create layers for colors, that would be cool too!
Hi, thanks for your interest!
I haven’t been working on it for a while, when I left the project it wasn’t working perfectly yet. I guess it did group shapes of the same color into layers, mostly, but it also added a black background that I couldn’t get rid off.
It’s not available anywhere but I could put it up somewhere. Except that I’m off vacationing for the next week and a half. When I’m back I’ll see if I can make it available to you!