Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Forums Adobe After Effects Expressions ExtendScript: Changing a value that I can’t believe is read-only

  • ExtendScript: Changing a value that I can’t believe is read-only

  • Michael Müller

    November 27, 2019 at 12:26 pm

    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 &lt;= 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 &lt;= 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 &lt;= 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 &lt; 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());

    }

  • Oleg Pirogov

    November 27, 2019 at 1:28 pm

    Would you please specify the structure of the Shape Layer you run this on. Cause it works just fine for me and I can’t recreate the error.

  • Michael Müller

    November 27, 2019 at 1:56 pm

    I made the mistake of trying to change the value by just typing in offset.value = 20 instead of offset.setValue(20). Perfect reply, now I know exactly how to continue. Dan gave me a perfect answer in the Adobe forum, where I asked the question as well.

    Thanks a bunch!

    Thread closed

Viewing 1 - 3 of 3 posts

Log in to reply.

We use anonymous cookies to give you the best experience we can.
Our Privacy policy | GDPR Policy