Skip to main content
Participant
March 13, 2013
Question

Unique Layer IDs?

  • March 13, 2013
  • 4 replies
  • 4196 views

Project items like compositions, and folders have an ID attribute tied to them:

app.project.activeItem.id

Layers within a composition don't seem to have this attribute, but it there something similar,

and attribute that is completely unique to a layer?

I need to save data that references specified layer items.

Layer index won't work since it is a value that can be changed, and once a layer's index is changed

the layer is lost. Name won't work either because multiple layers can share the same name and can

also be changed.

This topic has been closed for replies.

4 replies

stib
Inspiring
August 29, 2016

I'm guessing it won't persist between sessions, but what about if you just add a GUID property to the AVLayer object? Isn't that how Javascript works - you seem to be able to just hot-glue properties and methods onto objects at will.

This works so far for me:

var myLayers = app.project.activeItem.selectedLayers;

for (var i=0; i<myLayers.length; i++){

  myLayers.GUID = "GUID_" + i; //obviously I have to explore creating a proper GUID

}

var moreLayers = app.project.activeItem.selectedLayers;

for (var i=0; i<myLayers.length; i++){

  writeln moreLayers.GUID;

}

tardigrade01
Inspiring
August 29, 2016

we ended up doing something similar to what Dan suggested and the generateRandomNumber function (and I can confirm that these values persist from session to session):

function createItemID(aeItem, dataModelItem){

    var wasLocked = false;

    if (aeItem.locked == true){

        wasLocked = true;

        aeItem.locked = false;

    }

    if (aeItem.comment == "" || aeItem.comment == "0"){

        aeItem.comment = generateRandomNumber();

    }

    if (wasLocked == true){

        aeItem.locked = true;

    }

    dataModelItem.id = aeItem.comment;

}

Legend
December 17, 2015

So there IS the getRenderGUID() method for layer objects. Not sure how many AE versions it appears in, but it is in AE CC 2014. It's not documented from what I can tell. Which means Adobe will not support it and may even remove it at any point, so you'll be gambling if you do use it.

It requires 1-2 parameters, not sure what exactly, but I used 1 and got a mixed serial number that seems to stick with the layer regardless of index position. I have not aggressively tested it or tried to see if it persists through app sessions, but might be worth a look.

layerObj.getRenderGUID(1);     //returns 45ede9dc-dbd5-52c8-6cf0-8b260000008f

saurabhs88911103
Participant
December 17, 2015

Dimn, Have you find any solution? I also stuck in same problem.   

Dan Ebberts
Community Expert
Community Expert
December 17, 2015

What I do is use the layer's comment field to store my unique ID. I guess it could be modified by the user, but usually it's not even visible, so that hasn't been an issue.

Dan

Inspiring
March 13, 2013

I don't think AVLayer Objects have an equivalent to an id. But their source is an AVItem which will have one. So layer.source.id will work.

Then again, several layers can share the same source, so this won't work straight away, but you can probably generate an id for a layer by concatenating these parameters:

- the comp's id,

- the layer's index,

- the layer's name,

- the layer's source.id.

I think this should make an individual id for your layer, and you can probably make it a bit more complex by adding the layer's color or stuff like that.

Is that what you were looking for?

Dimn7211Author
Participant
March 13, 2013

Generating an id for a layer would work but I can't find a way to make that new id a permanent attribute of the layer.

My script needs to be able to find the layer again based on this id when the project is closed and then opened. If

I add a new attribute like layer.customID, it is reset when the project is closed. I suppose I could tie the ID to a

marker comment or something but ideally I need an attribute that would only have the functionality of IDing the layer

and be locked so the user can't modify it in after effects.

Concatenating the above fields would have the same problem as using the index as the ID. If the user changes the order(index) of

the layers the ID will no longer match.

Inspiring
March 13, 2013

If the user changes the order(index) of the layers the ID will no longer match.

Alright, I wasn't sure what you wanted to do with the ID and if it had to work with the layers in another order.

Others might have a better solution but I guess it'd be pretty simple to store an id you choose for each layer in its comment (no need to overwrite the comment BTW, just add it to the beginning).

Then to find a layer you'll have to loop through all the comps and all their respective layers until you find the right ID.

Then again, this won't work if a layer is duplicated after the ID is stored, but I don't see any other way right now.