Skip to main content
Inspiring
July 2, 2019
Answered

Auto-generate boxes from measurements

  • July 2, 2019
  • 3 replies
  • 1307 views

I perform a complex series of steps on a daily basis, and was wondering if anyone had any idea how to go about automating it. Here it is in a nutshell:


We are given 3 measurements that we use to make 3 rectangle frames: A, B, and C:

A.) Page Size Box (h" x w")

     -Same dimensions as the page size.

     -No fill, 1 pt stroke (WB spot color)

B.) Window Box (h" x w")

     -No fill, 1 pt stroke (WB spot color), .25" rounded corners.

C.) Positioning Box (h" x w")

     -No fill, no stroke

Also, we use 2 spot colors called "wb" and "noprint".

Here is the process:

1.) Add the Page Size Box (A). Center to page.

2.) Add the Positioning Box (C). Position to lower left corner.

3.) Add the Window Box (B) the lower left corner of this box should meet the upper-right corner of the Positioning Box (C).

4.) Add a text-box in the lower right of the Window Box (B) that lists the A, B, and C measurements w/the "noprint" spot color.

5.) Label the dimensions of the Positioning Box (C) with measurements and arrows. Align these to the Window Box (B).

(image of the final file is included)

I was wondering if there was a way to enter the 6 measurements into a pop-up window or an excel file or something, and create this file automatically? Anyone have any ideas how to make that happen, or a better way to go about it?

Thanks a TON!

This topic has been closed for replies.
Correct answer Mike Bro

Steve,

Sorry, - Re-posting the code due to a missing bracket and a typo......

var myDialog = app.dialogs.add({name:"Create New Document",canCancel:true});

with(myDialog){

   

with(dialogColumns.add()){

with (dialogRows.add()){

staticTexts.add({staticLabel:"Enter Document Width:  "});

with(dialogColumns.add()){

var myDocumentWidth = realEditboxes.add({editValue:0});

with(dialogColumns.add()){

staticTexts.add({staticLabel:"inches"});

}

}

with (dialogRows.add()){

with(dialogColumns.add()){

staticTexts.add({staticLabel:"Enter Document Height: "});

with(dialogColumns.add()){

var myDocumentHeight = realEditboxes.add({editValue:0});

with(dialogColumns.add()){

staticTexts.add({staticLabel:"inches"});

}

}

}

with (dialogRows.add()){

with(dialogColumns.add()){

staticTexts.add({staticLabel:"Enter Window Width:      "});

with(dialogColumns.add()){

var myWindowWidth = realEditboxes.add({editValue:0});

with(dialogColumns.add()){

staticTexts.add({staticLabel:"inches"});

}

}

}

with (dialogRows.add()){

with(dialogColumns.add()){

staticTexts.add({staticLabel:"Enter Window Height:     "});

with(dialogColumns.add()){

var myWindowHeight = realEditboxes.add({editValue:0});

with(dialogColumns.add()){

staticTexts.add({staticLabel:"inches"});

}

}

}

with (dialogRows.add()){

with(dialogColumns.add()){

staticTexts.add({staticLabel:"Enter Positioning Width: "});

with(dialogColumns.add()){

var myPositioningWidth = realEditboxes.add({editValue:0});

with(dialogColumns.add()){

staticTexts.add({staticLabel:"inches"});

}

}

}

with (dialogRows.add()){

with(dialogColumns.add()){

staticTexts.add({staticLabel:"Enter Positioning Height:"});

with(dialogColumns.add()){

var myPositioningHeight = realEditboxes.add({editValue:0});

with(dialogColumns.add()){

staticTexts.add({staticLabel:"inches"});

                      }

                 }

             }

         }

                      }

                }

           }

      }

                }

          }

     }

var myResult = myDialog.show();

if(myResult == true){

   

//~  Invalid values based on minimum allowed by Adobe InDesign

if(myDocumentWidth.editValue < 1.125 || myDocumentHeight.editValue < 1.125 || myWindowWidth.editValue < 1.125 || myWindowHeight.editValue < .0625|| myPositioningWidth.editValue < .0625 || myPositioningHeight.editValue < .0625) {

alert ("Error!\nA invalid value was entered in one or more of the fields.");

exit();

}

var myDocWidth = myDocumentWidth.editValue;

var myDocHeight = myDocumentHeight.editValue;

var myWinWidth = myWindowWidth.editValue;

var myWinHeight = myWindowHeight.editValue; 

var myPositionWidth = myPositioningWidth.editValue;

var myPositionHeight = myPositioningHeight.editValue;

var myPositionW = myPositionWidth.toString();

var myPositionWSize = myPositionW.replace(/^0+/, '')

var myPositionH = myPositionHeight.toString();

var myPositionHSize = myPositionH.replace(/^0+/, '')

 

var myDocument = app.documents.add();

with(myDocument.documentPreferences){

pageWidth = myDocWidth + "inches";

pageHeight = myDocHeight + "inches";

//~ pageOrientation = PageOrientation.landscape;

pagesPerDocument = 1;

}

    var doc = app.documents[0];

    doc.properties = {

    viewPreferences:{

        horizontalMeasurementUnits: +MeasurementUnits.INCHES,

        verticalMeasurementUnits: +MeasurementUnits.INCHES,

        },

            documentPreferences: {

            documentBleedBottomOffset: ".0 in",

            documentBleedTopOffset: ".0 in",

            documentBleedInsideOrLeftOffset: ".0 in",

            documentBleedOutsideOrRightOffset: ".0 in",

       }

  }

       var page = doc.pages.item(0);

        page.marginPreferences.properties = {

        top : 0,

        left: 0,

        right: 0,

        bottom: 0

   }

   

       var wb = doc.colors.add();

       wb.colorValue = [0,0,0,100];

       wb.name = "wb";

       wb.model =ColorModel.SPOT

      var noprint = doc.colors.add();

      noprint.colorValue = [100,0,0,0];

      noprint.name = "noprint";

      noprint.model =ColorModel.SPOT

        docframe = doc.rectangles.add ({geometricBounds:[".0in",".0in", myDocHeight + "in", myDocWidth + "in"], contentType:ContentType.GRAPHIC_TYPE});

        docframe.fillColor  = "None";

        docframe.strokeWeight = "1pt";

        docframe.strokeType = "Solid";

        docframe.strokeColor = "wb";

       

               

        posframe = doc.rectangles.add ({geometricBounds:["0in", "0in", myPositionHeight + "in", myPositionWidth + "in"], contentType:ContentType.GRAPHIC_TYPE});       

        posframe.fillColor  = "None";

        posframe.strokeWeight = "0pt";

        posframe.strokeType = "None";

        posframe.strokeColor = "None";                   

        posframe.move([-0,myDocument.documentPreferences.pageHeight - myPositionHeight]);

      

      

        winframe = doc.rectangles.add ({geometricBounds:["0in", "0in", myWinHeight + "in", myWinWidth + "in"], contentType:ContentType.GRAPHIC_TYPE});

        winframe.fillColor  = "None";

        winframe.strokeWeight = "1pt";

        winframe.strokeType = "Solid";

        winframe.strokeColor = "wb";                 

        winframe.topLeftCornerOption = CornerOptions.ROUNDED_CORNER;                    

        winframe.topLeftCornerRadius = .25;                   

        winframe.bottomLeftCornerOption = CornerOptions.ROUNDED_CORNER;                    

        winframe.bottomLeftCornerRadius = .25;                                       

        winframe.topRightCornerOption = CornerOptions.ROUNDED_CORNER;                   

        winframe.topRightCornerRadius = .25;                     

        winframe.bottomRightCornerOption = CornerOptions.ROUNDED_CORNER;                     

        winframe.bottomRightCornerRadius = .25;                                  

        winframe.move([myPositionWidth ,myDocument.documentPreferences.pageHeight - myWinHeight - myPositionHeight + "in"]);

            

    

       myTextFrame = doc.textFrames.add ({geometricBounds:["0in","0in",".7in","2in"]});

       myTextFrame.contents = myDocWidth +'"'+ ' X ' + myDocHeight +'"\r '+ myWinWidth +'"'+ ' X ' + myWinHeight +'"'+' Window\r '+ myPositionWSize +'" Left, ' + myPositionHSize +'" Bottom';

       myTextFrame.texts.everyItem().fillColor = noprint;

       myTextFrame.parentStory.justification=Justification.RIGHT_ALIGN;

       myTextFrame.move([+ myPositionWidth+ myWinWidth -2.1, myDocument.documentPreferences.pageHeight - myPositionHeight -.7]);

      

      

        myLineX= app.activeDocument.graphicLines.add({geometricBounds:["0in","0in",".0in", myPositionWidth +"in"]}); 

        myLineX.strokeColor = "noprint";

        myLineX.leftLineEnd = ArrowHead.CURVED_ARROW_HEAD;

        myLineX.rightLineEnd = ArrowHead.CURVED_ARROW_HEAD;

        myLineXOffset = myWinHeight / 2; 

        myLineX.move([-0,myDocument.documentPreferences.pageHeight  - myPositionHeight - myLineXOffset]);

      

      

        myXTextFrame = doc.textFrames.add ({geometricBounds:["0in","0in",".17in", myPositionWidth +"in"]});   

        myXTextFrame.contents = myPositionWSize + '"';

        myXTextFrame.texts.everyItem().fillColor = noprint;

        myXTextFrame.parentStory.justification=Justification.CENTER_ALIGN;

        myXTextFrame.move([-0, myDocument.documentPreferences.pageHeight - myPositionHeight -myLineXOffset-.13]);

       

       

        myLineY= app.activeDocument.graphicLines.add({geometricBounds:["0in",".0in", myPositionHeight +"in",".0in"]}); 

        myLineY.strokeColor = "noprint";

        myLineY.leftLineEnd = ArrowHead.CURVED_ARROW_HEAD;

        myLineY.rightLineEnd = ArrowHead.CURVED_ARROW_HEAD;

        myLineYOffset = myWinWidth / 2; 

        myLineY.move([myPositionWidth + myLineYOffset, myDocument.documentPreferences.pageHeight - myPositionHeight]);

      

       

        myYTextFrame = doc.textFrames.add ({geometricBounds:[".17in", myPositionHeight +"in","0in","0in"]});  

        myYTextFrame.contents = myPositionHSize + '"';

        myYTextFrame.texts.everyItem().fillColor = noprint;

        myYTextFrame.parentStory.justification=Justification.CENTER_ALIGN;

        myYTextFrame.rotationAngle = -90;

        myYTextFrame.move([+ myLineYOffset + myPositionWidth + .2,myDocument.documentPreferences.pageHeight - myPositionHeight]);

 

 

        for(var i = 0; i < doc.textFrames.length; i++) {

        while(doc.textFrames.item(i).overflows) {

        var fontSize = doc.textFrames.item(i).paragraphs.item(0).pointSize;

        doc.textFrames.item(i).paragraphs.item(0).pointSize = fontSize-.5;

        myTextFrame.texts.everyItem().fillColor = noprint;      

        myXTextFrame.texts.everyItem().fillColor = noprint;

        myYTextFrame.texts.everyItem().fillColor = noprint;

    }

}

       }else{

     myDialog.destroy();

}

Regards,

Mike

3 replies

Legend
July 22, 2019

Steve,

Give this a try for your needs.......enjoy!

var myDialog = app.dialogs.add({name:"Create New Document",canCancel:true});

with(myDialog){

   

with(dialogColumns.add()){

with (dialogRows.add()){

staticTexts.add({staticLabel:"Enter Document Width:  "});

with(dialogColumns.add()){

var myDocumentWidth = realEditboxes.add({editValue:0});

with(dialogColumns.add()){

staticTexts.add({staticLabel:"inches"});

}

}

with (dialogRows.add()){

with(dialogColumns.add()){

staticTexts.add({staticLabel:"Enter Document Height: "});

with(dialogColumns.add()){

var myDocumentHeight = realEditboxes.add({editValue:0});

with(dialogColumns.add()){

staticTexts.add({staticLabel:"inches"});

}

}

}

with (dialogRows.add()){

with(dialogColumns.add()){

staticTexts.add({staticLabel:"Enter Window Width:      "});

with(dialogColumns.add()){

var myWindowWidth = realEditboxes.add({editValue:0});

with(dialogColumns.add()){

staticTexts.add({staticLabel:"inches"});

}

}

}

with (dialogRows.add()){

with(dialogColumns.add()){

staticTexts.add({staticLabel:"Enter Window Height:     "});

with(dialogColumns.add()){

var myWindowHeight = realEditboxes.add({editValue:0});

with(dialogColumns.add()){

staticTexts.add({staticLabel:"inches"});

}

}

}

with (dialogRows.add()){

with(dialogColumns.add()){

staticTexts.add({staticLabel:"Enter Positioning Width: "});

with(dialogColumns.add()){

var myPositioningWidth = realEditboxes.add({editValue:0});

with(dialogColumns.add()){

staticTexts.add({staticLabel:"inches"});

}

}

}

with (dialogRows.add()){

with(dialogColumns.add()){

staticTexts.add({staticLabel:"Enter Positioning Height:"});

with(dialogColumns.add()){

var myPositioningHeight = realEditboxes.add({editValue:0});

with(dialogColumns.add()){

staticTexts.add({staticLabel:"inches"});

                      }

                 }

             }

         }

                      }

                }

           }

      }

                }

          }

     }

var myResult = myDialog.show();

if(myResult == true){

   

//~  Invalid values based on minimum allowed by Adobe InDesign

if(myDocumentWidth.editValue < 1.125 || myDocumentHeight.editValue < 1.125 || myWindowWidth.editValue < 1.125 || myWindowHeight.editValue < .0625|| myPositioningWidth.editValue < .0625 || myPositioningHeight.editValue < .0625 {

alert ("Error!\nA invalid value was entered in one or more of the fields.");

exit();

}

var myDocWidth = myDocumentWidth.editValue;

var myDocHeight = myDocumentHeight.editValue;

var myWinWidth = myWindowWidth.editValue;

var myWinHeight = myWindowHeight.editValue; 

var myPositionWidth = myPositioningWidth.editValue;

var myPositionHeight = myPositionminimumingHeight.editValue;

var myPositionW = myPositionWidth.toString();

var myPositionWSize = myPositionW.replace(/^0+/, '')

var myPositionH = myPositionHeight.toString();

var myPositionHSize = myPositionH.replace(/^0+/, '')

 

var myDocument = app.documents.add();

with(myDocument.documentPreferences){

pageWidth = myDocWidth + "inches";

pageHeight = myDocHeight + "inches";

//~ pageOrientation = PageOrientation.landscape;

pagesPerDocument = 1;

}

    var doc = app.documents[0];

    doc.properties = {

    viewPreferences:{

        horizontalMeasurementUnits: +MeasurementUnits.INCHES,

        verticalMeasurementUnits: +MeasurementUnits.INCHES,

        },

            documentPreferences: {

            documentBleedBottomOffset: ".0 in",

            documentBleedTopOffset: ".0 in",

            documentBleedInsideOrLeftOffset: ".0 in",

            documentBleedOutsideOrRightOffset: ".0 in",

       }

  }

       var page = doc.pages.item(0);

        page.marginPreferences.properties = {

        top : 0,

        left: 0,

        right: 0,

        bottom: 0

   }

   

       var wb = doc.colors.add();

       wb.colorValue = [0,0,0,100];

       wb.name = "wb";

       wb.model =ColorModel.SPOT

      var noprint = doc.colors.add();

      noprint.colorValue = [100,0,0,0];

      noprint.name = "noprint";

      noprint.model =ColorModel.SPOT

        docframe = doc.rectangles.add ({geometricBounds:[".0in",".0in", myDocHeight + "in", myDocWidth + "in"],    contentType:ContentType.GRAPHIC_TYPE});

        docframe.fillColor  = "None";

        docframe.strokeWeight = "1pt";

        docframe.strokeType = "Solid";

        docframe.strokeColor = "wb";

       

               

        posframe = doc.rectangles.add ({geometricBounds:["0in", "0in", myPositionHeight + "in", myPositionWidth + "in"], contentType:ContentType.GRAPHIC_TYPE});       

        posframe.fillColor  = "None";

        posframe.strokeWeight = "0pt";

        posframe.strokeType = "None";

        posframe.strokeColor = "None";                   

        posframe.move([-0,myDocument.documentPreferences.pageHeight - myPositionHeight]);

      

      

        winframe = doc.rectangles.add ({geometricBounds:["0in", "0in", myWinHeight + "in", myWinWidth + "in"], contentType:ContentType.GRAPHIC_TYPE});

        winframe.fillColor  = "None";

        winframe.strokeWeight = "1pt";

        winframe.strokeType = "Solid";

        winframe.strokeColor = "wb";                 

        winframe.topLeftCornerOption = CornerOptions.ROUNDED_CORNER;                    

        winframe.topLeftCornerRadius = .25;                   

        winframe.bottomLeftCornerOption = CornerOptions.ROUNDED_CORNER;                    

        winframe.bottomLeftCornerRadius = .25;                                       

        winframe.topRightCornerOption = CornerOptions.ROUNDED_CORNER;                   

        winframe.topRightCornerRadius = .25;                     

        winframe.bottomRightCornerOption = CornerOptions.ROUNDED_CORNER;                     

        winframe.bottomRightCornerRadius = .25;                                  

        winframe.move([myPositionWidth ,myDocument.documentPreferences.pageHeight - myWinHeight - myPositionHeight + "in"]);

            

    

       myTextFrame = doc.textFrames.add ({geometricBounds:["0in","0in",".7in","2in"]});

       myTextFrame.contents = myDocWidth +'"'+ ' X ' + myDocHeight +'"\r '+ myWinWidth +'"'+ ' X ' + myWinHeight +'"'+' Window\r '+ myPositionWSize +'" Left, ' + myPositionHSize +'" Bottom';

       myTextFrame.texts.everyItem().fillColor = noprint;

       myTextFrame.parentStory.justification=Justification.RIGHT_ALIGN;

       myTextFrame.move([+ myPositionWidth+ myWinWidth -2.1, myDocument.documentPreferences.pageHeight - myPositionHeight -.7]);

      

      

        myLineX= app.activeDocument.graphicLines.add({geometricBounds:["0in","0in",".0in", myPositionWidth +"in"]}); 

        myLineX.strokeColor = "noprint";

        myLineX.leftLineEnd = ArrowHead.CURVED_ARROW_HEAD;

        myLineX.rightLineEnd = ArrowHead.CURVED_ARROW_HEAD;

        myLineXOffset = myWinHeight / 2; 

        myLineX.move([-0,myDocument.documentPreferences.pageHeight  - myPositionHeight - myLineXOffset]);

      

      

        myXTextFrame = doc.textFrames.add ({geometricBounds:["0in","0in",".17in", myPositionWidth +"in"]});   

        myXTextFrame.contents = myPositionWSize + '"';

        myXTextFrame.texts.everyItem().fillColor = noprint;

        myXTextFrame.parentStory.justification=Justification.CENTER_ALIGN;

        myXTextFrame.move([-0, myDocument.documentPreferences.pageHeight - myPositionHeight -myLineXOffset-.13]);

       

       

        myLineY= app.activeDocument.graphicLines.add({geometricBounds:["0in",".0in", myPositionHeight +"in",".0in"]}); 

        myLineY.strokeColor = "noprint";

        myLineY.leftLineEnd = ArrowHead.CURVED_ARROW_HEAD;

        myLineY.rightLineEnd = ArrowHead.CURVED_ARROW_HEAD;

        myLineYOffset = myWinWidth / 2; 

        myLineY.move([myPositionWidth + myLineYOffset, myDocument.documentPreferences.pageHeight - myPositionHeight]);

      

       

        myYTextFrame = doc.textFrames.add ({geometricBounds:[".17in", myPositionHeight +"in","0in","0in"]});  

        myYTextFrame.contents = myPositionHSize + '"';

        myYTextFrame.texts.everyItem().fillColor = noprint;

        myYTextFrame.parentStory.justification=Justification.CENTER_ALIGN;

        myYTextFrame.rotationAngle = -90;

        myYTextFrame.move([+ myLineYOffset + myPositionWidth + .2,myDocument.documentPreferences.pageHeight - myPositionHeight]);

 

 

        for(var i = 0; i < doc.textFrames.length; i++) {

        while(doc.textFrames.item(i).overflows) {

        var fontSize = doc.textFrames.item(i).paragraphs.item(0).pointSize;

        doc.textFrames.item(i).paragraphs.item(0).pointSize = fontSize-.5;

        myTextFrame.texts.everyItem().fillColor = noprint;      

        myXTextFrame.texts.everyItem().fillColor = noprint;

        myYTextFrame.texts.everyItem().fillColor = noprint;

    }

}

       }else{

     myDialog.destroy();

}

Regards,

Mike

Inspiring
July 22, 2019

Forgive me, but I don't have much coding experience. How do I import this code?

Legend
July 22, 2019

Hi Steve,

On a Mac copy the code in to TextEdit, then choose Format->Make Plain Text before saving. Save the file naming to your liking then add the .jsx file extension. In InDesign go to (Window > Utilities > Scripts), then right-click on User folder, Reveal in Finder and place the script in the Scripts Panel folder. You'll now be able to run the script from the Scripts panel user folder by double clicking on it.

Regards,

Mike

Legend
July 3, 2019

Hello Steve,

Take a look at this post Scripting shape creation reply #2, this should be a good starting point for you to get started to add the additional functions you're looking for.

Regards,

Mike

John Mensinger
Community Expert
Community Expert
July 2, 2019

I suspect at least some of this can be scripted; ask here: InDesign Scripting

Community Expert
July 3, 2019

Moving it to the scripting forum

-Manan

-Manan