Javascript - Default text and Grouping

Community Beginner ,
Jan 31, 2020

Copy link to clipboard

Copied

Someone wrote a code to help me automatically create new InDesign files that have a block added that has size/positioning labels, but I am having 2 issues with it:

1.) I want to change the default text for the document that is created.

2.) I would like certain items to be grouped (ex. group the arrows with the measurements).

 

Can anyone help?

 

Here is the code:

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, strokeAlignment: StrokeAlignment.INSIDE_ALIGNMENT});
        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.strokeWeight = 2;
        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.strokeWeight = 2;
        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();
}

TOPICS
Scripting, Type

Views

628

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

Javascript - Default text and Grouping

Community Beginner ,
Jan 31, 2020

Copy link to clipboard

Copied

Someone wrote a code to help me automatically create new InDesign files that have a block added that has size/positioning labels, but I am having 2 issues with it:

1.) I want to change the default text for the document that is created.

2.) I would like certain items to be grouped (ex. group the arrows with the measurements).

 

Can anyone help?

 

Here is the code:

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, strokeAlignment: StrokeAlignment.INSIDE_ALIGNMENT});
        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.strokeWeight = 2;
        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.strokeWeight = 2;
        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();
}

TOPICS
Scripting, Type

Views

629

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
Jan 31, 2020 0
Adobe Community Professional ,
Feb 01, 2020

Copy link to clipboard

Copied

Hi Steve,

I am not sure what you mean by your 1st question, could you elaborate as to what does that mean. For the 2nd question, i.e. grouping the arrow and its measurement box, add the following 2 lines before the for statement near the end of your code

app.documents[0].groups.add([myLineX, myXTextFrame])

app.documents[0].groups.add([myLineY, myYTextFrame])

 

-Manan

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
Reply
Loading...
Feb 01, 2020 0
Adobe Community Professional ,
Feb 01, 2020

Copy link to clipboard

Copied

On your first question, maybe create a paragraph style right after you add the colors:

 

 

    try{
        myParagraphStyle = myDocument.paragraphStyles.item("LabelStyle");
    	myName = myParagraphStyle.name;
    }
    catch (myError){
    	myParagraphStyle = myDocument.paragraphStyles.add({name:"LabelStyle"});
    }

    with(myParagraphStyle){
    	appliedFont = "Minion Pro";
        fontStyle = "Regular";
        fillColor = noprint;
        justification = Justification.RIGHT_ALIGN;
        //etc.
    }

 

And then apply the style:

 

      //myTextFrame.texts.everyItem().fillColor = noprint;
       //myTextFrame.parentStory.justification=Justification.RIGHT_ALIGN;
       myTextFrame.parentStory.appliedParagraphStyle = myParagraphStyle;
       myTextFrame.move([+ myPositionWidth+ myWinWidth -2.1, myDocument.documentPreferences.pageHeight - myPositionHeight -.7]);
      

 

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
Reply
Loading...
Feb 01, 2020 0
Enthusiast ,
Feb 01, 2020

Copy link to clipboard

Copied

Hi Steve,

Hahaha......I wrote that script for you.

Give the below code a try,

for some reason I have had some issues getting certain fonts to work but whats applied now does.

"Helvetica Neue Medium"

You can change the applied font and style with a suitable one that works and go with it!

 

 

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;

pages = app.documents[0].pages

 

}

 

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, strokeAlignment: StrokeAlignment.INSIDE_ALIGNMENT});

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;

myTextObject = myTextFrame.parentStory.characters.everyItem();

myTextObject.appliedFont = app.fonts.item("Helvetica Neue");

myTextObject.fontStyle = "Medium";

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.strokeWeight = "2pt";

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;

myXTextObject = myXTextFrame.parentStory.characters.everyItem();

myXTextObject.appliedFont = app.fonts.item("Helvetica Neue");

myXTextObject.fontStyle = "Medium";

myXTextFrame.parentStory.justification=Justification.CENTER_ALIGN;

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

 

app.documents[0].groups.add([myLineX, myXTextFrame]);

 

 

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

myLineY.strokeColor = "noprint";

myLineY.strokeWeight = "2pt";

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;

myYTextObject = myYTextFrame.parentStory.characters.everyItem();

myYTextObject.appliedFont = app.fonts.item("Helvetica Neue");

myYTextObject.fontStyle = "Medium";

myYTextFrame.parentStory.justification=Justification.CENTER_ALIGN;

myYTextFrame.rotationAngle = -90;

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

 

app.documents[0].groups.add([myLineY, myYTextFrame]);

 

 

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

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
Reply
Loading...
Feb 01, 2020 1
Enthusiast ,
Feb 01, 2020

Copy link to clipboard

Copied

Steve,

I'll email you the .jsx file.....something is going wrong with the code when coping and pasting on to this site.

 

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
Reply
Loading...
Feb 01, 2020 1
Community Beginner ,
Feb 03, 2020

Copy link to clipboard

Copied

Mike--you are a genius! This saves me SO much time!! Seriously, you are amazing.

Is it possible to run this script so that it adds/formats/positions everything into an open document (that is already set up the correct width/height) rather than creating a new document?

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
Reply
Loading...
Feb 03, 2020 0
Enthusiast ,
Feb 03, 2020

Copy link to clipboard

Copied

Hi Steve,

Yes its possible,  when you say "already set up the correct width/height" does that mean nothing more like the spot colors?

 

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
Reply
Loading...
Feb 03, 2020 0
Enthusiast ,
Feb 04, 2020

Copy link to clipboard

Copied

Hi Steve,

 

Give this a try. This script auto fills the document width and height dimensions from the active document.

doc = app.documents[0];

doc.viewPreferences.horizontalMeasurementUnits = MeasurementUnits.inches;
doc.viewPreferences.verticalMeasurementUnits = MeasurementUnits.inches;

var w = doc.documentPreferences.pageWidth;
var h = doc.documentPreferences.pageHeight;

 
var myDialog = app.dialogs.add({name:"Add Inputs to Document",canCancel:true}); 
with(myDialog){ 
    
with(dialogColumns.add()){
with (dialogRows.add()){
staticTexts.add({staticLabel:"Document Width:           "});
with(dialogColumns.add()){
var myDocumentWidth = realEditboxes.add({editValue:w});
with(dialogColumns.add()){
staticTexts.add({staticLabel:"inches"});
}
}
with (dialogRows.add()){
with(dialogColumns.add()){
staticTexts.add({staticLabel:"Document Height:          "});
with(dialogColumns.add()){
var myDocumentHeight = realEditboxes.add({editValue:h});
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[0];
with(myDocument.documentPreferences){
pageWidth = myDocWidth + "inches";
pageHeight = myDocHeight + "inches";

// pageOrientation = PageOrientation.landscape;

}

    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

   }
       try {
       var wb = doc.colors.add();
       wb.colorValue = [0,0,0,100];
       wb.name = "wb"; 
       wb.model =ColorModel.SPOT
       } catch (e) {
     }

     try {
      var noprint = doc.colors.add();
      noprint.colorValue = [100,0,0,0];
      noprint.name = "noprint"; 
      noprint.model =ColorModel.SPOT
      } catch (e) {
     }

        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, strokeAlignment: StrokeAlignment.INSIDE_ALIGNMENT});
        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;
       myTextObject = myTextFrame.parentStory.characters.everyItem();
       myTextObject.appliedFont = app.fonts.item("Helvetica Neue");
       myTextObject.fontStyle = "Medium";
       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.strokeWeight = "2pt";
        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;
        myXTextObject = myXTextFrame.parentStory.characters.everyItem();
        myXTextObject.appliedFont = app.fonts.item("Helvetica Neue");
        myXTextObject.fontStyle = "Medium";
        myXTextFrame.parentStory.justification=Justification.CENTER_ALIGN; 
        myXTextFrame.move([-0, myDocument.documentPreferences.pageHeight - myPositionHeight -myLineXOffset-.13]); 

        app.documents[0].groups.add([myLineX, myXTextFrame]);   
       

        myLineY= app.activeDocument.graphicLines.add({geometricBounds:["0in",".0in", myPositionHeight +"in",".0in"]});  
        myLineY.strokeColor = "noprint";
        myLineY.strokeWeight = "2pt";        
        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;
        myYTextObject = myYTextFrame.parentStory.characters.everyItem();
        myYTextObject.appliedFont = app.fonts.item("Helvetica Neue");
        myYTextObject.fontStyle = "Medium";        
        myYTextFrame.parentStory.justification=Justification.CENTER_ALIGN;
        myYTextFrame.rotationAngle = -90; 
        myYTextFrame.move([+ myLineYOffset + myPositionWidth + .24,myDocument.documentPreferences.pageHeight - myPositionHeight]);

        app.documents[0].groups.add([myLineY, myYTextFrame]);

  
        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

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
Reply
Loading...
Feb 04, 2020 0
Community Beginner ,
Mar 05, 2020

Copy link to clipboard

Copied

Hey Mike, sorry I am so slow at responding.
This code didn't work. I created a new document and ran the script, and got a weird Syntax Error that I don't know if I should post because it might have something to do with your computer. But the error is in line 1, and ends in cocoasubrtf840 with offending text: \.

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
Reply
Loading...
Mar 05, 2020 0
Enthusiast ,
Mar 05, 2020

Copy link to clipboard

Copied

Hi Steve,

 

Here you go...........This script auto fills the document width and height dimensions from the active document.

doc = app.documents[0];

doc.viewPreferences.horizontalMeasurementUnits = MeasurementUnits.inches;
doc.viewPreferences.verticalMeasurementUnits = MeasurementUnits.inches;

var w = doc.documentPreferences.pageWidth;
var h = doc.documentPreferences.pageHeight;

 
var myDialog = app.dialogs.add({name:"Add Inputs to Document",canCancel:true}); 
with(myDialog){ 
    
with(dialogColumns.add()){
with (dialogRows.add()){
staticTexts.add({staticLabel:"Document Width:           "});
with(dialogColumns.add()){
var myDocumentWidth = realEditboxes.add({editValue:w});
with(dialogColumns.add()){
staticTexts.add({staticLabel:"inches"});
}
}
with (dialogRows.add()){
with(dialogColumns.add()){
staticTexts.add({staticLabel:"Document Height:          "});
with(dialogColumns.add()){
var myDocumentHeight = realEditboxes.add({editValue:h});
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[0];
with(myDocument.documentPreferences){
pageWidth = myDocWidth + "inches";
pageHeight = myDocHeight + "inches";

// pageOrientation = PageOrientation.landscape;

}

    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

   }
       try {
       var wb = doc.colors.add();
       wb.colorValue = [0,0,0,100];
       wb.name = "wb"; 
       wb.model =ColorModel.SPOT
       } catch (e) {
     }

     try {
      var noprint = doc.colors.add();
      noprint.colorValue = [100,0,0,0];
      noprint.name = "noprint"; 
      noprint.model =ColorModel.SPOT
      } catch (e) {
     }

        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, strokeAlignment: StrokeAlignment.INSIDE_ALIGNMENT});
        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;
       myTextObject = myTextFrame.parentStory.characters.everyItem();
       myTextObject.appliedFont = app.fonts.item("Helvetica Neue");
       myTextObject.fontStyle = "Medium";
       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.strokeWeight = "2pt";
        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;
        myXTextObject = myXTextFrame.parentStory.characters.everyItem();
        myXTextObject.appliedFont = app.fonts.item("Helvetica Neue");
        myXTextObject.fontStyle = "Medium";
        myXTextFrame.parentStory.justification=Justification.CENTER_ALIGN; 
        myXTextFrame.move([-0, myDocument.documentPreferences.pageHeight - myPositionHeight -myLineXOffset-.13]); 

        app.documents[0].groups.add([myLineX, myXTextFrame]);   
       

        myLineY= app.activeDocument.graphicLines.add({geometricBounds:["0in",".0in", myPositionHeight +"in",".0in"]});  
        myLineY.strokeColor = "noprint";
        myLineY.strokeWeight = "2pt";        
        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;
        myYTextObject = myYTextFrame.parentStory.characters.everyItem();
        myYTextObject.appliedFont = app.fonts.item("Helvetica Neue");
        myYTextObject.fontStyle = "Medium";        
        myYTextFrame.parentStory.justification=Justification.CENTER_ALIGN;
        myYTextFrame.rotationAngle = -90; 
        myYTextFrame.move([+ myLineYOffset + myPositionWidth + .24,myDocument.documentPreferences.pageHeight - myPositionHeight]);

        app.documents[0].groups.add([myLineY, myYTextFrame]);

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

 

This version works the same way without displaying the document W and H dimensions.

 

doc = app.documents[0];

doc.viewPreferences.horizontalMeasurementUnits = MeasurementUnits.inches;
doc.viewPreferences.verticalMeasurementUnits = MeasurementUnits.inches;

var myDocumentWidth = doc.documentPreferences.pageWidth;
var myDocumentHeight = doc.documentPreferences.pageHeight;

 
var myDialog = app.dialogs.add({name:"Add Inputs to Document",canCancel:true}); 
with(myDialog){ 
with(dialogColumns.add()){
with (dialogRows.add()){
     
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(myWindowWidth.editValue < .0625 || 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;
var myDocHeight = myDocumentHeight;
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[0];
with(myDocument.documentPreferences){
pageWidth = myDocWidth + "inches";
pageHeight = myDocHeight + "inches";

// pageOrientation = PageOrientation.landscape;
}

    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

   }
       try {
       var wb = doc.colors.add();
       wb.colorValue = [0,0,0,100];
       wb.name = "wb"; 
       wb.model =ColorModel.SPOT
       } catch (e) {
     }

     try {
      var noprint = doc.colors.add();
      noprint.colorValue = [100,0,0,0];
      noprint.name = "noprint"; 
      noprint.model =ColorModel.SPOT
      } catch (e) {
     }

        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, strokeAlignment: StrokeAlignment.INSIDE_ALIGNMENT});
        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;
       myTextObject = myTextFrame.parentStory.characters.everyItem();
       myTextObject.appliedFont = app.fonts.item("Helvetica Neue");
       myTextObject.fontStyle = "Medium";
       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.strokeWeight = "2pt";
        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;
        myXTextObject = myXTextFrame.parentStory.characters.everyItem();
        myXTextObject.appliedFont = app.fonts.item("Helvetica Neue");
        myXTextObject.fontStyle = "Medium";
        myXTextFrame.parentStory.justification=Justification.CENTER_ALIGN; 
        myXTextFrame.move([-0, myDocument.documentPreferences.pageHeight - myPositionHeight -myLineXOffset-.13]); 

        app.documents[0].groups.add([myLineX, myXTextFrame]);   
       

        myLineY= app.activeDocument.graphicLines.add({geometricBounds:["0in",".0in", myPositionHeight +"in",".0in"]});  
        myLineY.strokeColor = "noprint";
        myLineY.strokeWeight = "2pt";        
        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;
        myYTextObject = myYTextFrame.parentStory.characters.everyItem();
        myYTextObject.appliedFont = app.fonts.item("Helvetica Neue");
        myYTextObject.fontStyle = "Medium";        
        myYTextFrame.parentStory.justification=Justification.CENTER_ALIGN;
        myYTextFrame.rotationAngle = -90; 
        myYTextFrame.move([+ myLineYOffset + myPositionWidth + .24,myDocument.documentPreferences.pageHeight - myPositionHeight]);

        app.documents[0].groups.add([myLineY, myYTextFrame]);

  
        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

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
Reply
Loading...
Mar 05, 2020 0
Community Beginner ,
Jan 07, 2021

Copy link to clipboard

Copied

I have been messing around with this code again, and have customized it a great deal. However, this line is giving me problems:

 

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

 

Any time I try to change either dimension (.7in and/or 2in), I get an error message for an invalid value. Mike (or anyone else), do you know why this is happening and/or how I can change it?

 

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
Reply
Loading...
Jan 07, 2021 0
Adobe Community Professional ,
Jan 07, 2021

Copy link to clipboard

Copied

Can you provide a sample line that's throwing that error? I presume you are leaving the quotation marks in?

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
Reply
Loading...
Jan 07, 2021 0