Copy link to clipboard
Copied
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
Copy link to clipboard
Copied
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
Yellow Rectangle on YELLOW_BLANK layer
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
Get ready! An upgraded Adobe Community experience is coming in January.
Learn more