Script to make custom size rectangular box shape

New Here ,
Sep 09, 2021 Sep 09, 2021

Copy link to clipboard

Copied

Hi,

Could anyone guide me with making a script that would generate a rectangle shape, where the user could specify:

Width, height, linetype (defaults to dashed), outline thickness, outline color (defaults to black), no fill or fill color (but defaults to no fill), bleed size (defaults to 1/2")

 

Ideally the script would generate a graphic template like the sample below: a dashed line black rectangle (Finished Size Rectangle) based on the the user inputted width and height, but would also generate two more rectangles:

  • Bleed Rectangle: a second larger outline only red rectangle (with a 50% transparency) that is offset outward by the bleed size on each of the 4 sides, and that has a line thickness equal to the bleed size. 
  • Safe Zone Rectangle: a third smaller green outline only that is offset inward by 1" on each of the 4 sides.
  • And also fill in the Text Variables circled in red on my sample attached, based on the inputted values

 

As a bonus it would be great if the Document Setup dimensions would be able to update automatically to the values of the red Bleed Rectangle.

 

Thanks for any help you can provide on this!!!template sample.jpg

TOPICS
Scripting

Views

162

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
Advocate ,
Sep 09, 2021 Sep 09, 2021

Copy link to clipboard

Copied

Hello @TestriteVisual,

 

I created a similar type script you can use as a starting point, you'll need to modify it to your specific needs.

you can find it in the post below...

https://community.adobe.com/t5/indesign-discussions/auto-generate-boxes-from-measurements/m-p/104714...

 

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
New Here ,
Sep 28, 2021 Sep 28, 2021

Copy link to clipboard

Copied

Awesome Mike,

Very much appreciated, I'll give it a go!!

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
New Here ,
Nov 16, 2021 Nov 16, 2021

Copy link to clipboard

Copied

Hi Mike,

 

Could you please tell me what broad text swap change, if any, I could make to have all of the "rectangle frame tool" shapes that are created to just be plane "rectangle tool" shapes instead?

 

Thanks!

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
New Here ,
Nov 16, 2021 Nov 16, 2021

Copy link to clipboard

Copied

Any chance you coul provide an Adobe link for where I could find all the script variables? Much appreciated!!

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 16, 2021 Nov 16, 2021

Copy link to clipboard

Copied

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 16, 2021 Nov 16, 2021

Copy link to clipboard

Copied

LATEST

Hi @TestriteVisual , The Y1,X1,Y2,X2 format for geometric bounds isn’t very intuitive, so in addition to @mikeb41294032 ’s script, the bounds of an empty rectangle could be set as x,y,w,h via a function like this:

 

app.scriptPreferences.measurementUnit = MeasurementUnits.INCHES
app.activeDocument.zeroPoint = [0,0]
var p = app.activeDocument.pages[0];


//makes an empty rectangle with no content assignment at x,y,w,h
var f = setXYWH(p,1,1,5,5)


/**
* Makes a recatangle at x,y,width,height 
* @param the page to target 
* @param x 
* @param y 
* @param width
* @param height 
* @return the rectangle 
* 
*/
function setXYWH(p,x,y,w,h){
    return p.rectangles.add ({geometricBounds:[y,x, y+h, x+w], contentType:ContentType.UNASSIGNED});
}

 

Here’s the rectangle properties API page:

 

https://www.indesignjs.de/extendscriptAPI/indesign-latest/#Rectangle.html#d1e217417

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