• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Add keyframe to all path shape

Community Beginner ,
Mar 22, 2018 Mar 22, 2018

Copy link to clipboard

Copied

Hi Everyone,

I'm new in scripting but I try to write a simple script for adding a keyframe on every path of shape layer, i succeed with a part of that:

var myLayers = app.project.activeItem.selectedLayers;

var myLayer;

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

  myLayer = myLayers;

  if (myLayer instanceof ShapeLayer){

    var myContents = myLayer.property("ADBE Root Vectors Group");

    for (var j = 1; j <= myContents.numProperties; j++){

      myContents.property(j).property("ADBE Vectors Group").property("ADBE Vector Shape - Group").property("ADBE Vector Shape").addKey(1);

    }

  }

}

but i have difficult if there is a lot of "Vector Shape" on "Shape - Group" it doesn't work.

key path.PNG

Do you have an idea how to do it ?

Thanks a lot

TOPICS
Scripting

Views

2.3K

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Advocate , Mar 28, 2018 Mar 28, 2018

You will need a recursive function to make this happen. Here's a simple version of it.

Basically it loops through all layer properties and checks if it's ADBE Vector Shape property. If it is, it stores it in the array. Once all properties have been checked it returns array with all ADBE Vector Shape properties it found along the way.

Now, since we get properties that we need in shapeProperties array, we can perform additional loop add add keyframes to them.

(function() {

    // Get active compositio

...

Votes

Translate

Translate
Community Beginner ,
Mar 23, 2018 Mar 23, 2018

Copy link to clipboard

Copied

This seems fine to me, I just tested it and it works.

Maybe you have a problem with shapes (like circle or rectangle) and the shapes that have a path).

If you want to answer in french, you can

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Mar 23, 2018 Mar 23, 2018

Copy link to clipboard

Copied

Thanks for your answer,

Merci ^^ en fait comme sur l'image que j'ai posté le script marche mais quand on a plusieurs tracé dans une forme, il ne check pas tous les tracés et du coup ne met des clés que au premier tracé. Du coup j'arrive pas à mettre 2 conditions for (var j = 1; j <= myContents.numProperties; j++){ 

une pour les premiers groupe et une pour le groupe de tracé, tu aurais une idée ?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advocate ,
Mar 23, 2018 Mar 23, 2018

Copy link to clipboard

Copied

Guys, please keep posts in English. It's a community forum, so not everyone understands French. Please keep it in English.

Thank you.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Mar 23, 2018 Mar 23, 2018

Copy link to clipboard

Copied

Yes, sorry, sometimes it's hard to explain ourselves in another language, especially for such precise parts

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Mar 23, 2018 Mar 23, 2018

Copy link to clipboard

Copied

Maybe you can try this way :

Use this post to go deep in your shape layer

My script for discovering the names of AE properties

Then after that you can use a switch to list all cases you'll encounter : rectangle, ellipse, star, etc...)

If i have time this week-end i'll try something

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Mar 23, 2018 Mar 23, 2018

Copy link to clipboard

Copied

Thanks guys,

Sorry for french but I have not say something else i mention in my first post. Just for comprehension with a french camarade ^^.

GCTOIS thanks a lot i will go to see your link, if I can get what i need.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advocate ,
Mar 28, 2018 Mar 28, 2018

Copy link to clipboard

Copied

You will need a recursive function to make this happen. Here's a simple version of it.

Basically it loops through all layer properties and checks if it's ADBE Vector Shape property. If it is, it stores it in the array. Once all properties have been checked it returns array with all ADBE Vector Shape properties it found along the way.

Now, since we get properties that we need in shapeProperties array, we can perform additional loop add add keyframes to them.

(function() {

    // Get active composition;

    var composition = app.project.activeItem;

    if (!composition || !(composition instanceof CompItem))

        return alert("Please select composition first");

    // Get selected Layers

    var selectedLayers = composition.selectedLayers;

    if (selectedLayers.length === 0) {

        return alert("Please select some layers");

    }

    app.beginUndoGroup("Add Keyframes");

    var layer, shapeProperties;

    // For each selected layer

    for (var i = 0, il = selectedLayers.length; i < il; i++) {

        layer = selectedLayers;

      

        // Get "ADBE Vector Shape" properties

        shapeProperties = getProperties(layer, "ADBE Vector Shape");

        // Loop through all "ADBE Vector Shape" properties and do your magic

        for (var j = 0, jl = shapeProperties.length; j < jl; j++) {

            shapeProperties.addKey(1);

        }

    }

    app.endUndoGroup();

    // Recursive function to find properties by matchName

    function getProperties(currentProperty, propertyMatchName, propsArray) {

        propsArray = propsArray || [];

        for (var i = 1, il = currentProperty.numProperties; i <= il; i++) {

            if (currentProperty.property(i).matchName === propertyMatchName) {

                propsArray.push(currentProperty.property(i));

            }

            getProperties(currentProperty.property(i), propertyMatchName, propsArray);

        }

        return propsArray;

    }

})();

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Mar 29, 2018 Mar 29, 2018

Copy link to clipboard

Copied

LATEST

Thank you for all Tomas and for all your alerts you put in expression, It's more professional than I can do.

And I have a question too, if you put all Keys create into an array1 and put this keys(array1) SetValueAtTime 0 in another shape with same number of Vector Shape for doing a morphing between a shape and the first one, can I use your base of code for doing it ?

I say that because i'm trying to morph two txt layer with the same letter but with a different font weight with a script.

example : A(regular) morph to A(bold)

I have already try it but i just succeed to put one keyframe(At time 1) of the array to the second shape keys(at time 0) but my code puts just one key of the Array.

I use setValueAtTime(1, array[0]), I think I have to identify the index of my array and the index of my second Layer Shapes property and match them like setValueAtTime(1, array[array index = shape property index])... I don't know if it's the good way ?

I am clear in my question ?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines