Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions Referencing a parent of a comp

  • Referencing a parent of a comp

    Posted by Brian Stewart on July 18, 2007 at 3:22 pm

    Hi,

    I’m still pretty new to After Effects, though not programming. I was creating an animation of a cube, where each side had a piece of text on it. I precomped the side and the text, and created 4 different precomps like this, one for each side. I wanted to use these precomps in a variety of other comps, and the transparency of the text on the various sides would change, depending on which parent comp it was placed in. I wanted to do this by creating a null object in the parent comp, naming it “Side1-Opacity”, adding a slider effect to it, and then referencing that slider in an expression for the transparency of the text in the included comp. This would essentially allow “parameters” to be passed to the precomps. The expression I wanted was:
    thisComp.parent.layer(“Side1-Opacity”).effect(“Slider Control”)(“Slider”)
    But evidently this is not possible. I read in another post that you can reference parent comps by name, and I have done this before, but it would defeat the “reuseability” of the precomps. I eventually solved it by pulling the sides, text, etc. out and putting them all into a single comp, and using parenting to do it. This was possibly the most elegant way to do this particular thing, but I know this will come up again, and was just wondering if there was some workaround out there for finding the parent of a comp.

    Thanks

    Brian

    Thomas Junk replied 16 years, 8 months ago 5 Members · 7 Replies
  • 7 Replies
  • Dan Ebberts

    July 18, 2007 at 4:04 pm

    No, not really. Here’s my understanding of the reason:

    Since a comp can appear as a precomp in any number of other comps, it can’t really have a parent. A nested comp is really an instance of a comp (not a copy), so any change to that comp affects all the instances wherever they appear. So you can’t have an instance of a comp that behaves differently than other instances.

    Dan

  • Darby Edelen

    July 18, 2007 at 6:14 pm

    [Brian Stewart] “thisComp.parent.layer(“Side1-Opacity”).effect(“Slider Control”)(“Slider”)”

    Unless I’m mistaken the ‘parent’ method literally returns the parent of the layer in the composition. When you put a pre-composition into a final composition, the final comp is not the parent of the pre-comp. The pre-comp simply exists within the final comp as another layer.

    thisComp.parent wouldn’t return anything because a composition cannot have a parent, unless it is used as a layer in another ‘final’ composition. Then only in that ‘final’ composition, where the pre-comp is treated as a layer, can a parent be assigned to the pre-comp.

    However, it’s still treated as a layer within the final composition and you would need to use thisLayer.parent instead of thisComp.parent (which would try to find the parent of the ‘final’ comp and fail).

    You can consider that a long ‘no way dude’ =)

    Darby Edelen
    DVD Menu Artist
    Left Coast Digital
    Aptos, CA

  • Brian Stewart

    July 18, 2007 at 6:31 pm

    [Darby Edelen] “Unless I’m mistaken the ‘parent’ method literally returns the parent of the layer in the composition”

    Yes, I figured that when the expression failed – I was just wondering if there was a work-around, so you and Dan have both answered my question…just not the answer I had hoped for…

    Dan’s comment about instancing makes sense – I guess if it was something I really needed badly I might could make an effect plug-in out of it? Obviously various layers can reference the same effect, but with different parameters being supplied to that effect by each layer. This is pretty much the kind of thing I was hoping to accomplish by referencing the parent of the comp.

    Thanks!

    Brian

  • Darby Edelen

    July 18, 2007 at 7:14 pm

    The only way I can think to do what you want is to use create a unique pre-comp for each final comp. If you name them identically but add “_pre” onto the end of the pre-comp then you can speed your work by using an expression that chops the “_pre” off the end of the pre-comp’s name to access the final comp:


    l = thisComp.name.length - 4; //subtract 4 (the length of '_pre') from the length of the thisComp's name
    finalName = thisComp.name.substring(0, l); //remove the last 4 letters from the thisComp's name
    comp(finalName).layer("Side1-Opacity").effect("Slider Control")("Slider")

    Darby Edelen
    DVD Menu Artist
    Left Coast Digital
    Aptos, CA

  • Johnny W

    April 29, 2009 at 2:11 pm

    Not exactly sure if this is what you need, or if you still need it.
    But I’m sure it will be of use for someone.

    Had a problem where I in precomps needed to get values from the main timeline where they recide.

    Wrote this script and it works for me (all precomps needs a unique name)

    Hope it helps (someone), peace.

    Script, in the precomp where you need to get value (recides in main timeline):

  • Johnny W

    April 29, 2009 at 2:13 pm

    Repost, seems the script got lost!

    Not exactly sure if this is what you need, or if you still need it.
    But I’m sure it will be of use for someone.

    Had a problem where I in precomps needed to get values from the main timeline where they recide.

    Wrote this script and it works for me (all precomps needs a unique name)

    Hope it helps (someone), peace.

    https://www.vex.se

    Script, in the precomp where you need to get value (recides in main timeline):
    ————————————————
    timeline_time = comp(“Main_Timeline”).layer( thisComp.name ).inPoint + time
    val = comp(“Main_Timeline”).layer(“Audio Keys”).effect(“Bass Keys”)(“Slider”);
    val.valueAtTime(timeline_time );

  • Thomas Junk

    December 6, 2009 at 11:31 am

    I reworked this a little: I needed layers to orient to a parent’s composition camera.
    This is what I got working with your help. Thank you!!

    „parent“ ist the name of the Composition containing the Camera called „CameraMain“

    delta = toWorld(anchorPoint) - comp("Parent").layer("CameraMain").toWorld([0,0,0]);
    radiansToDegrees(Math.atan2(delta[0],delta[2]))

    demodern | digital design studio
    Cologne, Germany

We use anonymous cookies to give you the best experience we can.
Our Privacy policy | GDPR Policy