Photoshop: Ability to access "animationFrameDelay" and "animationLoopCount" via scripting

  • 1
  • Idea
  • Updated 2 years ago
  • (Edited)
At our company, we are using Photoshop to animate 2D sprites for video games. To export the files from Photoshop, we are using custom scripts. However, our programmers encounterted a couple of problems with some of the functionality here.

First of all, there does not seem to be a documented API for large portions of the animation segment of Photoshop. However, this is one of the most important parts for automation, since it is very time consuming to manipulate each frame manually.

We've encountered two similar problems here:

var id45 = charIDToTypeID( "setd" );
var desc21 = new ActionDescriptor();
var id46 = charIDToTypeID( "null" );
var ref42 = new ActionReference();
var id47 = stringIDToTypeID( "animationFrameClass" );
var id48 = charIDToTypeID( "Ordn" );
var id49 = charIDToTypeID( "Trgt" );
ref42.putEnumerated( id47, id48, id49 );
desc21.putReference( id46, ref42 );
var id50 = charIDToTypeID( "T " );
var desc22 = new ActionDescriptor();
var id51 = stringIDToTypeID( "animationFrameDelay" );
desc22.putDouble( id51, 10.000000 );
var id52 = stringIDToTypeID( "animationFrameClass" );
desc21.putObject( id50, id52, desc22 );
executeAction( id45, desc21, DialogModes.NO );

In this example, the frame exposure is set to 10.0. However, the reference of "animationFrameClass" is zero, which means this value can only be read but not written.

The second example is this:

var idsetd = charIDToTypeID( "setd" );
var desc2 = new ActionDescriptor();
var idnull = charIDToTypeID( "null" );
var ref1 = new ActionReference();
var idanimationClass = stringIDToTypeID( "animationClass" );
var idOrdn = charIDToTypeID( "Ordn" );
var idTrgt = charIDToTypeID( "Trgt" );
ref1.putEnumerated( idanimationClass, idOrdn, idTrgt );
desc2.putReference( idnull, ref1 );
var idT = charIDToTypeID( "T " );
var desc3 = new ActionDescriptor();
var idanimationLoopCount = stringIDToTypeID( "animationLoopCount" );
desc3.putInteger( idanimationLoopCount, 6 );
var idanimationClass = stringIDToTypeID( "animationClass" );
desc2.putObject( idT, idanimationClass, desc3 );
executeAction( idsetd, desc2, DialogModes.NO );

Here we are trying to set the loop count to 6 and we encounter a similar problem as described above.

Thank you!
Photo of Hannes Drexl

Hannes Drexl

  • 7 Posts
  • 0 Reply Likes

Posted 4 years ago

  • 1
Photo of Jeffrey Tranberry

Jeffrey Tranberry, Sr. Product Manager, Digital Imaging

  • 14614 Posts
  • 1944 Reply Likes
What version of Photoshop are you running? What OS/version are you on?
Photo of Eric Ching

Eric Ching, Employee

  • 87 Posts
  • 48 Reply Likes
Hi Hannes,

I ran the code snippets you provided and they worked. I did have to change the charIDToTypeID( "T " ) in each sample to charIDToTypeID( "T " ); Note the charID's are four characters in length. After making that change I was able to set both the frame delay and loop count.

Could you see if that resolves your problem? If it doesn't could you provide a sample script and sample file that reproduces the problem (and provide the Photoshop version and OS/version as requested)?

Thanks,
Eric
Photo of Eric Ching

Eric Ching, Employee

  • 87 Posts
  • 48 Reply Likes
It appears the forum removes spaces in posts, so the change I mentioned probably isn't the issue you are seeing. Please provide the Photoshop version and sample files, if possible.

Thanks,
Eric
Photo of Michael Schießl

Michael Schießl

  • 1 Post
  • 0 Reply Likes
Hi Eric, Hi Jeffrey,

There's a small mistake in Hannes's question. What we're trying to do is read those values ("animationFrameDelay" and "animationLoopCount"). Setting them through code recorded with the ScriptingListener works fine but I have found no way of reading them.

Is there any way (either through the public API or through ScriptingListener code) to do that?

We are using Photoshop CC 2014.2.1 (20141014.r.257 x64) on Windows 7
Photo of Jeffrey Tranberry

Jeffrey Tranberry, Sr. Product Manager, Digital Imaging

  • 14614 Posts
  • 1944 Reply Likes
Thanks. I've updated the topic. We'll look at adding this to the DOM. It's not currently possible.
Photo of Michael Stockwell

Michael Stockwell

  • 1 Post
  • 0 Reply Likes
I have a need to get the animation loop count and type (once, 3 times, forever, etc) as well.  This thread is 3 years old, any chance this has this been added to the DOM yet?

Edit: I got a working solution here:
https://forums.adobe.com/message/9530838#2318910
(Edited)