Copy link to clipboard
Copied
Is it possible to know if a light/layer is a duplicate of another one?
My plugin creates some connections to lights, and I want to replicate this connections if a light is duplicated. However, I can't find a way to distinguish between a new light and a duplicate.
1 Correct answer
Thanks for the answer Shachar.
So, I narrowed my issue to lights only. I only need to detect if a light is a duplicate.
I cannot rely on the naming because if I have 2 lights with their default name, and try to duplicate the first one, I'll get a numerical increment on the second, not the first. Also, duplicated or not, the naming number increments sequentially.
I've been thinking about this for a while, and I think I have a solution. Lights have a unique ID, and if I manage to save this ID into so
...Copy link to clipboard
Copied
meh. kind of.
1. you can parse the liyer name immediately after duplication. it should be
a numerical increment over the original name.
2. if an effect of yours is applied to that layer you can store some GUID
in sequence data during SEQUENCE_SETUP. that call only happens one per
instance, so if 2 instances carry the same GUID one must be a duplicate.
the you can deduce the original from the duplicate by tracking the "last
known location" of each instance during most calls. (i.e. effect index,
layer ID, comp item ID)
that's all i got...
Copy link to clipboard
Copied
Thanks for the answer Shachar.
So, I narrowed my issue to lights only. I only need to detect if a light is a duplicate.
I cannot rely on the naming because if I have 2 lights with their default name, and try to duplicate the first one, I'll get a numerical increment on the second, not the first. Also, duplicated or not, the naming number increments sequentially.
I've been thinking about this for a while, and I think I have a solution. Lights have a unique ID, and if I manage to save this ID into some property of the light, once the light is duplicated, this property will also be duplicated and I can look into in on the new light and figure out the original ID of the original light!!
This is all good, except for the fact that lights can't hold any user property. At least I don't know how. So my idea is to store this ID in the alpha channel of the color (since it's not actually used). I need to check it periodically though since I suspect changing the color of the light also resets the alpha channel.
I'm going to try this now and see how it goes.
Copy link to clipboard
Copied
holy c7ap! nice thinking!
i'm not familiar with the unique light id. how can it be acquired? in your
solution, i dear the case where the user changes the color value of the
light and the stored id in the alpha channel is lost.
Copy link to clipboard
Copied
You can get the ID with the function AEGP_GetLayerID.
And you are right about the change of the color, however, since my plugin is forcibly asynchronous, and I use the IdleHook to sync everything, I'm safe on the color change. This is because once I read the lights to update them in my plugin, I can check if the alpha is less or equal to 1.0, meaning it was reset or it's a new light. In this case I update the alpha with the light ID.
This is a major workaround, but if it works, I'm fine with it
Copy link to clipboard
Copied
oh maaaaaan, i'm such an idiot for having forgotten about the layerID! it's
indeed unique, and a duplicate would have a different one from the original.
in the words of yoda in Revenge of the sith, "into exite, i must go".
Copy link to clipboard
Copied
Well, it worked!
Indeed changing the color, resets the alpha to 1.0, but not actually a problem in my case.
Thanks again Shachar, I'll mark my workaround as the correct answer.
Copy link to clipboard
Copied
horray!
Copy link to clipboard
Copied
Well... I spoke too soon...
It turns out AE has a small bug here. I'm writing the light ID into the alpha channel of the color. The problem is that all new lights will get the last alpha I wrote to one of them. It looks like the API is using an intermediate variable to store the color and is not changing/reseting the alpha whenever we read the color using the AEGP_GetLayerStreamValue function.
There it goes my ingenious solution...
EDIT: The problem solved itself by changing the color in the "new light" window 1 time. I haven't been able to replicate it again unfortunately...
Copy link to clipboard
Copied
aw... bummer.
Copy link to clipboard
Copied
Hi,
bumping into the discussion here, I love interrupting ;-)...
Since you have an Idlehook, why don't you check your lights and see if light's alpha = light's ID?
Cos' even if the alpha is "duplicated", the ID isn't...
Cheers,
François
Copy link to clipboard
Copied
yo francois! good to hear from you!
On Fri, Apr 5, 2019 at 12:48 PM françois leroy <forums_noreply@adobe.com>
Copy link to clipboard
Copied
https://forums.adobe.com/people/fran%C3%A7ois+leroy wrote
Hi,
bumping into the discussion here, I love interrupting ;-)...
Since you have an Idlehook, why don't you check your lights and see if light's alpha = light's ID?
Cos' even if the alpha is "duplicated", the ID isn't...
Cheers,
François
Not sure I understand what you are trying to say, but I think you are explaining exactly my original idea. I save the light ID to the alpha, and once this light is duplicated, the duplicate will have a new ID and the same alpha as the original. And this is how I detect if a light is a duplicate or not.
The new problem I got was that new lights (not duplicates) have as alpha, an ID from another light in the scene. I would expect new light to have alpha as 1.0.
Copy link to clipboard
Copied
You're right, I missed the point here...
Did you try to add a CommandHook, to see if different cmd is triggered when duplicating / creating lights?
If the cmd is different, it'll be easy to fix.
Otherwise, there is a possible workaround, but I don't know if it fits your needs:
the lights used by your plugin could be parented (to the layer using the effect, or to a 3D null that you create) or even have a "pseudo parenting", like an expression linking a property (your color alpha?) to your main layer. Then, duplicates will keep the link, while newly created lights won't...
Hope it helps this time 😉
François
ps: Hi Shachar! Long time no see 🙂
Copy link to clipboard
Copied
Great, thanks for the ideas.
I've been wondering about CommandHooks:
- are those reliable?
- are they immediately called once we do the corresponding action in AE?
Copy link to clipboard
Copied
As far as I've used them, they're reliable...
And yes, they're called immediately. When you receive them, you can even choose to work before or after AE does.
Copy link to clipboard
Copied
there are some blind spots in their reliability. for instance, some
commands are sent to the hook command when activated by clicking in a menu,
but not so when using keyboard shortcuts. you'll just have to experiment
and see.

