Overblog
Editer la page Suivre ce blog Administration + Créer mon blog
/ / /

This script prints into a file an action descriptor, an action reference or an action list with all parameters and types.

 

Action descriptors are the basic units of communication with Photoshop to do what is not possible with a normal script using classes and objects.

 

Action descriptors are also used to get many internal informations like for instance the opacity of the current brush among a lot of others.

 

Action descriptors are given as arguments to photoshop events and so allow to known what is the context of an event call. For instance on "open", an action descriptor gives the path name of the document .

 

The problem in using these powerfull descriptors is to known the format and the identifers that are not documented.

 

This is the purpose of this script: to show informations inside action descriptors and to give an example of how to do it.

 

/************************************************************************
   Action Viewer
 ************************************************************************
 Prints an action descriptor, action reference or action list with all
 arguments and types into a file and/or an alert box.
 IDs are printed as strings if possible ("Select") else as chars ('slct').
 ************************************************************************
 20/05/2010 Habaki V1r01 : Creation
 ************************************************************************/
var ScriptName = "Action Viewer, (c) Habaki 2010";

var FilePath   = "/c/PSActionD.txt"; // Full path of the output file
/*----------------------------------------------------------------------*
                        Num to String (enumeration value)
 *----------------------------------------------------------------------*/
function NumSt(Num)
{
  var St = app.typeIDToStringID(Num);
  if (St) return("\"" + St + "\"");
  St = app.typeIDToCharID(Num);
  if (St) return("'" + St + "'");
  return(String(Num));
}
/*----------------------------------------------------------------------*
                        ID to String
 *----------------------------------------------------------------------*/
function IDSt(ID)
{
  var St = app.typeIDToStringID(ID);
  if (St) return("\"" + St + "\"");
  return("'" + app.typeIDToCharID(ID) + "'");
}
/*----------------------------------------------------------------------*
                        Print Action Reference to string
 *----------------------------------------------------------------------*/
function AR_PrintSt(AR, Margin)
{
  var St = Margin;
  var Form;
  var ValSt, FormSt, ValClass, ValClassc;
 
  AR.getName();
  Form = AR.getForm();
  ValClass = app.typeIDToStringID(AR.getDesiredClass());
  ValClassc = app.typeIDToCharID(AR.getDesiredClass());
 
  if (Form == ReferenceFormType.CLASSTYPE) {
    FormSt = "Class";
    ValSt = ValClass;
  }
  else
  if (Form == ReferenceFormType.ENUMERATED) {
    FormSt = "Enumerated";
    Type = AR.getEnumeratedType();
    Val  = AR.getEnumeratedValue();
    ValSt = "(Type=" + IDSt(Type)
          + ", Val=" + NumSt(Val)
          + ")";
  }
  else
  if (Form == ReferenceFormType.IDENTIFIER) {
    FormSt = "Identifier";
    ValSt  = IDSt(AR.getIdentifier());
  }
  else
  if (Form == ReferenceFormType.INDEX) {
    FormSt = "Index";
    ValSt  = String(AR.getIndex());
  }
  else
  if (Form == ReferenceFormType.NAME) {
    FormSt = "Name";
    ValSt = "\"" + AR.getName() + "\"";
  }
  else
  if (Form == ReferenceFormType.OFFSET) {
    FormSt = "Offset";
    ValSt = String(AR.getOffset());
  }
  else
  if (Form == ReferenceFormType.PROPERTY) {
    FormSt = "Property";
    ValSt = IDSt(AR.getProperty());
  }
  else {
    FormSt = "??";
    ValSt = "??";
  }
 
  St += "Class=" + ValClass
     //+ "('" + ValClassc + "')" // CharID
     + ", " + FormSt + "=" + ValSt
     ;
  return(St);
}
/*----------------------------------------------------------------------*
   Print Descriptor
 *----------------------------------------------------------------------*/
function DS_PrintSt(DS, Key, Margin)
{
  var Val;
  var TypeSt = "?";
  var ValSt = "?";
  var Type = DS.getType(Key);
 
  if (Type == DescValueType.ALIASTYPE) {
    TypeSt = "Path";
    ValSt = DS.getPath(Key);
  }
  else
  if (Type == DescValueType.BOOLEANTYPE) {
    TypeSt = "Boolean";
    ValSt = DS.getBoolean(Key);
  }
  else
  if (Type == DescValueType.CLASSTYPE) {
    TypeSt = "Class";
    Type = DS.getClass(Key);
    ValSt = IDSt(Type);
  }
  else
  if (Type == DescValueType.DOUBLETYPE) {
    TypeSt = "Double";
    ValSt = String(DS.getDouble(Key));
  }
  else
  if (Type == DescValueType.ENUMERATEDTYPE) {
    TypeSt = "Enumerated";
    Type = DS.getEnumerationType(Key);
    Val  = DS.getEnumerationValue(Key);
    ValSt = "Type=" + IDSt(Type)
          + ", Val=" + NumSt(Val)
          ;
  }
  else
  if (Type == DescValueType.INTEGERTYPE) {
    TypeSt = "Integer";
    ValSt = String(DS.getInteger(Key));
  }
  else
  if (Type == DescValueType.LISTTYPE) {
    TypeSt = "List";
    Val = DS.getList(Key);
    ValSt = "\r"
          + AL_PrintSt(Val, Margin + "    ")
          //+ Margin
          ;
  }
  else
  if (Type == DescValueType.OBJECTTYPE) {
    TypeSt = "Object";
    Type = DS.getObjectType(Key);
    Val = DS.getObjectValue(Key);
    ValSt = "Type=" + IDSt(Type) + ",\r"
          + AD_PrintSt(Val, Margin + "    ")
          //+ Margin
          ;
  }
  else
  if (Type == DescValueType.RAWTYPE) {
    TypeSt = "Raw";
    ValSt = "{" + DS.getData(Key) + "}";
  }
  else
  if (Type == DescValueType.REFERENCETYPE) {
    TypeSt = "Reference";
    Val = DS.getReference(Key);
    ValSt = AR_PrintSt(Val, "");
  }
  else
  if (Type == DescValueType.STRINGTYPE) {
    TypeSt = "String";
    ValSt = "\"" + DS.getString(Key) + "\"";
  }
  else
  if (Type == DescValueType.UNITDOUBLE) {
    TypeSt = "UnitDouble";
    Type = DS.getUnitDoubleType(Key);
    ValSt = "Type=" + IDSt(Type)
          + ", Val=" + String(DS.getUnitDoubleValue(Key))
          ;
  }
  else {
    TypeSt = "Type";
    ValSt = DS.getType(Key);
  }
  return(TypeSt + "(" + ValSt + ")");
}
/*----------------------------------------------------------------------*
                        Print Action List to string
 *----------------------------------------------------------------------*/
function AL_PrintSt(AL, Margin)
{
  var Key;
  var St = "";
 
  for (Key=0;Key < AL.count; Key++) {
    St += Margin + "[" + String(Key) + "]:"
        + DS_PrintSt(AL, Key, Margin)
        ;
    if (Key == AL.count-1) St += "\r";
    else                   St += ",\r"
  } // for
  St += Margin;
  return(St);
}
/*----------------------------------------------------------------------*
                        Print Action Descriptor to string
 *----------------------------------------------------------------------*/
function AD_PrintSt(AD, Margin)
{
  var i;
  var St = "";
  var Key;
 
  for (i=0;i < AD.count; i++) {
    Key  = AD.getKey(i);
    St += Margin + "Key[" + String(i) + "]:" + IDSt(Key)
       + " = "
       + DS_PrintSt(AD, Key, Margin)
       ;
    if (i == AD.count-1) St += "\r";
    else                 St += ",\r"
  } // for
  St += Margin;
  return(St);
}
/*----------------------------------------------------------------------*
   Main
 Prints a main action descriptor.
 *----------------------------------------------------------------------*/
try {
  var ref = new ActionReference();
  ref.putEnumerated(charIDToTypeID("capp"),
                    charIDToTypeID("Ordn"),
                    charIDToTypeID("Trgt")
                    );
  // Everything
  var AD = executeActionGet(ref);
 
  // Current tool only
  //AD = AD.getObjectValue(stringIDToTypeID('currentToolOptions'));
 
  // Current brush only
  //AD = AD.getObjectValue(stringIDToTypeID('brush'));
 
  var St = AD_PrintSt(AD, "");
 
  var FF = new File(FilePath);
  FF.open("w:");
  FF.write(St);
  FF.close();
  FF.execute();
 
  //alert(St, ScriptName);
 
} catch(ex) {
  alert(ex.message);
}

Partager cette page
Repost0
Published by Habaki - dans Scripts

Catégories