I’ve been trying to read in a .svg i made in Illustrator. It imports/displays properly as a PShape, but I’m hoping to convert the shape into an ArrayList of PVectors so I can manipulate the shape.
Here’s what I’ve done:
• loadShape and store in PShape
• .getFamily() on the shape and got “0” (which means it’s a PShape group?)
Problem:
• When I try to loop through the vertices on this imported shape I get this error message: “getVertexCount() only works with PATH or GEOMETRY shapes”
• When I try .getVertex() on the loaded PShape, I get: “NullPointerException
Could not run the sketch (Target VM failed to initialize).” - assuming this is similar in that the PShape commands don’t work on a group
See code below.
The .svg is just a path in illustrator (see image below) too.
Some ideas?
• I’m wondering if I can either export the .svg in a way that would result in it being a PATH or GEOMETRY shape instead of a GROUP.
• Alternatively, is there something wrong with the .svg I loaded? If so, how should I export it?
• Are there any other ways I can import shapes drawn elsewhere?
Thank you!
PShape wa;
ArrayList<PVector> newshape;
void setup() {
size(600, 600);
wa = loadShape("test.svg");
println(wa.getFamily());
}
void draw() {
background(255);
//go thru the pshape and make it into array list of pvectors
newshape = new ArrayList<PVector>();
for (int i = 0; i<wa.getVertexCount(); i++) {
PVector v = wa.getVertex(i);
newshape.add(v);
}
stroke(180);
noFill();
beginShape();
for (PVector v: newshape) {
vertex(v.x,v.y);
}
endShape(CLOSE);
}