Skip to main content
Participant
January 10, 2021
Answered

Which layers are visible on each frame?

  • January 10, 2021
  • 1 reply
  • 385 views

I'm using JavaScript to make Photoshop scripts and I've come across a problem. I'd like to merge visible layers across multiple frames so all layers that are visible on the same layer get merged.

So let's say I have a Photoshop document with 4 layers and 2 frames. Layer 1 and 2 are visible on the first frame, 3 and 4 are visible in the second frame. so I'd like to make a function that would merge layers 1 and 2, and also 3 and 4 together.

Is there a way to do this? Looking at the JavaScript reference and there's a shocking lack of any functions that will deal with frames.

This topic has been closed for replies.
Correct answer JJMack

Adobe Photoshop Scripting  DOM does not cover all of Photoshop Feature so you can not script many of Photoshop feature using DOM code. Often scripts need to use Action Manager code to script Photoshop features that the actions can be recorder for.  On Adobe's Web Site there is a Plug-in you can install in Photoshop  "Scriptlistener"  when installed  it will record two log on your desktop one is a javascript log the other a vbs log.  Every thing you do in Photoshop that can be recorded in an action will recorded in Action Manager code in these logs.  Like Actions the code will have Steps with hard coder step settings.  But you can change the setting into variables and create functions you can use in your scripts.    So it is easy to select a Frame Animation frame by  number with a function that uses Action Manager code,  If you know the layers  you want visible  in a particular frame,  Target the Frame by number then then use DOM code on Photoshop scripting layer objects and set the layers visibility. You do not actually merge layers you set the layers visibility the form the frame's composite  image. The code between{} is action manager code I changed the hard coded frame number to a variable frameNumber and create the function selectFrame.

 

 

 

function selectFrame(frameNumber) {  
   var idslct = charIDToTypeID( "slct" );
       var desc9 = new ActionDescriptor();
       var idnull = charIDToTypeID( "null" );
           var ref3 = new ActionReference();
           var idanimationFrameClass = stringIDToTypeID( "animationFrameClass" );
           ref3.putIndex( idanimationFrameClass, frameNumber );
       desc9.putReference( idnull, ref3 );
   executeAction( idslct, desc9, DialogModes.NO );
}


selectFrame(10)

 

 

 

 

1 reply

JJMack
Community Expert
JJMackCommunity ExpertCorrect answer
Community Expert
January 10, 2021

Adobe Photoshop Scripting  DOM does not cover all of Photoshop Feature so you can not script many of Photoshop feature using DOM code. Often scripts need to use Action Manager code to script Photoshop features that the actions can be recorder for.  On Adobe's Web Site there is a Plug-in you can install in Photoshop  "Scriptlistener"  when installed  it will record two log on your desktop one is a javascript log the other a vbs log.  Every thing you do in Photoshop that can be recorded in an action will recorded in Action Manager code in these logs.  Like Actions the code will have Steps with hard coder step settings.  But you can change the setting into variables and create functions you can use in your scripts.    So it is easy to select a Frame Animation frame by  number with a function that uses Action Manager code,  If you know the layers  you want visible  in a particular frame,  Target the Frame by number then then use DOM code on Photoshop scripting layer objects and set the layers visibility. You do not actually merge layers you set the layers visibility the form the frame's composite  image. The code between{} is action manager code I changed the hard coded frame number to a variable frameNumber and create the function selectFrame.

 

 

 

function selectFrame(frameNumber) {  
   var idslct = charIDToTypeID( "slct" );
       var desc9 = new ActionDescriptor();
       var idnull = charIDToTypeID( "null" );
           var ref3 = new ActionReference();
           var idanimationFrameClass = stringIDToTypeID( "animationFrameClass" );
           ref3.putIndex( idanimationFrameClass, frameNumber );
       desc9.putReference( idnull, ref3 );
   executeAction( idslct, desc9, DialogModes.NO );
}


selectFrame(10)

 

 

 

 

JJMack