Skip to main content
August 14, 2013
Question

What why and when charIDToTypeID ?

  • August 14, 2013
  • 2 replies
  • 1587 views

I'm seeing this "charIDToTypeID" thing being used in many scripts both Adobe and developers, but I couldn't find any explanation as to why this "special adobe characters exist".

Could someone please reference me to a link or explain why and where should I be using this "encoding" ?

btw, a complete list of these lovely adobe chars can be found at http://ps-scripts.cvs.sourceforge.net/viewvc/ps-scripts/xtools/xlib/PSConstants.js?revision=1.18&view=markup

This topic has been closed for replies.

2 replies

DBarranca
Legend
August 22, 2013

As c.pfaffenbichler said, 4 chars strings are converted via charIDToTypeID to numbers. In effect "save" is easier to remember than 1935767141.

typeIDs are used in ActionManager code (have a look at it in the log of the ScriptingListener plugin), which is an alternative way to drive Photoshop - that is, without using the DOM.

Everything you can do with the DOM, you can reply via AM - not the reverse, though.

Even more user friendly that charID are, in my opinion, stringIDs.

For instance, while "save" is meaningful, "#Rlt" not so (it's "distanceUnit", as a stringID).

A charIDToStringID function can be implemented easily:

var c2s = function(charID) { return app.typeIDToStringID(app.charIDToTypeID(charID)) };

As follows for instance the default output of the ScriptingListener for the PS "File - New" command:

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

var idMk = charIDToTypeID( "Mk  " );

    var desc78 = new ActionDescriptor();

    var idNw = charIDToTypeID( "Nw  " );

        var desc79 = new ActionDescriptor();

        var idpreset = stringIDToTypeID( "preset" );

        desc79.putString( idpreset, """Default Photoshop Size""" );

    var idDcmn = charIDToTypeID( "Dcmn" );

    desc78.putObject( idNw, idDcmn, desc79 );

executeAction( idMk, desc78, DialogModes.NO );

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

which can be rewritten as:

var d1 = new ActionDescriptor();

var d2 = new ActionDescriptor();

d2.putString( s2t("preset"), "Default Photoshop Size" );

d1.putObject( s2t("new"), s2t("document"), d2 );

executeAction( s2t("make"), d1, DialogModes.NO);

and it's possibly a bit more readable by humans ;-)

Davide Barranca

www.davidebarranca.com

c.pfaffenbichler
Community Expert
Community Expert
August 15, 2013

Quote from the Object Model Viewer:

Converts from a four character code to a runtime ID.

I think the character IDs were introduced to make things easier as they should be more easy to remember than the corresponding numbers.