Copy link to clipboard
Copied
How can expression to a layer comp that when have image in comp opacity 100 and when doesn't have any image in comp opacity 0?
Copy link to clipboard
Copied
You can't. Expressions cannot check whether there is content in a sub-comp or not. Only scripts can do that. Whwtever you want will require a different approach like always having a layer in the pre-comp and checking its visibility state with isActive() or similar.
Mylenium
Copy link to clipboard
Copied
var img = false;
for (var i = 1; i <= thisComp.numLayers; i++) {
var layer = thisComp.layer(i);
if (layer.name.match(/\.(jpg|jpeg|png|bmp|gif|tiff|tga|psd|eps|ai|dpx)$/i)) {
img = true;
break;
}
}
img * 100;
Copy link to clipboard
Copied
At worst, you can check if the name of a layer in the composition contains an image extension, and in that case,return 100 or 0.
Won't work if you rename stuff, though, whether that's the layer or source item...
Mylenium
Copy link to clipboard
Copied
If he wants to rename his images, he can add the prefix IMG and modify the expression like this:
var img = false;
for (var i = 1; i <= thisComp.numLayers; i++) {
var layer = thisComp.layer(i);
if (layer.name.match(/^IMG/)) {
img = true;
break;
}
}
img * 100;
If he knows that he will use an expression that checks if the layer name contains an image extension,
it would be foolish to rename his image layers and then be surprised that the expression doesn’t work.
It’s just a matter of organization.
Copy link to clipboard
Copied
You would have to reference every layer in every comp. The calculations could be recursive, slowing things down a lot.
The only other option would be to put all of the other layers in a nested comp (pre-comp) and then do a point sample of the alpha channel to look for transparency in a specific area of the comp. A simple if/else statement would generate an opacity switch.
I can only offer those suggestions without a screenshot of your comps' structure and a detailed explanation of the design goals.
Find more inspiration, events, and resources on the new Adobe Community
Explore Now