Skip to main content
TestriteVisual
Inspiring
September 9, 2021
Question

Script to make custom size rectangular box shape

  • September 9, 2021
  • 2 replies
  • 1033 views

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!!!

This topic has been closed for replies.

2 replies

rob day
Community Expert
Community Expert
November 16, 2021

Hi @TestriteVisual , The Y1,X1,Y2,X2 format for geometric bounds isn’t very intuitive, so in addition to @Mike Bro ’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

Legend
September 9, 2021

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/10471460#M142911

 

Regards,

Mike

 

TestriteVisual
Inspiring
September 28, 2021

Awesome Mike,

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