Copy link to clipboard
Copied
I am writing a script that creates 2 intersecting boxes and then uses shape1.excludeOverlapPath(shape2); to subtract one shape from the other. The code works, but I would like to do more stuff with the resulting shape (change the fill color, add rounded corners, etc.), but I don't know how to select it.
I tried saving the result to override the original variable
shape1 = shape1.excludeOverlapPath(shape2);
I also tried to assign the result to a new variable
var newShape = shape1.excludeOverlapPath(shape2);
Neither of these ideas work; the errors either say the variable was changed or is undefined. Does anyone have any suggestions/advice about how to do this?
Thanks for your help!
I got it to work!! This didn't work for me per se, but I used it as a guide and figured it out. Here is what worked:
//These variables are placeholders for testing
var rectHeight1 = 2;
var rectWidth1 = 4;
var rectHeight2 = 1;
var rectWidth2 = 5;
//Add rectangle 1
var rectangle1 = doc.rectangles.add ({geometricBounds:["0in", "0in", rectHeight1 + "in", rectWidth1 + "in"], contentType:ContentType.GRAPHIC_TYPE});
//Add rectangle 2
var rectangle2 = doc.rectangles.add ({geometricBounds:["0in", "0in", rectHe
...Copy link to clipboard
Copied
Hello @stevem49039051
Can you post the code you're using to subtract one shape from the other for us to test with?
Regards,
Mike
Copy link to clipboard
Copied
//These variables are placeholders for testing
var rectHeight1 = 2;
var rectWidth1 = 4;
var rectHeight2 = 1;
var rectWidth2 = 5;
//Add rectangle 1
var rectangle1 = doc.rectangles.add ({geometricBounds:["0in", "0in", rectHeight1 + "in", rectWidth1 + "in"], contentType:ContentType.GRAPHIC_TYPE});
//Add rectangle 2
var rectangle2 = doc.rectangles.add ({geometricBounds:["0in", "0in", rectHeight2 + "in", rectWidth2 + "in"], contentType:ContentType.GRAPHIC_TYPE});
//Here is where I'm stuck. This code doesn't work.
var newShape = rectangle1.excludeOverlapPath(rectangle2);
Copy link to clipboard
Copied
Hi Steve,
I always provide an array as argument for excludeOverlapPath().
The resulting shape is returned by the method and I see no issue to write it to a variable.
Have two objects on the first spread of a test document.
First draw a rectangle, then an oval overlapping the rectangle.
var doc = app.documents[0];
var oval = doc.spreads[0].ovals[0];
var rect = doc.spreads[0].rectangles[0];
var newShape = rect.excludeOverlapPath([oval]);
// newShape returns [object Oval]
// All is working as expected.
newShape.fillColor = "Yellow";
Note: The method still returns an [object Oval] even if the shape is something else entirely.
Before:
After running the code above:
Regards,
Uwe Laubender
( ACP )
Copy link to clipboard
Copied
I got it to work!! This didn't work for me per se, but I used it as a guide and figured it out. Here is what worked:
//These variables are placeholders for testing
var rectHeight1 = 2;
var rectWidth1 = 4;
var rectHeight2 = 1;
var rectWidth2 = 5;
//Add rectangle 1
var rectangle1 = doc.rectangles.add ({geometricBounds:["0in", "0in", rectHeight1 + "in", rectWidth1 + "in"], contentType:ContentType.GRAPHIC_TYPE});
//Add rectangle 2
var rectangle2 = doc.rectangles.add ({geometricBounds:["0in", "0in", rectHeight2 + "in", rectWidth2 + "in"], contentType:ContentType.GRAPHIC_TYPE});
//Put rectangles in arrays
var r1 = [rectangle1];
var r2 = [rectangle2];
//Store pathfinder result as a new variable
var newShape = r1[0].excludeOverlapPath(rs[0]);
Thanks so much for your help!