ADOBE AFTER EFFECTS: Forum Expressions Tutorials Creative Cloud

scripting: fill color same as layer label color?

COW Forums : Adobe After Effects Expressions

<< PREVIOUS   •   FAQ   •   VIEW ALL   •   PRINT   •   NEXT >>
Santi Agustí
scripting: fill color same as layer label color?
on Dec 31, 2018 at 12:53:56 am

Hi!
Do you know if is it possible (via scripting) to make the color of a fill effect, be the same as the layer's label color?

I guess it's not possible without retrieving the actual rgb label colors from the prefs, as said here: https://forums.creativecow.net/docs/forums/post.php?forumid=227&postid=3644...

but maybe there is an easiest way?

thanks!


Return to posts index

Scott McGee
Re: scripting: fill color same as layer label color?
on Jan 2, 2019 at 9:03:10 am

I think I've copied and pasted all that you need.

Essentially, I create an array of colours I want, then create all my buttons using the fillBrush. Then use the array to array through my buttons to match the same colour of the array.

Hopefully the below makes sense, because I still struggle to understand it with the Array bouncing out of other arrays, it took a few days of attempting this for me to get it to work.

var pcolor = new Array([0/255,68/255,137/255,255/255],[255/255,255/255,255/255,255/255])

var b = new Array();
for(var i = 0; i <= 1 ; i++ ){
b[i] = groupOne.add ('iconbutton', undefined, undefined, {name:'Blue', style: 'toolbutton'});
b[i].size = [30,20];
b[i].fillBrush = b[i].graphics.newBrush(b[i].graphics.BrushType.SOLID_COLOR,pcolor[i]);
b[i].onDraw = customDraw;
function customDraw()
{ with( this ) {
graphics.drawOSControl();
graphics.rectPath(0,0,size[0],size[1]);
graphics.fillPath(fillBrush);
if( text ) graphics.drawString(text,textPen,(size[0]-graphics.measureString (text,graphics.font,size[0])[0])/2,3,graphics.font);
}}
}

for(var i = 0; i <= 1 ; i++ ){
b[i].onClick =
(function(i){
return function() {
app.beginUndoGroup("AddEffect");
var curItem = app.project.activeItem;
var selectedLayers = curItem.selectedLayers;

for (var j = 0; j < selectedLayers.length; j++) {

try {
curRem = selectedLayers[j].effect.property("Fill").remove();
curLayer = selectedLayers[j].Effects.addProperty("ADBE Fill")("Color").setValue(pcolor[i]);
}
catch (err) {
curLayer = selectedLayers[j].Effects.addProperty("ADBE Fill")("Color").setValue(pcolor[i]);
}
}

app.endUndoGroup();
}
})(i);
}


Return to posts index

Scott McGee
Re: scripting: fill color same as layer label color?
on Jan 2, 2019 at 9:05:11 am

I can guarantee that it work though. As I use it with my plugin.



Return to posts index


Santi Agustí
Re: scripting: fill color same as layer label color?
on Jan 3, 2019 at 4:23:51 am

wow! thanks for the sharing! it will be for sure super useful in a near future!

regarding the original question of the thread, I think I totally misexplained myself

I'm with a script to create a shape layer on each selected null, and I wanted to make its fill color be the same as the null label color, this way it will mimic the null color, so the question was more about if there was a way to get the actual 16 label colors stored on the preferences.

I'd use the default colors, but some people may have customized the original colors, so I was wondering if there is an easy way to get these colors from the label number without having to deal with the reading of the prefs file text stored and diving too deep.

So if you have a null layer with the lavender label color, the fill color of the new shape associated to that null would be the lavender hex #A9A9CA.

The user is always having the option of changing that initial shape layer color. I just thought that would be nice to mimic the null's color when the shape is created via the script.



But maybe I will end just having an array of the default label colors plus some other palettes and launch a base color from that, instead of the original idea .

anyway, thanks again!


Return to posts index

Scott McGee
Re: scripting: fill color same as layer label color?
on Jan 3, 2019 at 8:50:51 am

Ah Gotch ya,

well I did find this (below), which doesn't look promising. It states that there is no way to set them programmatically, which means that if someone has changed the colours themselves that would prove a problem with what you want to do. You can certainly get it to mimic with what I read, but I'd look at what I sent previous and create your own palette. That way you can guarantee the colour. I could be wrong as I'm not hugely confident in this area, as I'm always finding hacks when I want to.

MarkerValue.label

app.project.item(index).layer(index).property("Marker").keyValue(index).label

Description

The label color for a composition or layer marker. Colors are represented by their number (0 for None, or 1 to 16 for one of the preset colors in the Labels preferences). Custom label colors cannot be set programmatically.

Available in After Effects 16.0 or later.

Type

Integer (0 to 16); read/write.


Return to posts index

Santi Agustí
Re: scripting: fill color same as layer label color?
on Jan 3, 2019 at 1:36:36 pm

thanks Scott for your help!

I think I found a workaround here https://forums.adobe.com/thread/1354211
but at the same time, I was thinking on a plan B for that issue (also, maybe the user has a lot of nulls and want more color variety than only repeating 16 from the label color).

I think for now I will make the shape get a color from the defined palette as you suggested. I wanted to see how to make it work with hex values, just in case I can save nice color palettes as an array of hexadecimal values
so, from this starting post https://forums.creativecow.net/readpost/227/37767, I adapted it a bit to make it work with the array of desired colors. I added some hex values from the google material palette, and the original 16 label colors coming in AE, so now when I create a shape associated to a null, the base color of the shape will be a random color from that array.

just in case anyone is interested, there is the piece of code to read the color from an hexadecimal array and apply randomly to the created shape layer (applied to a pseudo effect)

function hexToColor(theHex){
var r = theHex >> 16;
var g = (theHex & 0x00ff00) >> 8;
var b = theHex & 0xff;
return [r/255,g/255,b/255,1];
}
var colors = ['#FFDE03', '#0336FF', '#FF0266', '#F44236', '#E91E63',
'#9C27B0', '#673AB7', '#3F51B5', '#2196F3', '#03A9F4',
'#00BCD4', '#009688', '#4CAF50', '#8BC34A', '#CDDC39',
'#FFEB3B', '#FFC107', '#FF9800', '#FF5722', '#9E9E9E',
'#607D8B', '#079D94', '#FFB31A', '#FFA301', '#FF77A8',
'#29ADFF', '#FF89B5', '#005784', '#2F484E', '#B2DCEF',
'#E666B3', '#33991A', '#B53838', '#E5BCC9', '#E4D84C',
'#A9CBC7', '#B3C7B3', '#B3C7B3', '#677DE0',
'#677DE0', '#4AA44C', '#8E2C9A', '#E8920D', '#7F452A',
'#F46DD6', '#3DA2A5', '#A89677', '#1E401E'];

var idx = Math.floor(Math.random()*colors.length);
colors[idx]
myHex = (parseInt(colors[idx].slice(1),16));
var color = hexToColor(myHex);
// here is where I apply this: myShape.property("ADBE Effect Parade").property("lashape").property("color").setValue(color);


Return to posts index

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