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

CS4 Script Listener Note

New Here ,
Oct 18, 2008 Oct 18, 2008
Using CS4 this morning, I noted that there are problems with the script listener code that is generated.

CS4 seems to have changed the naming conventions when generating variables. This change has led to a lot of duplicated variable names in the generated code.

This means that you can't just take vanilla script listener code and put it into a vb.net program and have it work. You will have to go through and rename the duplicated variables and rename their appearance in following commands.

Not a show stopper but it will make it much more difficult for people to use this usually highly useful tool.

Regards

George Smith
TOPICS
Actions and scripting
3.9K
Translate
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
Adobe
Explorer ,
Oct 18, 2008 Oct 18, 2008
> This means that you can't just take vanilla script listener code and put it into a vb.net program and have it work. You will have to go through and rename the duplicated variables and rename their appearance in following commands.
>

You should probably be wrapping the chunks of ScriptingListener code in functions.

-X
Translate
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
New Here ,
Oct 18, 2008 Oct 18, 2008
X

Of course I do that. Just the wrapped code isn't compilable as is because of the duplicated variable names.

As I said it can be corrected but its a bit dicey.

Here is an example:

REM =======================================================
DIM objApp
SET objApp = CreateObject("Photoshop.Application")
REM Use dialog mode 3 for show no dialogs
DIM dialogMode
dialogMode = 3
DIM idGrn
idGrn = objApp.CharIDToTypeID( "Grn " )
DIM desc34
SET desc34 = CreateObject( "Photoshop.ActionDescriptor" )
DIM idGEfk
idGEfk = objApp.CharIDToTypeID( "GEfk" )
DIM idGEft
idGEft = objApp.CharIDToTypeID( "GEft" )
DIM idGrn
idGrn = objApp.CharIDToTypeID( "Grn " )
Call desc34.PutEnumerated( idGEfk, idGEft, idGrn )
DIM idIntn
idIntn = objApp.CharIDToTypeID( "Intn" )
Call desc34.PutInteger( idIntn, 40 )
DIM idCntr
idCntr = objApp.CharIDToTypeID( "Cntr" )
Call desc34.PutInteger( idCntr, 50 )
DIM idGrnt
idGrnt = objApp.CharIDToTypeID( "Grnt" )
DIM idGrnt
idGrnt = objApp.CharIDToTypeID( "Grnt" )
DIM idGrnR
idGrnR = objApp.CharIDToTypeID( "GrnR" )
Call desc34.PutEnumerated( idGrnt, idGrnt, idGrnR )
Call objApp.ExecuteAction( idGrn, desc34, dialogMode )

The above is a grain filter application.

Note at the end the duplicate declaration for idGrnt. Then both are used in the Call desc34.PutEnumerated(idGrnt,idGrnt,idGrnR) statement.

This is an error and won't compile. One must change the second declaration of idGrnt to something else like idGrnt2 then alter the reference to it in the putenumerated command also.

It's pretty obvious this was never tested by anyone as this is immediately obvious once it's placed into a program, wrapped or not.

Regards

George Smith
Translate
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
New Here ,
Oct 18, 2008 Oct 18, 2008
By the way, I checked and the same problem seems to be present in java script listener code also.

The same apply grain filter:

var idGrn = charIDToTypeID( "Grn " );
var desc34 = new ActionDescriptor();
var idGEfk = charIDToTypeID( "GEfk" );
var idGEft = charIDToTypeID( "GEft" );
var idGrn = charIDToTypeID( "Grn " );
desc34.putEnumerated( idGEfk, idGEft, idGrn );
var idIntn = charIDToTypeID( "Intn" );
desc34.putInteger( idIntn, 40 );
var idCntr = charIDToTypeID( "Cntr" );
desc34.putInteger( idCntr, 50 );
var idGrnt = charIDToTypeID( "Grnt" );
var idGrnt = charIDToTypeID( "Grnt" );
var idGrnR = charIDToTypeID( "GrnR" );
desc34.putEnumerated( idGrnt, idGrnt, idGrnR );
executeAction( idGrn, desc34, DialogModes.NO );

Note the double var declaration for idGrnt which is the same error as seen in the vb script example above.

This isn't so bad in a small example like this but check out a blending option like application of a bevel. There were 8 or 9 duplicated fields throughout.

Regards

George Smith
Translate
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
Explorer ,
Oct 18, 2008 Oct 18, 2008
> Note the double var declaration for idGrnt which is the same error as seen in the vb script example above.
>
> This isn't so bad in a small example like this but check out a blending option like application of a bevel. There were 8 or 9 duplicated fields throughout.

I hadn't noticed the dupes. I don't like the format of SL code at all so I write
a script that converts it into something a bit more palatable.

Your SL-JS code would translate to this:

//
// Generated from ~/Desktop/test.log on Sat Oct 18 2008 12:38:33 GMT-0500
//

function ftn1() {
function cTID(s) { return app.charIDToTypeID(s); };
function sTID(s) { return app.stringIDToTypeID(s); };

var desc34 = new ActionDescriptor();
desc34.putEnumerated( cTID('GEfk'), cTID('GEft'), cTID('Grn ') );
desc34.putInteger( cTID('Intn'), 40 );
desc34.putInteger( cTID('Cntr'), 50 );
desc34.putEnumerated( cTID('Grnt'), cTID('Grnt'), cTID('GrnR') );
executeAction( cTID('Grn '), desc34, DialogModes.NO );
};


or this:

function ftn1() {
function cTID(s) { return app.charIDToTypeID(s); };
function sTID(s) { return app.stringIDToTypeID(s); };

var desc34 = new ActionDescriptor();
desc34.putEnumerated( cTID('GEfk'), cTID('GEft'), PSEnum.Green );
desc34.putInteger( PSKey.Intensity, 40 );
desc34.putInteger( PSEnum.Center, 50 );
desc34.putEnumerated( PSKey.GrainType, PSKey.GrainType, PSEnum.GrainRegular );
executeAction( PSEnum.Green, desc34, DialogModes.NO );
};


I had to modify the converter slightly to handle CS4 output.

BTW, JavaScript doesn't have an issue with the duplicate variable declarations.
The raw SL code executes just fine in CS4.

-X
Translate
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
Guru ,
Oct 18, 2008 Oct 18, 2008
The duplicate variables don't seem to be a problem with javascript. I don't have CS4 yet, but the JS version of the code above works fine in CS3 and CS2.

Mike
Translate
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
New Here ,
Oct 18, 2008 Oct 18, 2008
Yes I noted also that the javascript executed ok in CS4, though I wonder which var the reference refers back to, probably the last one declared?. It's obviously not what was intended.

However it won't work for c#.net or vb.net as the compiler catches the double declaration.

Regards

George Smith
Translate
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
New Here ,
Oct 18, 2008 Oct 18, 2008
Testing is the first thing that suffers in economic downturns and due to outsourcing... ;)
Translate
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
New Here ,
Oct 11, 2009 Oct 11, 2009

Would someone mind posting a verbose exact cut/paste of the CS4 ScriptListener log to this forum so I can look at it?  I would like to update myVBS2VB6 tool to handle this new format.  Please insert the full output you receive without any alterations.   Thanks.

My free tool for converting VBS ScriptListenerVB.log output into more readable code will work on pre-CS4ScriptListenerVB.log outpout right now.

http://ps-scripts.com/bb/viewtopic.php?p=12937#12937

The program is not example code but complied as Visual Basic 6 in object form only.   Please save my bandwidth and only download this code if you use the Visual Basic method of coding.  I will not do anything for you if you are coding JS and just a waste of time otherwise 🙂

Translate
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
Guru ,
Oct 11, 2009 Oct 11, 2009

Below is a short example vb log

REM =======================================================
DIM objApp
SET objApp = CreateObject("Photoshop.Application")
REM Use dialog mode 3 for show no dialogs
DIM dialogMode
dialogMode = 3
DIM idOpn
idOpn = objApp.CharIDToTypeID( "Opn " )
    DIM desc233
    SET desc233 = CreateObject( "Photoshop.ActionDescriptor" )
    DIM idnull
    idnull = objApp.CharIDToTypeID( "null" )
    Call desc233.PutPath( idnull, "C:\\Documents and Settings\\Mike\\Desktop\\white-to-to purple.psd" )
Call objApp.ExecuteAction( idOpn, desc233, dialogMode )

REM =======================================================
DIM objApp
SET objApp = CreateObject("Photoshop.Application")
REM Use dialog mode 3 for show no dialogs
DIM dialogMode
dialogMode = 3
DIM idsetd
idsetd = objApp.CharIDToTypeID( "setd" )
    DIM desc234
    SET desc234 = CreateObject( "Photoshop.ActionDescriptor" )
    DIM idnull
    idnull = objApp.CharIDToTypeID( "null" )
        DIM ref140
        SET ref140 = CreateObject( "Photoshop.ActionReference" )
        DIM idLyr
        idLyr = objApp.CharIDToTypeID( "Lyr " )
        DIM idOrdn
        idOrdn = objApp.CharIDToTypeID( "Ordn" )
        DIM idTrgt
        idTrgt = objApp.CharIDToTypeID( "Trgt" )
        Call ref140.PutEnumerated( idLyr, idOrdn, idTrgt )
    Call desc234.PutReference( idnull, ref140 )
    DIM idT
    idT = objApp.CharIDToTypeID( "T   " )
        DIM desc235
        SET desc235 = CreateObject( "Photoshop.ActionDescriptor" )
        DIM idUsrM
        idUsrM = objApp.CharIDToTypeID( "UsrM" )
        Call desc235.PutBoolean( idUsrM, False )
    DIM idLyr
    idLyr = objApp.CharIDToTypeID( "Lyr " )
    Call desc234.PutObject( idT, idLyr, desc235 )
Call objApp.ExecuteAction( idsetd, desc234, dialogMode )

REM =======================================================
DIM objApp
SET objApp = CreateObject("Photoshop.Application")
REM Use dialog mode 3 for show no dialogs
DIM dialogMode
dialogMode = 3
DIM idHd
idHd = objApp.CharIDToTypeID( "Hd  " )
    DIM desc236
    SET desc236 = CreateObject( "Photoshop.ActionDescriptor" )
    DIM idnull
    idnull = objApp.CharIDToTypeID( "null" )
        DIM list67
        SET list67 = CreateObject( "Photoshop.ActionList" )
            DIM ref141
            SET ref141 = CreateObject( "Photoshop.ActionReference" )
            DIM idLyr
            idLyr = objApp.CharIDToTypeID( "Lyr " )
            DIM idOrdn
            idOrdn = objApp.CharIDToTypeID( "Ordn" )
            DIM idTrgt
            idTrgt = objApp.CharIDToTypeID( "Trgt" )
            Call ref141.PutEnumerated( idLyr, idOrdn, idTrgt )
        Call list67.PutReference( ref141 )
    Call desc236.PutList( idnull, list67 )
Call objApp.ExecuteAction( idHd, desc236, dialogMode )

REM =======================================================
DIM objApp
SET objApp = CreateObject("Photoshop.Application")
REM Use dialog mode 3 for show no dialogs
DIM dialogMode
dialogMode = 3
DIM idslct
idslct = objApp.CharIDToTypeID( "slct" )
    DIM desc237
    SET desc237 = CreateObject( "Photoshop.ActionDescriptor" )
    DIM idnull
    idnull = objApp.CharIDToTypeID( "null" )
        DIM ref142
        SET ref142 = CreateObject( "Photoshop.ActionReference" )
        DIM idLyr
        idLyr = objApp.CharIDToTypeID( "Lyr " )
        Call ref142.PutName( idLyr, "Layer 3" )
    Call desc237.PutReference( idnull, ref142 )
    DIM idMkVs
    idMkVs = objApp.CharIDToTypeID( "MkVs" )
    Call desc237.PutBoolean( idMkVs, False )
Call objApp.ExecuteAction( idslct, desc237, dialogMode )

REM =======================================================
DIM objApp
SET objApp = CreateObject("Photoshop.Application")
REM Use dialog mode 3 for show no dialogs
DIM dialogMode
dialogMode = 3
DIM idInvr
idInvr = objApp.CharIDToTypeID( "Invr" )
Call objApp.ExecuteAction( idInvr, , dialogMode )

REM =======================================================
DIM objApp
SET objApp = CreateObject("Photoshop.Application")
REM Use dialog mode 3 for show no dialogs
DIM dialogMode
dialogMode = 3
DIM idMk
idMk = objApp.CharIDToTypeID( "Mk  " )
    DIM desc238
    SET desc238 = CreateObject( "Photoshop.ActionDescriptor" )
    DIM idnull
    idnull = objApp.CharIDToTypeID( "null" )
        DIM ref143
        SET ref143 = CreateObject( "Photoshop.ActionReference" )
        DIM idAdjL
        idAdjL = objApp.CharIDToTypeID( "AdjL" )
        Call ref143.PutClass( idAdjL )
    Call desc238.PutReference( idnull, ref143 )
    DIM idUsng
    idUsng = objApp.CharIDToTypeID( "Usng" )
        DIM desc239
        SET desc239 = CreateObject( "Photoshop.ActionDescriptor" )
        DIM idType
        idType = objApp.CharIDToTypeID( "Type" )
            DIM desc240
            SET desc240 = CreateObject( "Photoshop.ActionDescriptor" )
            DIM idLvls
            idLvls = objApp.CharIDToTypeID( "Lvls" )
            Call desc240.PutInteger( idLvls, 4 )
        DIM idPstr
        idPstr = objApp.CharIDToTypeID( "Pstr" )
        Call desc239.PutObject( idType, idPstr, desc240 )
    DIM idAdjL
    idAdjL = objApp.CharIDToTypeID( "AdjL" )
    Call desc238.PutObject( idUsng, idAdjL, desc239 )
Call objApp.ExecuteAction( idMk, desc238, dialogMode )

If you do like Xbytor suggested and replace the variables with function calls i.e.

Call desc238.PutObject(objApp.CharIDToTypeID( "Usng" ), objApp.CharIDToTypeID( "AdjL" ), desc239 )

it doesn't matter that Adobe changed the way the varibles are named. To me niether the old style of idNumber or new style of idCharID makes the log any more readable.

Translate
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
Advisor ,
Oct 11, 2009 Oct 11, 2009
To me niether the old style of idNumber or new style of idCharID makes the log any more readable.

Agreed. The most readable I've done  forJS is like this:

function ftn1() {
  function cTID(s) { return app.charIDToTypeID(s); };
  function sTID(s) { return app.stringIDToTypeID(s); };

// =======================================================
    var desc23 = new ActionDescriptor();
        var desc24 = new ActionDescriptor();
        desc24.putClass( PSClass.Mode, PSClass.RGBColorMode );
        desc24.putUnitDouble( PSKey.Width, PSUnit.Distance, 576.000000 );
        desc24.putUnitDouble( PSKey.Height, PSUnit.Distance, 720.000000 );
        desc24.putUnitDouble( PSKey.Resolution, PSUnit.Density, 72.000000 );
        desc24.putDouble( PSString.PixelScaleFactor, 1.000000 );
        desc24.putEnumerated( PSEvent.Fill, PSEvent.Fill, PSEnum.White );
        desc24.putInteger( PSKey.Depth, 8 );
        desc24.putString( PSString.profile, "sRGB IEC61966-2.1" );
    desc23.putObject( PSKey.New, PSClass.Document, desc24 );
    executeAction( PSEvent.Make, desc23, DialogModes.NO );
};

This is using SLCFix from xtools. I've been meaning to write an event handler to write a scripting listener log in this format instead of the current and old formats. The next step from there would be writing actual DOM code.

-X

Translate
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
New Here ,
Oct 11, 2009 Oct 11, 2009

xbator2's recoding structure is pretty dog gone sexy, that's what I think 🙂

Translate
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
New Here ,
Oct 11, 2009 Oct 11, 2009

What is the tag for code mark up in this forum? i.e. what tags do you wrap around text to indicate it is code like in the previous examples?

Translate
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
Guru ,
Oct 11, 2009 Oct 11, 2009

I use the >> next to the then choose Syntax Highlighing- Plain

Translate
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
New Here ,
Oct 11, 2009 Oct 11, 2009
LATEST

OK, I think someone set me up here.  I was absolutely tricked me into saying this way of coding is better than what comes out of PS natively.  🙂  I should have known better.  That sparks competition, adrenalin, and a competitive atmosphere that is counter productive.   Let me start over.   What I meant to say is that here is different way of coding this passage; its an option and if you go for it, I hope you enjoy.  If you like it, just run the output of PS ScriptListenerVB.log through the VBS2VB6 routine.

Back to the topic - turns out the program as-is today works on the CS4 format after all.  

Note this routine requires both the PS Type and Object libraries defined in the VB6 Project, Reference section.

Using the example above, there is the output of the VBS2VB6 tool:

Option Explicit

'
' Note: Running this routine in VB 6 requires that you add the following
'       references to the project:
'
'       - Adobe Photoshop x.0 Object Library  (where X is your installed version)
'       - Adobe Photoshop x.0 Type Library    (where X is any recent version)
'            i.e. use File, References, Add: \Programs\Adobe\Adobe Photoshop CS2\TypeLibrary.TI
'
'                   >>>>>>   You must have defined minimally these 2 references to use the output of this program!

' Global Variables:
Dim appRef As Photoshop.Application   'replaces CreateObject; makes VB6 functions easier to code with look-ahead
'
Dim dialogMode as long
' end of global variables

Private Sub Form_Load()

   dialogMode = 3

   Set appRef = New Photoshop.Application

   '''''' temporary variable string definitions
   '''''' end of temporary variable string definitions
End Sub

Private Sub Command1_Click()
    
   REM ====== [ optionaly name this subroutine ] =========== 
    
   DIM desc233 AS Photoshop.ActionDescriptor
   Set desc233 = New Photoshop.ActionDescriptor
    
   Call desc233.PutPath( phTypeNull, "C:\\Documents and Settings\\Mike\\Desktop\\white-to-to purple.psd")
   Call appRef.ExecuteAction( phEventOpen, desc233, dialogMode)
    
   REM ====== [ optionaly name this subroutine ] =========== 
    
   DIM desc234 AS Photoshop.ActionDescriptor
   DIM ref140 AS Photoshop.ActionReference
   DIM desc235 AS Photoshop.ActionDescriptor
   Set desc234 = New Photoshop.ActionDescriptor
   Set ref140 = New Photoshop.ActionReference
   Set desc235 = New Photoshop.ActionDescriptor
    
   Call ref140.PutEnumerated( phClassLayer, phTypeOrdinal, phEnumTarget)
   Call desc234.PutReference( phTypeNull, ref140)
   Call desc235.PutBoolean( phKeyUserMaskEnabled, False)
   Call desc234.PutObject( phKeyTo, phClassLayer, desc235)
   Call appRef.ExecuteAction( phEventSet, desc234, dialogMode)
    
   REM ====== [ optionaly name this subroutine ] =========== 
    
   DIM desc236 AS Photoshop.ActionDescriptor
   DIM list67 AS Photoshop.ActionList
   DIM ref141 AS Photoshop.ActionReference
   Set desc236 = New Photoshop.ActionDescriptor
   Set list67 = New Photoshop.ActionList
   Set ref141 = New Photoshop.ActionReference
    
   Call ref141.PutEnumerated( phClassLayer, phTypeOrdinal, phEnumTarget)
   Call list67.PutReference( ref141)
   Call desc236.PutList( phTypeNull, list67)
   Call appRef.ExecuteAction( phEventHide, desc236, dialogMode)
    
   REM ====== [ optionaly name this subroutine ] =========== 
    
   DIM desc237 AS Photoshop.ActionDescriptor
   DIM ref142 AS Photoshop.ActionReference
   Set desc237 = New Photoshop.ActionDescriptor
   Set ref142 = New Photoshop.ActionReference
    
   Call ref142.PutName( phClassLayer, "Layer 3")
   Call desc237.PutReference( phTypeNull, ref142)
   Call desc237.PutBoolean( phKeyMakeVisible, False)
   Call appRef.ExecuteAction( phEventSelect, desc237, dialogMode)
    
   REM ====== [ optionaly name this subroutine ] =========== 
    
    
   Call appRef.ExecuteAction( phClassInvert, , dialogMode)
    
   REM ====== [ optionaly name this subroutine ] =========== 
    
   DIM desc238 AS Photoshop.ActionDescriptor
   DIM ref143 AS Photoshop.ActionReference
   DIM desc239 AS Photoshop.ActionDescriptor
   DIM desc240 AS Photoshop.ActionDescriptor
   Set desc238 = New Photoshop.ActionDescriptor
   Set ref143 = New Photoshop.ActionReference
   Set desc239 = New Photoshop.ActionDescriptor
   Set desc240 = New Photoshop.ActionDescriptor
    
   Call ref143.PutClass( phClassAdjustmentLayer)
   Call desc238.PutReference( phTypeNull, ref143)
   Call desc240.PutInteger( phClassLevels, 4)
   Call desc239.PutObject( phKeyType, phClassPosterize, desc240)
   Call desc238.PutObject( phKeyUsing, phClassAdjustmentLayer, desc239)
   Call appRef.ExecuteAction( phEventMake, desc238, dialogMode)
End Sub

If you descide to use the tool ..... ENJOY it to the max!  Thanks again everyone for your support.

Translate
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