Get Frame

Anyone, especially newbies, asking for help with photoshop scripting and photoshop automation - as opposed to those contributing to discussion about an aspect of photoshop scripting

Moderators: Patrick, Mike Hale, xbytor, Larry Ligon, Andrew, PS-Moderators

Get Frame

Postby getInteger » Tue Dec 15, 2009 11:52 pm

Hi all.

I'm new with scripting, i use Javascript and Photoshop CS3.
I would like to know when i have a video layer the current frame.
How to get the current frame number into a variable ?

Thanks.
getInteger
 
Posts: 34
Joined: Tue Dec 15, 2009 8:52 pm

Postby Mike Hale » Wed Dec 16, 2009 12:09 am

I don't think you can. The videoLayer descriptor does not have any timeline info and I haven't found a way to get the timeline descriptor.
Mike Hale
Site Admin
 
Posts: 2785
Joined: Fri Sep 30, 2005 10:52 pm
Location: USA

Postby getInteger » Wed Dec 16, 2009 1:14 am

:''''( nooo...
Are you sure about this ??

I can set the frame, so why can't we get the frame ? :s
getInteger
 
Posts: 34
Joined: Tue Dec 15, 2009 8:52 pm

Postby Mike Hale » Wed Dec 16, 2009 1:29 am

No, I'm not sure. There may be a way, but I haven't found one.

I will bet the code you have to set the time puts the timeline class in a null reference. Most of the time that means that there is no way to get that class's descriptor. And you will need that descriptor to get the current frame.
Mike Hale
Site Admin
 
Posts: 2785
Joined: Fri Sep 30, 2005 10:52 pm
Location: USA

Postby getInteger » Wed Dec 16, 2009 1:57 am

This is the log when you click in the timeline in the animation window, when you do a previous frame and a next frame.

You don't get the real current frame number but you have seconds +frame rate + frame = frame number.

Code: Select all
// =======================================================
var id29 = charIDToTypeID( "setd" );
    var desc5 = new ActionDescriptor();
    var id30 = charIDToTypeID( "null" );
        var ref2 = new ActionReference();
        var id31 = charIDToTypeID( "Prpr" );
        var id32 = stringIDToTypeID( "time" );
        ref2.putProperty( id31, id32 );
        var id33 = stringIDToTypeID( "timeline" );
        ref2.putClass( id33 );
    desc5.putReference( id30, ref2 );
    var id34 = charIDToTypeID( "T   " );
        var desc6 = new ActionDescriptor();
        var id35 = stringIDToTypeID( "seconds" );
        desc6.putInteger( id35, 6 );
        var id36 = stringIDToTypeID( "frame" );
        desc6.putInteger( id36, 11 );
        var id37 = stringIDToTypeID( "frameRate" );
        desc6.putDouble( id37, 30.000000 );
    var id38 = stringIDToTypeID( "timecode" );
    desc5.putObject( id34, id38, desc6 );
executeAction( id29, desc5, DialogModes.NO );

// =======================================================
var id39 = stringIDToTypeID( "previousFrame" );
    var desc7 = new ActionDescriptor();
    var id40 = stringIDToTypeID( "toNextWholeSecond" );
    desc7.putBoolean( id40, false );
executeAction( id39, desc7, DialogModes.NO );

// =======================================================
var id41 = stringIDToTypeID( "nextFrame" );
    var desc8 = new ActionDescriptor();
    var id42 = stringIDToTypeID( "toNextWholeSecond" );
    desc8.putBoolean( id42, false );
executeAction( id41, desc8, DialogModes.NO );
getInteger
 
Posts: 34
Joined: Tue Dec 15, 2009 8:52 pm

Postby jugenjury » Wed Dec 16, 2009 12:34 pm

I don't believe this is what you're looking for. This could be used to tell Photoshop which frame to select but not for Photoshop to return information to the script.

I need to try some stuff and if I have any luck I'll let you know. I haven't worked with video/animation in scripts yet.


getInteger wrote:This is the log when you click in the timeline in the animation window, when you do a previous frame and a next frame.

You don't get the real current frame number but you have seconds +frame rate + frame = frame number.

Code: Select all
// =======================================================
var id29 = charIDToTypeID( "setd" );
    var desc5 = new ActionDescriptor();
    var id30 = charIDToTypeID( "null" );
        var ref2 = new ActionReference();
        var id31 = charIDToTypeID( "Prpr" );
        var id32 = stringIDToTypeID( "time" );
        ref2.putProperty( id31, id32 );
        var id33 = stringIDToTypeID( "timeline" );
        ref2.putClass( id33 );
    desc5.putReference( id30, ref2 );
    var id34 = charIDToTypeID( "T   " );
        var desc6 = new ActionDescriptor();
        var id35 = stringIDToTypeID( "seconds" );
        desc6.putInteger( id35, 6 );
        var id36 = stringIDToTypeID( "frame" );
        desc6.putInteger( id36, 11 );
        var id37 = stringIDToTypeID( "frameRate" );
        desc6.putDouble( id37, 30.000000 );
    var id38 = stringIDToTypeID( "timecode" );
    desc5.putObject( id34, id38, desc6 );
executeAction( id29, desc5, DialogModes.NO );

// =======================================================
var id39 = stringIDToTypeID( "previousFrame" );
    var desc7 = new ActionDescriptor();
    var id40 = stringIDToTypeID( "toNextWholeSecond" );
    desc7.putBoolean( id40, false );
executeAction( id39, desc7, DialogModes.NO );

// =======================================================
var id41 = stringIDToTypeID( "nextFrame" );
    var desc8 = new ActionDescriptor();
    var id42 = stringIDToTypeID( "toNextWholeSecond" );
    desc8.putBoolean( id42, false );
executeAction( id41, desc8, DialogModes.NO );
jugenjury
 
Posts: 12
Joined: Tue Dec 15, 2009 10:39 pm
Location: Berwick, PA

Postby getInteger » Wed Dec 16, 2009 1:07 pm

Thanks.
I hope you'll find something.
Yes i know the log i posted is about set not get but that's all i was able to get in the log :(
getInteger
 
Posts: 34
Joined: Tue Dec 15, 2009 8:52 pm

Postby jugenjury » Wed Dec 16, 2009 2:01 pm

I'm onto something but I need to know how you are selecting your frames to determine the frame number. In the timeline with the slider? The "in" slider or the "out" slider?


getInteger wrote:Thanks.
I hope you'll find something.
Yes i know the log i posted is about set not get but that's all i was able to get in the log :(
jugenjury
 
Posts: 12
Joined: Tue Dec 15, 2009 10:39 pm
Location: Berwick, PA

Postby getInteger » Wed Dec 16, 2009 2:19 pm

Oh nice !
What do you mean by "in" slider or "out" slider ?

I guess i use all the ways i know to change the current frame.
I use the playback panel, the current frame number (you can click on it to slide or to enter a specific number) and the timeline slider.

Image
getInteger
 
Posts: 34
Joined: Tue Dec 15, 2009 8:52 pm

Postby jugenjury » Wed Dec 16, 2009 3:04 pm

The slider you have circled is the "out" slider. The slider located at 00 in your example is the "in" slider. But, it won't matter. I made it so you can choose either when you call the function. Try this...

Code: Select all
function getFrame(IO) {

   if (IO == "in") var tIO = stringIDToTypeID("workInTime");
   if (IO == "out") var tIO = stringIDToTypeID("workOutTime");

   var fr = 0;
   var secs = 0;
   var mins = 0;
   var hrs = 0;
   var frRate = 30.0;
   
   var rate = stringIDToTypeID("frameRate");
   var frame = stringIDToTypeID("frame");
   var seconds = stringIDToTypeID("seconds");
   var minutes = stringIDToTypeID("minutes");
   var hours = stringIDToTypeID("hours");

   var tLine=stringIDToTypeID("timeline");
   var get=charIDToTypeID('getd');
   var nul=charIDToTypeID('null');
   var prop=charIDToTypeID('Prpr');
   
   var actionRef = new ActionReference();
   actionRef.putProperty(prop,tIO);
   actionRef.putClass(tLine);

   var desc=new ActionDescriptor();
   desc.putReference(nul, actionRef);
         
   var TC=executeAction(get,desc,DialogModes.NO);
   var TL=TC.getObjectValue(tIO);
   
   try {fr=TL.getInteger(frame);} catch(e){}
   try {secs=TL.getInteger(seconds);} catch(e){}
   try {mins=TL.getInteger(minutes);} catch(e){}
   try {hrs=TL.getInteger(hours);} catch(e){}
   frRate = TL.getDouble(rate);

   return hrs * 3600 * frRate + mins * 60 * frRate + secs * frRate + fr;

}
alert(getFrame("in"));
alert(getFrame("out"));



getInteger wrote:Oh nice !
What do you mean by "in" slider or "out" slider ?

I guess i use all the ways i know to change the current frame.
I use the playback panel, the current frame number (you can click on it to slide or to enter a specific number) and the timeline slider.

Image
[/code]

If you get errors on the "frRate = TL.getDouble(rate);" line, you may want to set it up in a try-catch block like the secs, mins, hrs are. I think framerate is always returned, though, so you may not need it.
jugenjury
 
Posts: 12
Joined: Tue Dec 15, 2009 10:39 pm
Location: Berwick, PA

Postby jugenjury » Wed Dec 16, 2009 3:31 pm

OK. The above will return the "in" slider position and the last frame but not the currently selected frame.

Give me a bit to find the current frame descriptor.
jugenjury
 
Posts: 12
Joined: Tue Dec 15, 2009 10:39 pm
Location: Berwick, PA

Postby jugenjury » Wed Dec 16, 2009 3:37 pm

OK. Sorry about that. Try this one....

Code: Select all
function getFrame(IO) {

   if (IO=="in") var tIO = stringIDToTypeID("workInTime");
   if (IO=="out") var tIO = stringIDToTypeID("workOutTime");
   if (IO=="current") var tIO=stringIDToTypeID("currentFrame");

   var fr = 0;
   var secs = 0;
   var mins = 0;
   var hrs = 0;
   var frRate = 30.0;
   
   var rate = stringIDToTypeID("frameRate");
   var frame = stringIDToTypeID("frame");
   var seconds = stringIDToTypeID("seconds");
   var minutes = stringIDToTypeID("minutes");
   var hours = stringIDToTypeID("hours");

   var tLine=stringIDToTypeID("timeline");
   var get=charIDToTypeID('getd');
   var nul=charIDToTypeID('null');
   var prop=charIDToTypeID('Prpr');
   
   var actionRef = new ActionReference();
   actionRef.putProperty(prop,tIO);
   actionRef.putClass(tLine);

   var desc=new ActionDescriptor();
   desc.putReference(nul, actionRef);
         
   var TC=executeAction(get,desc,DialogModes.NO);
   
   if (IO=="current") return TC.getInteger(tIO);
   
   var TL=TC.getObjectValue(tIO);
   
   try {fr=TL.getInteger(frame);} catch(e){}
   try {secs=TL.getInteger(seconds);} catch(e){}
   try {mins=TL.getInteger(minutes);} catch(e){}
   try {hrs=TL.getInteger(hours);} catch(e){}
   frRate = TL.getDouble(rate);

   return hrs * 3600 * frRate + mins * 60 * frRate + secs * frRate + fr;

}
alert(getFrame("in"));  // For the beginning slider position
alert(getFrame("out"));  // For the end slider position
alert(getFrame("current"));  // For the current slider position
jugenjury
 
Posts: 12
Joined: Tue Dec 15, 2009 10:39 pm
Location: Berwick, PA

Postby Mike Hale » Wed Dec 16, 2009 4:04 pm

Well who said you can't teach an old dog new tricks, thanks jugenjury. I didn't think it was possible to get the descriptor from a null reference but I have been using executeActionGet()

Here is a version that just get the current time.

Code: Select all
function getCurrentFrame(){
   try{
      var actionRef = new ActionReference();
      actionRef.putProperty(charIDToTypeID('Prpr'), stringIDToTypeID("currentFrame"));
      actionRef.putClass(stringIDToTypeID("timeline"));

      var desc=new ActionDescriptor();
      desc.putReference(charIDToTypeID('null'), actionRef);
         
      var TC=executeAction(charIDToTypeID('getd'), desc, DialogModes.NO);
      return TC.getInteger(stringIDToTypeID("currentFrame"));
   }catch(e){}
}
getCurrentFrame();


Now off to see what else I can apply this method of getting the descriptor to.
Mike Hale
Site Admin
 
Posts: 2785
Joined: Fri Sep 30, 2005 10:52 pm
Location: USA

Postby getInteger » Wed Dec 16, 2009 10:06 pm

OMG THANKS A LOT it works !!!!!!!!!! :shock: :lol:

EDIT: i have a question.

In the log some actions are totally invisibles, does that means that we can't do anything with ?
I mean for example when you edit a tool preset there is nothing wrote in the log, so is it imposssible to script stuff that control tool preset properties ?
getInteger
 
Posts: 34
Joined: Tue Dec 15, 2009 8:52 pm

Postby jugenjury » Thu Dec 17, 2009 2:47 am

getInteger wrote:OMG THANKS A LOT it works !!!!!!!!!! :shock: :lol:

EDIT: i have a question.

In the log some actions are totally invisibles, does that means that we can't do anything with ?
I mean for example when you edit a tool preset there is nothing wrote in the log, so is it imposssible to script stuff that control tool preset properties ?


What do you mean when you say "edit a tool preset"? There are certain things that can be done but maybe not quite as you're thinking of it.

Are you talking about things like brush size, brush opacity, brush flow, brush shape, etc?
jugenjury
 
Posts: 12
Joined: Tue Dec 15, 2009 10:39 pm
Location: Berwick, PA

Next

Return to Help Me

Who is online

Users browsing this forum: No registered users and 0 guests