Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions Select property only in certain property groups

  • Select property only in certain property groups

    Posted by Florian Zeiler on March 20, 2018 at 10:04 am

    Dear Creative Cow People,

    i’m currently struggling to find a good solution for a little script i’m working on – it currently selects all color properties in the selected layer. I want to refine this script by only selecting the color property, if it is within a property group called “Stroke” (for example).

    I tried using “propGroup.name === ‘Stroke’ ” in the if condition, but it doesn’t seem to work – and furthermore, sometimes a shape layer will have several “Stroke” groups or ones that have numbers appended, such as “Stroke 1” or similar.

    What would be the best way to approach this?

    Thanks in advance – any help is greatly appreciated!

    Kind regards

    Florian

    {
    app.beginUndoGroup("Set Colors");

    var myComp = app.project.activeItem;
    var numLayer = myComp.selectedLayers;
    var colorExp = '(placeholder for color expression)';

    if (numLayer.length == 0) {
    alert("NO LAYERS SELECTED - Please select one or several Layers before running this script.", "Color");

    } else {

    function scanPropGroupProperties(propGroup) {
    var i, prop;

    // Iterate over the specified property group's properties
    for (i = 1; i <= propGroup.numProperties; i++) {
    prop = propGroup.property(i);
    if (prop.propertyType === PropertyType.PROPERTY && prop.name === 'Color' && propGroup.canSetEnabled) // Found a property
    {
    prop.expression = colorExp
    } else if ((prop.propertyType === PropertyType.INDEXED_GROUP) || (prop.propertyType === PropertyType.NAMED_GROUP)) {
    // Found an indexed or named group, so check its nested properties
    scanPropGroupProperties(prop);
    }
    }
    }

    for (var i = 0; i < numLayer.length; i++) {
    scanPropGroupProperties(numLayer[i]);
    }

    }

    app.endUndoGroup();
    }

    Steve Sierra replied 8 years, 1 month ago 3 Members · 4 Replies
  • 4 Replies
  • Steve Sierra

    March 20, 2018 at 11:06 am

    Hi,

    I’d use slice to get only the “stroke” part of the property name.

    it goes:
    prop.name.slice(the character you want to start slicing at , the character you want to finish slicing at);

    In your case, slice(0,6) I think…

    Hope this helps !
    By the way, what is the difference betxeen “==” and “===” ? 😉

  • Andrei Popa

    March 21, 2018 at 9:36 am

    @Steve
    a=1;
    b=”1″;
    c=1;
    d=true;

    a==b true
    a===b false

    a==c true
    a===c true

    a==d true
    a===d false

    So using the ===, the values must be identical. Same value and same type. == converts the values and then checks if they are equal

    Andrei
    My Envato portfolio.

  • Florian Zeiler

    March 21, 2018 at 9:49 am

    @Steve

    Thank you so much, that worked perfectly ☺

  • Steve Sierra

    March 21, 2018 at 11:44 am

    Thanks for the explanation Andrei ! Could come in handy some time…
    Good luck with your project Florian 😉

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