Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

InDesign Script: How to Add a Rectangle on Layer

Explorer ,
Oct 01, 2019 Oct 01, 2019

I am trying to figure out how to add a new Rectangle object onto the active layer; and then fill it with color: Red.

 

In this script below, I am adding a new Layer called "RED_BLANK" if it doesn't already exist.

Then I want to add a rectangle object to this layer (the full size of the document) and color it RED. I've tried a few different ways, but this is the latest.  the line that failing is trying to add the rectangle and set its size and fill color.

 

Thanks,
Heather


//***************************************** RED LAYER ***********************************************
adorName="RED_BLANK";

//Check master file for layer that matches adorName
targetLayer=myDoc.layers.itemByName(adorName);

//if does not exist, then add it
if(targetLayer==null)
{
//if no layer found create one
myDoc.layers.add ({name: adorName, layerColor: UIColors.RED}).move(LocationOptions.AT_BEGINNING);
//apply the visibility ador to the new layer
targetLayer=myDoc.layers.itemByName(adorName);
targetLayer.adorName =adorName;

var myPage = myDoc.pages.item(0);

//BELOW IS THE LINE THAT IS FAILING
var myRectangle = myPage.rectangles.add({geometricBounds: [9,6,9, 6], fillColor: "Red"});

}//end IF

3.4K
Translate
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 ,
Oct 02, 2019 Oct 02, 2019
LATEST

Got it 😄

 

In this case, in the code below... there is a RED_BLANK and YELLOW_BLANK layer added and then a rectangle added to each of those new layers; a Magenta rectangle on the RED_BLANK layer and a Yellow rectangle on the YELLOW_BLANK layer.

 

I will now just fool around with the size but at least I now have the syntax.

 

//***************************************** RED LAYER ***********************************************
adorName="RED_BLANK";

targetLayer=myDoc.layers.itemByName(adorName);

//if does not exist, then add it
if(targetLayer==null)
{
//if no layer found create one
myDoc.layers.add ({name: adorName, layerColor: UIColors.RED}).move(LocationOptions.AT_BEGINNING);
//apply the visibility ador to the new layer
targetLayer=myDoc.layers.itemByName(adorName);
//targetLayer.adorName =adorName;
var rect =myDoc.rectangles.add({geometricBounds : [0,0,100,100] ,fillColor : myDoc.colors.itemByName("Magenta") });
}//end IF


//***************************************** YELLOW LAYER ***********************************************
adorName="YELLOW_BLANK";

targetLayer=myDoc.layers.itemByName(adorName);

//if does not exist, then add it
if(targetLayer==null)
{
//if no layer found create one
myDoc.layers.add ({name: adorName, layerColor: UIColors.YELLOW}).move(LocationOptions.AT_BEGINNING);
//apply the visibility ador to the new layer
targetLayer=myDoc.layers.itemByName(adorName);
//targetLayer.adorName =adorName;
var rect =myDoc.rectangles.add({geometricBounds : [0,0,100,100] ,fillColor : myDoc.colors.itemByName("Yellow") });
}//end IF

 

Results:

 

Magenta rectangle on RED_BLANK layer

clipboard_image_1.png

 

Yellow Rectangle on YELLOW_BLANK layer

clipboard_image_0.png

 

Last but not least....

This forum helped me figure it out.
https://community.adobe.com/t5/InDesign/How-can-add-a-parallelogram-shape-by-Script/m-p/9822715

clipboard_image_0.png

 

Translate
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