Art  Delphi  Automation  History  Home  Politics  Email me Default Colours  Printable Colours

Automating Adobe Photoshop

{work in progress}

Contents


Sources of information

Web sites Delphi sites
For catching events, or general COM concepts, see also
Binh Ly's tutorials

Non-Delphi sites
Adobe Photoshop 5.5 SDK


Back to top

Quick reference

The Photoshop type library exposes the following interfaces (and their dispinterface equivalents):

  IAction
  IActions
  IActionControl
  IActionDescriptor
  IActionList
  IActionReference
  IAutoPSDoc
  IPhotoshopApplication

As you can see, Photoshop automation revolves around Actions. You can easily automate something by creating it as an Action in Photoshop, then playing it from Delphi using the IAction.Play or IPhotoshopApplication.PlayAction methods.

Back to top

IPhotoshopApplication - major methods and properties

    function Open(const fileName: WideString): IAutoPSDoc;
    function PlayAction(const fileName: WideString): WordBool;

    procedure Quit;

    function MakeControlObject: IActionControl;
    function MakeDescriptor: IActionDescriptor;
    function MakeList: IActionList;
    function MakeReference: IActionReference;


    property Actions: IActions read Get_Actions;
    property FullName: WideString read Get_FullName;
    property Visible: WordBool read Get_Visible write Set_Visible;
Back to top

IAutoPSDoc - major methods and properties

    procedure Activate;
    procedure Close;
    procedure SaveTo(const fileName: WideString);


    property Title: WideString read Get_Title;
Back to top

IAction - methods and properties

    procedure Play; safecall;


    function Get_name: WideString;
    property name: WideString read Get_name;
Back to top

IActions - methods and properties

    function Get_count: Integer;
    function Get_Item(index: Integer): IAction;
    function Get__NewEnum: IUnknown;
    
    property count: Integer read Get_count;
    property Item[index: Integer]: IAction read Get_Item; default;
    property _NewEnum: IUnknown read Get__NewEnum;
Back to top

IActionControl - methods

    function Play(eventID: Integer; 
		  const parameters: IActionDescriptor; 
		  dialogOptions: Integer): IActionDescriptor;
    procedure GetActionProperty(const reference: IActionReference; 
                                out propertyDesc: IActionDescriptor);


    procedure StringIDToTypeID(const stringID: WideString; out typeID: Integer);
    procedure TypeIDToStringID(typeID: Integer; out stringID: WideString);
Back to top

IActionDescriptor - methods

    procedure IsEqual(const otherDesc: IActionDescriptor; out IsEqual: WordBool);
    procedure Erase(key: Integer);
    procedure Clear;


    procedure GetType(key: Integer; out type_: Integer);
    procedure GetKey(index: Integer; out key: Integer);
    procedure HasKey(key: Integer; out HasKey: WordBool);
    procedure GetCount(out count: Integer);


    procedure GetInteger(key: Integer; out retval: Integer);
    procedure PutInteger(key: Integer; value: Integer);
    procedure GetDouble(key: Integer; out retval: Double);
    procedure PutDouble(key: Integer; value: Double);
    procedure GetUnitDouble(key: Integer; out unitID: Integer; out retval: Double);
    procedure PutUnitDouble(key: Integer; unitID: Integer; value: Double);
    procedure GetString(key: Integer; out retval: WideString);
    procedure PutString(key: Integer; const value: WideString);
    procedure GetBoolean(key: Integer; out retval: WordBool);
    procedure PutBoolean(key: Integer; value: WordBool);


    procedure GetList(key: Integer; out list: IActionList);
    procedure PutList(key: Integer; const list: IActionList);
    procedure GetObject(key: Integer; out classID: Integer; 
		        out retval: IActionDescriptor);
    procedure PutObject(key: Integer; classID: Integer; const value: IActionDescriptor);
    procedure GetGlobalObject(key: Integer; out classID: Integer; 
			      out retval: IActionDescriptor);
    procedure PutGlobalObject(key: Integer; classID: Integer; const value: IActionDescriptor);
    procedure GetEnumerated(key: Integer; out enumType: Integer; out value: Integer);
    procedure PutEnumerated(key: Integer; enumType: Integer; value: Integer);
    procedure GetReference(key: Integer; out reference: IActionReference);
    procedure PutReference(key: Integer; const reference: IActionReference);
    procedure GetClass(key: Integer; out classID: Integer);
    procedure PutClass(key: Integer; classID: Integer);
    procedure GetGlobalClass(key: Integer; out classID: Integer);
    procedure PutGlobalClass(key: Integer; classID: Integer);
    procedure GetPath(key: Integer; out pathString: WideString);
    procedure PutPath(key: Integer; const pathString: WideString);
Back to top

IActionList - methods

    procedure GetType(index: Integer; out value: Integer);
    procedure GetCount(out value: Integer);


    procedure GetInteger(index: Integer; out value: Integer);
    procedure PutInteger(value: Integer);
    procedure GetDouble(index: Integer; out value: Double);
    procedure PutDouble(value: Double);
    procedure GetUnitDouble(index: Integer; out unit_: Integer; out value: Double);
    procedure PutUnitDouble(unit_: Integer; value: Double);
    procedure GetString(index: Integer; out str: WideString);
    procedure PutString(const str: WideString);
    procedure GetBoolean(index: Integer; out value: WordBool);
    procedure PutBoolean(value: WordBool);


    procedure GetList(index: Integer; out actionList: IActionList);
    procedure PutList(const actionList: IActionList);
    procedure GetObject(index: Integer; out type_: Integer; out value: IActionDescriptor);
    procedure PutObject(type_: Integer; const value: IActionDescriptor);
    procedure GetGlobalObject(index: Integer; out type_: Integer; 
			      out value: IActionDescriptor);
    procedure PutGlobalObject(type_: Integer; const value: IActionDescriptor);
    procedure GetEnumerated(index: Integer; out type_: Integer; out value: Integer);
    procedure PutEnumerated(type_: Integer; value: Integer);
    procedure GetReference(index: Integer; out value: IActionReference);
    procedure PutReference(const value: IActionReference);
    procedure GetClass(index: Integer; out value: Integer);
    procedure PutClass(value: Integer);
    procedure GetGlobalClass(index: Integer; out value: Integer);
    procedure PutGlobalClass(value: Integer);
    procedure GetPath(index: Integer; out pathString: WideString);
    procedure PutPath(const pathString: WideString);
Back to top

IActionReference - methods

    procedure GetForm(out value: Integer);
    procedure GetDesiredClass(out value: Integer);
    procedure PutClass(desiredClass: Integer);
    procedure GetName(out name: WideString);
    procedure PutName(desiredClass: Integer; const name: WideString);
    procedure GetIndex(out value: Integer);
    procedure PutIndex(desiredClass: Integer; value: Integer);
    procedure GetIdentifier(out value: Integer);
    procedure PutIdentifier(desiredClass: Integer; value: Integer);
    procedure GetOffset(out value: Integer);
    procedure PutOffset(desiredClass: Integer; value: Integer);
    procedure GetEnumerated(out type_: Integer; out enumValue: Integer);
    procedure PutEnumerated(desiredClass: Integer; type_: Integer; value: Integer);
    procedure GetProperty(out value: Integer);
    procedure PutProperty(desiredClass: Integer; value: Integer);
    procedure GetContainer(out value: IActionReference);
Back to top

How do I ... ?

Back to top

>>>>>How to start PhotoShop<<<<<

uses ComObj, ActiveX, PhotoShopTypeLibrary_TLB;

var
  PS: IPhotoShopApplication;
  AppWasRunning: boolean;
  Unknown: IUnknown;
begin 
  AppWasRunning := False;
  Result := GetActiveObject(CLASS_PhotoshopApplication, nil, Unknown);
  if (Result = MK_E_UNAVAILABLE) then
    PS := CoPhotoshopApplication.Create
  else begin
    { make sure no other error occurred during GetActiveObject }
    OleCheck(Result);
    OleCheck(Unknown.QueryInterface(IPhotoShopApplication, PS));
    AppWasRunning := True;
  end;
  PS.Visible := True; 

Or, with late binding:

  PS := CreateOleObject('Photoshop.Application');
  PS.Visible := True;
Back to 'HowDoI'

>>>>>How to close Photoshop<<<<<

If PS is your Photoshop application variable:

 PS.Quit; 
Back to 'HowDoI'

>>>>>How to open a file<<<<<

If PS is your Photoshop application variable:

var
  Pic: IAutoPSDoc;
begin
  Pic := PS.Open('InsertNameHere.psd');      // Bingeley-bingeley-beep!
Back to 'HowDoI'

>>>>>How to save a file<<<<<

If Pic is your IAutoPSDoc variable:

Pic.SaveTo('InsertNameHere.psd');     
Back to 'HowDoI'

>>>>>How to play an action<<<<<

If PS is your Photoshop application variable:

  PS.PlayAction('Large Round Button');


Back to 'HowDoI'