Copy link to clipboard
Copied
Hello, very very new to ExtendScript, so I apologize if code looks weird.
I have this script where it does the following:
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;
Copy link to clipboard
Copied
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