2 Replies Latest reply on Jul 17, 2015 7:52 AM by c.pfaffenbichler

    Set animation frame duration with scripting

    Ghoulfool Level 1

      From within PS, I want to be able to create animation frames from layers and then set the frame duration (frame delay)

       

      This is what I have so far:

      var frametime = 1.0 // 1 sec /frame
      
      // create animation frames
      createAnimationFromLayers();
      
      // set frame timing
      setFrameDuration(frameTime);
      
      function createAnimationFromLayers()
      {
        // =======================================================
        var id9070 = stringIDToTypeID( "animationFramesFromLayers" );
        var desc1033 = new ActionDescriptor();
        executeAction( id9070, desc1033, DialogModes.NO );
      }
      
      function selectAllFrames()
      {
        // =======================================================
        var id3 = stringIDToTypeID( "animationSelectAll" );
        var desc2 = new ActionDescriptor();
        executeAction( id3, desc2, DialogModes.NO );
      }
      
      function setFrameDuration(num)
      {
        selectAllFrames()
        // =======================================================
        var id4 = charIDToTypeID( "setd" );
        var desc3 = new ActionDescriptor();
        var id5 = charIDToTypeID( "null" );
        var ref1 = new ActionReference();
        var id6 = stringIDToTypeID( "animationFrameClass" );
        var id7 = charIDToTypeID( "Ordn" );
        var id8 = charIDToTypeID( "Trgt" );
        ref1.putEnumerated( id6, id7, id8 );
        desc3.putReference( id5, ref1 );
        var id9 = charIDToTypeID( "T   " );
        var desc4 = new ActionDescriptor();
        var id10 = stringIDToTypeID( "animationFrameDelay" );
        desc4.putDouble( id10, num ); //num (duration in seconds)
        var id11 = stringIDToTypeID( "animationFrameClass" );
        desc3.putObject( id9, id11, desc4 );
        executeAction( id4, desc3, DialogModes.NO );
      }
      

       

      What I want to know is this

      - How can you open the animation window in scripting ( as it script will fail with it closed) - might have to add a try/catch for it otherwise

      - Is it possible to loop over the animation frames like this: (I don't know the syntax I'm guessing)

       

      for (var i = 0; i < numOFrames; i++)
      {
          app.activeDocument.animation.frames = 1.0;
      }
      
        • 1. Re: Set animation frame duration with scripting
          c.pfaffenbichler Level 9
          - How can you open the animation window in scripting ( as it script will fail with it closed) - might have to add a try/catch for it otherwise

          Is the important thing not that "Create Frame Animation" has been performed rather than for the Timeline Panel to be open?

          1 person found this helpful
          • 2. Re: Set animation frame duration with scripting
            c.pfaffenbichler Level 9

            - Is it possible to loop over the animation frames like this: (I don't know the syntax I'm guessing)

              1 for (var i = 0; i < numOFrames; i++) 

              2 { 

              3     app.activeDocument.animation.frames = 1.0; 

              4 } 

            What do you want to accomplish by this?

            Select or determine a frame – then what?

            This would select the second frame and set it to 0,1s :

            // =======================================================

            var idslct = charIDToTypeID( "slct" );

                var desc2 = new ActionDescriptor();

                var idnull = charIDToTypeID( "null" );

                    var ref1 = new ActionReference();

                    var idanimationFrameClass = stringIDToTypeID( "animationFrameClass" );

                    ref1.putIndex( idanimationFrameClass, 2 );

                desc2.putReference( idnull, ref1 );

            executeAction( idslct, desc2, DialogModes.NO );

            // =======================================================

            var idsetd = charIDToTypeID( "setd" );

                var desc3 = new ActionDescriptor();

                var idnull = charIDToTypeID( "null" );

                    var ref2 = new ActionReference();

                    var idanimationFrameClass = stringIDToTypeID( "animationFrameClass" );

                    var idOrdn = charIDToTypeID( "Ordn" );

                    var idTrgt = charIDToTypeID( "Trgt" );

                    ref2.putEnumerated( idanimationFrameClass, idOrdn, idTrgt );

                desc3.putReference( idnull, ref2 );

                var idT = charIDToTypeID( "T   " );

                    var desc4 = new ActionDescriptor();

                    var idanimationFrameDelay = stringIDToTypeID( "animationFrameDelay" );

                    desc4.putDouble( idanimationFrameDelay, 0.100000 );

                var idanimationFrameClass = stringIDToTypeID( "animationFrameClass" );

                desc3.putObject( idT, idanimationFrameClass, desc4 );

            executeAction( idsetd, desc3, DialogModes.NO );

             

            Does this have any relevance for your undertaking?

            adobe script for rotation and position

            1 person found this helpful