ADOBE AFTER EFFECTS: Forum Expressions Tutorials Creative Cloud

Select property only in certain property groups

COW Forums : Adobe After Effects Expressions

<< PREVIOUS   •   FAQ   •   VIEW ALL   •   PRINT   •   NEXT >>
Florian Zeiler
Select property only in certain property groups
on Mar 20, 2018 at 10:04:38 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 &lt;= 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 &lt; numLayer.length; i++) {
scanPropGroupProperties(numLayer[i]);
}

}

app.endUndoGroup();
}


Return to posts index

Steve Sierra
Re: Select property only in certain property groups
on Mar 20, 2018 at 11:06:02 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 "===" ? ;)


Return to posts index

Andrei Popa
Re: Select property only in certain property groups
on Mar 21, 2018 at 9:36:42 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.


Return to posts index


Florian Zeiler
Re: Select property only in certain property groups
on Mar 21, 2018 at 9:49:58 am

@Steve

Thank you so much, that worked perfectly ☺


Return to posts index

Steve Sierra
Re: Select property only in certain property groups
on Mar 21, 2018 at 11:44:53 am

Thanks for the explanation Andrei ! Could come in handy some time...
Good luck with your project Florian ;)


Return to posts index

<< PREVIOUS   •   VIEW ALL   •   PRINT   •   NEXT >>
© 2018 CreativeCOW.net All Rights Reserved
[TOP]