Welcome Dialog

Welcome to the Community!

We have a brand new look! Take a tour with us and explore the latest updates on Adobe Support Community.


InDesign Pathfinder Scripting

Community Beginner ,
Nov 03, 2021 Nov 03, 2021

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!

 

TOPICS
Scripting

Views

68

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Beginner , Nov 04, 2021 Nov 04, 2021
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 testingvar rectHeight1 = 2; var rectWidth1 = 4;var rectHeight2 = 1;var rectWidth2 = 5; //Add rectangle 1var rectangle1 = doc.rectangles.add ({geometricBounds:["0in", "0in", rectHeight1 + "in", rectWidth1 + "in"], contentType:ContentType.GRAPHIC_TYPE}); //Add rectangle 2var rectangle2 = doc.rectangles.add ({geometricBounds:["0in", "0in", rectH...

Likes

Translate

Translate
Advocate ,
Nov 03, 2021 Nov 03, 2021

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

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Nov 04, 2021 Nov 04, 2021

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);

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe Community Professional ,
Nov 04, 2021 Nov 04, 2021

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:

 

RectangleAndOval-Overlapping.PNG

After running the code above:

 

RectangleAndOval-Overlapping-RESULT.PNG

 

Regards,
Uwe Laubender

( ACP )

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Nov 04, 2021 Nov 04, 2021

Copy link to clipboard

Copied

LATEST

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!

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines