Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions shape layers: keep stroke width inside a scaled group?

  • shape layers: keep stroke width inside a scaled group?

    Posted by Santi Agustí on June 1, 2016 at 8:39 pm

    Hi! I’m getting mad with this close-to-but-always-getting-errors workaround…
    I have a shape layer with 4 lines (one group each, with its own stroke, and trim paths) so the 4 are: right, left (both vertical) and top, bottom (both horizontal), and as they are crossing themselves they create a square/rectangle.
    The 4 lines are inside a group, called “lines”. And on its scale I added this expression:

    l=effect("selected")("Layer")
    w=l.sourceRectAtTime().width;
    h =l.sourceRectAtTime().height;
    [w,h]

    so it wraps whatever selected layer I want. And with the trim paths, it makes an animated outlined effect to create a mini grid.

    The problem is, as the group is being scaled, the strokes got awfully scaled too…
    I’m using this expression to keep its consistency, but I don’t know how to change it to make it keep its scale also when the group they are in is re-scaled..

    var zCorrect;
    try{
    var cam = thisComp.activeCamera;
    var camWS = cam.toWorld(cam.transform.pointOfInterest);
    zCorrect = -1*(fromWorld(camWS)[2] - position[2])/cam.cameraOption.zoom;
    }
    catch(err){
    zCorrect = 1;
    }
    var w = thisComp.layer("control").effect("line width")("Slider");
    var newScale = trueScale(thisLayer,scale[1]);
    val = w*zCorrect*100/newScale

    function trueScale(layer,sc){
    if(layer.hasParent){
    return trueScale(layer.parent,sc*=(layer.parent.scale[0]/100));
    }
    else{
    return sc;
    }
    }

    is that doable?
    (or maybe another workaround for the thing?)

    thanks!

    Santi Agustí replied 9 years, 11 months ago 1 Member · 1 Reply
  • 1 Reply
  • Santi Agustí

    June 2, 2016 at 11:37 pm

    ok! fyi this small edit on the awesome Nik Ska expression did the trick !

    this is for the vertical lines:

    var zCorrect;
    try{
    var cam = thisComp.activeCamera;
    var camWS = cam.toWorld(cam.transform.pointOfInterest);
    zCorrect = -1*(fromWorld(camWS)[2] - position[2])/cam.cameraOption.zoom;
    }
    catch(err){
    zCorrect = 1;
    }
    var w = thisComp.layer("control").effect("line width")("Slider");
    var newScale = trueScale(thisLayer,scale[1]);
    var s = content("cuad").transform.scale[1];
    scaleFactor = 100/s;
    val = w*zCorrect*100/s
    function trueScale(layer,sc){
    if(layer.hasParent){
    return trueScale(layer.parent,sc*=(layer.parent.scale[0]/100));
    }
    else{
    return sc;
    }
    }

    And for the horizontal just changing the

    var newScale = trueScale(thisLayer,scale[1]);
    var s = content("cuad").transform.scale[1];

    to

    var newScale = trueScale(thisLayer,scale[0]);
    var s = content("cuad").transform.scale[0];

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