Script to convert shape rounded rectangle to rectangle

Explorer ,
Feb 09, 2021 Feb 09, 2021

Copy link to clipboard

Copied

I have an inDesign file with thousands of pages.  On each page is a background object which by default has rounded corners (a rounded rectangle).  I would like to create a script which would go through all of the pages and change this object to full corners (a rectangle).  Obviously, I can do this one by one by selecting the object and then clicking on Convert Shape Rectangle within the properties tab, but I haven't been able to find the correct object/method within scripting to make this happen.

 

Please note for argument sake, assume that I cannot use a single master page, change that, and have it apply to all pages.

 

Could someone provide a small sample script that could provide this ability?  Thank you in advance for any assitance provided ! 

TOPICS
How to, Scripting

Views

116

Likes

translate

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

Adobe Community Professional , Feb 09, 2021 Feb 09, 2021
Try this script.  //all page items on the bottom layer var pi = app.documents[0].layers[-1].allPageItems for (var i = 0; i < pi.length; i++){ try { if (pi[i].bottomRightCornerOption != CornerOptions.NONE || pi[i].bottomLeftCornerOption != CornerOptions.NONE ||pi[i].topCornerOption != CornerOptions.NONE || pi[i].topLeftCornerOption != CornerOptions.NONE) { pi[i].properties = {bottomRightCornerOption: CornerOptions.NONE, bottomLeftCornerOption: C...

Likes

translate

Translate

Translate
Adobe Community Professional ,
Feb 09, 2021 Feb 09, 2021

Copy link to clipboard

Copied

Hi any2cards,

is this rounded rectangle on every page of your document?
Are any other rounded rectangles on the pages that should be not converted to rectangles?

Does the rounded rectangle contain anything? An image? A Pasted Inside group of objects?

Are there any text frames with rounded corners?

How are the rounded corners be done? By using InDesign's feature only?
Or are there cases where the rounded corners were done with the Pathfinder Tools by substracting etc.pp.?

 

All questions that should be answered before writing a script.

Or at least "cases" a script should be able to react to in one or the other way.

 

Alternative solution without a script:

 

Use Find/Change Object.

Find an object with rounded corners.

Change to no rounded corners.

 

If there are more features in Find Object you can use to discern your background rectangles from other rectangles with rounded corners, the better for you. Like fill color, stroke width or stroke color perhaps.

 

Regards,
Uwe Laubender

( ACP )

 

Likes

translate

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
Explorer ,
Feb 09, 2021 Feb 09, 2021

Copy link to clipboard

Copied

There is a single rectangle frame which contains an image.  This image (within the frame) is what I want to convert from Rounded corners to full corners.  As I said, I can manually go through each and every page within the Properties tab and click on Convert Shape - Rounded or Convert Shape - Rectangle and get the desired results.  I am trying to achieve the same thing via a script.  I can write the entire script, but I just don't know what property name I am trying to reference when trying to do a "convert shape - rounded" or "convert shape - rectangle".

 

By the way, if I attempt the find/change, I can set it up properly, but I can't seem to find the proper mm size of the rounding to allow the search to find a matching object.  When you just use Convert Shape - Rounded, how many mm are used?

 

Thanks.

Likes

translate

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
Explorer ,
Feb 09, 2021 Feb 09, 2021

Copy link to clipboard

Copied

I have actually stepped from 1 mm to 15 mm for all corners within Find / Change, and it does not find any matching objects.  For example:

 

Find Object Format:

  Top Left Corner Effect: Rounded

  Top Left Corner Radius: (I have put 0 - 15 mm)

  Top Right Corner Effect: Rounded

  Top Right Corner Radius: (I have put 0 - 15 mm)

  Bottom Left Corner Effect: Rounded

  Bottom Left Corner Radius: (I have put 0 - 15 mm)

  Bottom Right Corner Effect: Rounded

  Bottom Right Corner Radius: (I have put 0 - 15 mm)

 

Change Object Format:

  Top Left Corner Effect: None

  Top Right Corner Effect: None

  Bottom Left Corner Effect: None

  Bottom Right Corner Effect: None

 

Search: All Documents

Type: All Frames

 

Likes

translate

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
Explorer ,
Feb 09, 2021 Feb 09, 2021

Copy link to clipboard

Copied

After playing around with manually changing the corner sizes, it looks like the sized used by Convert Shape - Rounded is 4.233 mm.  Even when I input this size within Find/Change however, it finds nothing.

Likes

translate

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 ,
Feb 09, 2021 Feb 09, 2021

Copy link to clipboard

Copied

You could leave out the mm value in Find/Change.

Or you you can detect the precise value using a script. 4.233 mm could be the rounded value.

To help you more: Could you make a one page sample InDesign document available to download?

 

Thanks,
Uwe Laubender

( ACP )

Likes

translate

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
Explorer ,
Feb 09, 2021 Feb 09, 2021

Copy link to clipboard

Copied

Here is a link to an indd file called wsh.indd within my DropBox:

 

WSH indd File 

 

Basically, I want to take any and all rectangle frames with a placement of: x:0 mm y:0 mm w: 57 mm, h: 89 mm and convert the shape from a rounded rectangle to a rectangle.

Likes

translate

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
Explorer ,
Feb 09, 2021 Feb 09, 2021

Copy link to clipboard

Copied

By the way, I did get Find/Change to work just fine by removing the size in mm. This is a workable solution, as in this case, I think a script would be overkill.  Still, as a learning experience, I think it would be interesting to know the properties I would need to make a script to make this happen.

Likes

translate

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 ,
Feb 09, 2021 Feb 09, 2021

Copy link to clipboard

Copied

Try this script. 

//all page items on the bottom layer
var pi = app.documents[0].layers[-1].allPageItems


for (var i = 0; i < pi.length; i++){
    try {
        if (pi[i].bottomRightCornerOption != CornerOptions.NONE || pi[i].bottomLeftCornerOption != CornerOptions.NONE ||pi[i].topCornerOption != CornerOptions.NONE || pi[i].topLeftCornerOption != CornerOptions.NONE) {
            
            pi[i].properties = {bottomRightCornerOption: CornerOptions.NONE, 
            bottomLeftCornerOption: CornerOptions.NONE, 
            topRightCornerOption: CornerOptions.NONE, 
            topLeftCornerOption: CornerOptions.NONE}
        } 
    }catch(e) {}   
}; 

 

Note that this only checks the page items on the bottom layer and doesn’t include master page items. Also your sample includes multiple layers but everything is on the bottom layer

 

Likes

translate

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