-
ExtendScript: Changing a value that I can’t believe is read-only
I must have missed something here.
Essentially, the script I’m working on is supposed to add “Offset Path” to a shape layer and change the “Amount” value depending on it’s stroke width. I’m getting an error, saying that this particular value is read-only and can’t be changed, which I’m having a hard time believing. Why would I not be able to change this value?
The error happens at line 77, which currently just shows the value of “Amount” in case there already is an “Offset Path”, which the script can already add. I would like to be able to change this Amount to something like 20 at first.
Thanks in advance for your help and time
Michael
var myComp = app.project.activeItem;
var myLayer = myComp.selectedLayers;//make sure a layer is selected
if (myLayer.length == 0) {
alert("Select a shape layer")
}try{
//Checks if shape layer has an enabled stroke
function hasStroke(){for (var i=0;i<myLayer.length;i++){
//Variable to access shape layer props
var contents = myLayer[i].property("ADBE Root Vectors Group");//
for(s = 1; s <= contents.numProperties; s++){
var shape = contents.property(s).property("Contents");
if(shape.property("ADBE Vector Graphic - Stroke").active == true){
return true
}else{
return false
}
}
}
}//Adds an offset Path
function addOffsetPath(){for (var i=0;i<myLayer.length;i++){
//Variable to access shape layer props
var contents = myLayer[i].property("ADBE Root Vectors Group");
var shape = contents.property(s).property("Contents");
shape.addProperty("ADBE Vector Filter - Offset")}
}//Checks if current shape layer already has an offset path
function hasOffsetPath(){for (var i=0;i<myLayer.length;i++){
//Variable to access shape layer props
var contents = myLayer[i].property("ADBE Root Vectors Group");//
for(s = 1; s <= contents.numProperties; s++){
var myFilter = "ADBE Vector Filter - Offset"
var shape = contents.property(s).property("Contents");
if(myFilter in shape){
return true
}else{
return false
}
}
}
}function changeOffsetValue(){
if (hasOffsetPath()) {
for (var i=0;i<myLayer.length;i++){//Variable to access shape layer props
var contents = myLayer[i].property("ADBE Root Vectors Group");//
for(s = 1; s <= contents.numProperties; s++){
var myFilter = "ADBE Vector Filter - Offset";
var shape = contents.property(s).property("Contents").property(myFilter);
var offset = shape.property(1);
alert(offset.value);}
}
}
}for(i = 0; i < myLayer.length; i++){
//Check if selection is a shape layer
if (myLayer[i] instanceof ShapeLayer) {
//If so, check if it has a stroke
if(hasStroke()) {
//If so, allow action
if(hasOffsetPath()) {
changeOffsetValue()
} else {
addOffsetPath()
}
} else {
("This shape doesn't have a stroke yet")
}
} else { alert("This is not a shape layer") }
}}catch(err){
alert("Error at line # " + err.line.toString() + "\r" + err.toString());}