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

AE ExtendScript error setting stroke color

Community Beginner ,
Dec 02, 2021 Dec 02, 2021

Hello, very very new to ExtendScript, so I apologize if code looks weird.

 

I have this script where it does the following:

 

  1. Checks if comp is made, if not, make one called "test comp" (this works)
  2. Asks user to name the layer. Checks if user cancels or if layer name already exists. If it exists with same name, delete it, otherwise save the user submitted name. (this works)
  3. After layer with user (or default name) is created.
       a) Make a shape layer with saved name
       b) Make group name "My Shape"
       c) Add a Polystar vector shape
       d) Set polystar from STAR to POLYGON
       e) Change polygon points to 6
       f) Rotate the group 30 degrees
       g) Add a stroke property
       h) Set Stroke property to 10
       i) Add a fill property
       j) Set fill color to white
       (All of this works)
  4. Ask user if this is going to be a guide layer
       a) If TRUE, set guideLayer to true, set parent layer opacity to 35, Set stroke color to red
       b) If FALSE, set guideLayer to false, keep parent layer opacity to 100, set stroke color to green
       (this is where I get the error)

 

Everytime I set the stroke within the guideLayer IF statement, I get the error in the attached screenshot. But the exact same strokeGroup line in the initial IF statement works like a charm. I don't get it, what am I doing wrong? I've acttached the script as a TXT file so you can see the entire script.

 

I bet there's a better way of going about this, like maybe asking if this is a guide layer before everything, and just save the color value, and just call it in the setValue; but I'm really curious why this doesn't work.

 

Thank you!

 

//set project values and set a layer name to test2

var project = app.project;
var comp = project.activeItem;
var lName = "test 3"
var sGroup, pathGroup, myShape, strokeGroup, fillGroup, polyName, isGuideLayer;

//if there's no comp, create one standard 1080p, compname="test comp" make a new shapLayer and name it test.

polyName = prompt("Name this poly");


if (comp == null){
    comp = project.items.addComp("test comp", 1920, 1080, 1, 10, 30);
    
    $.write("new comp added");


}  else {
   
}

//open new comp in viewer
comp.openInViewer();


//This add's a standard group in the shape layer, and naming it "My shape"

function delLayer(layerName){
    comp.layer(layerName).remove();
    $.writeln("deleted - delLayer");
}

function makePoly(){
    
    

    if(polyName == null || polyName == ""){
        lName = "test poly";
        //shape layer does not exist
        if (comp.layer("test poly") != null){
            //if user cancels prompt, remove test poly if it exists
            delLayer("test poly");
        } else {
            $.writeln("test poly doesn't exist");
        }
    } else {
        
        //if user prompt matches a layer that already exists, delete it. Otherwise set lName iwth user submitted name
        lName = polyName
        if(comp.layer(lName) != null){
            //the layer exists BE GONE!
            delLayer(lName);
            
        } else {
            $.writeln("Name doesn't exist. User made layer "+lName+".")
        }
        
    }

    if (comp.layer(lName) == null){
        sLayer = comp.layers.addShape();
        sLayer.name = lName;
        sGroup = comp.layer(lName).property("Contents").addProperty("ADBE Vector Group"); //make a group name
        sGroup.name = "My Shape"; //set Group name
        pathGroup = comp.layer(lName).property("Contents").property("My Shape").property("Contents").addProperty("ADBE Vector Shape - Star") //add Polystar shape
    
        pathGroup.property("Type").setValue(2); // and set the TYPE to POLYGON
        pathGroup.property("Points").setValue(6); //set POLYGON count to 6
        sGroup.property("Transform").property("Rotation").setValue(30) //rotate 30 degrees
    
       strokeGroup = comp.layer(lName).property("Contents").property("My Shape").property("Contents").addProperty("ADBE Vector Graphic - Stroke"); //add stroke
       //strokeGroup.property("Color").setValue([0.42,0.75,0.29]) //stroke color RGB to float point values ugh!
      
       strokeGroup.property("Stroke Width").setValue(10)
    
       fillGroup = comp.layer(lName).property("Contents").property("My Shape").property("Contents").addProperty("ADBE Vector Graphic - Fill")//add fill
       fillGroup.property("Color").setValue([1,1,1])//fill color white
    }

    if(confirm("Make guide layer?")){
        
        comp.layer(lName).guideLayer = true; //if selected yes, make guide layer
        comp.layer(lName).property("Opacity").setValue(35); //set transparency to 35
        strokeGroup.property("Color").setValue([0.89,0.14,0.1]); //set color to Cisco RED
        //THIS IS WHERE I GET THE ERROR
    } else {
        //user selected no for guide layer
        strokeGroup.property("Color").setValue([0.42,0.75,0.29]); //set color to Cisco Green
        //THIS IS WHERE I GET THE ERROR
    }
    $.writeln("New Shape layer "+lName+" is now created. Guide layer created="+comp.layer(lName).guideLayer);

}

makePoly();

$.writeln("end script");






//fillGroup fills the gorup with a color
//var fillGroup = comp.layer("test2").property("Contents").property("My Shape").property("Contents").addProperty("ADBE Vector Shape - Fill")


app.endUndoGroup;
TOPICS
Error or problem , Expressions , Scripting
855
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
LEGEND ,
Dec 02, 2021 Dec 02, 2021
LATEST

Outside the initial creation of the layer you lose the context of which layer you're actually on. You would need to reference the layer again explicitly or simply nest the guide function inside your other function.

 

Mylenium

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