Skip to main content
Participant
Jun 25, 2023 6:29 AM UTC
Question

can anyone help me with shape object scripting?

this is my first time posting in the community. i'm sorry if there's a mistake.

so i was working on a javascript that allow you to create a shape adjustment layer and i want to activate the Tool Create Mask in the shape object via javascript without change it manually, but i'm still not understand the logic of "Tool Create Mask". i've already read the scripting guide but i'm still stuck. is there anyone can help me?

 

here's the script

function addShape(){
    app.beginUndoGroup("addShape");

    app.executeCommand(3736);   //Add Shape Layer
    var comp = app.project.activeItem;
    var thisLayer = comp.selectedLayers[0];
    thisLayer.name = "Adjustment Shape";
    thisLayer.adjustmentLayer = true;
    thisLayer.transform.position.setValue([0, 0]);
    thisLayer.transform.position.expression = "[ thisComp.width/2, thisComp.height/2 ];";
    thisLayer.property("ADBE Root Vectors Group").addProperty("ADBE Vector Shape - Rect");
    thisLayer.property("ADBE Root Vectors Group").property(1).property("ADBE Vector Rect Size").expression = "[ thisComp.width, thisComp.height ];";
    thisLayer.property("ADBE Root Vectors Group").addProperty("ADBE Vector Graphic - Fill");
    thisLayer.label = 5;
    app.endUndoGroup();
}

addShape();

 

This topic is closed to new replies. Start a new post to keep the conversation going.

2 replies

Mylenium
Legend
Jun 25, 2023 8:00 AM UTC

I think you are misunderstandiung the process. Tools are tools and the program would expect you to manually use them and draw your rectangle. If you really just want to add a shape layer rectangle, you can easily do it by just adding the properties directly with the addProperty() method an d define whatever  property parameters you need. Relying on the menu command just to create standard layer types is not safe/ not cross-version proof, it's not smart and it's simply not necessary.

 

Mylenium

Translate
Participant
Jun 25, 2023 8:19 AM UTC

ah okay. thank you for the answer

Translate