Introduction to OLE Automation in Photoshop

Discussion in 'Photoshop' started by Michael Fuchs, Apr 3, 2004.

  1. Can anybody provide me with a link to an introduction to OLE automation
    in Adobe Photoshop? Where can I get information about the object model,
    maybe some samples would be helpful.

    I need to do some stuff that goes beyond the capabilities of plain
    action recording.

    (Or is there another way of automatically generating images from a *.psd
    with different text imported from a list?)

    sorry 4 crossposting ... ;-(

    thanks a lot,
    fuze
     
    Michael Fuchs, Apr 3, 2004
    #1
    1. Advertisements

  2. Michael Fuchs

    Mike Russell Guest

    Not OLE automation per se, but scripting, which I think you'll like even
    better.
    http://partners.adobe.com/asn/photoshop/scripting.jsp
    Quite appropriate in this case. It avoids duplicate posts and replys. :)
     
    Mike Russell, Apr 4, 2004
    #2
    1. Advertisements

  3. You can use the OLE browser that comes with either MS Visual Studio or Perl.
    If you don't have Visual Studio, download Perl (which is free) and it will
    install the OLE browser (works only via MSIE).
     
    Branko Vukelic, Apr 4, 2004
    #3
  4. Branko Vukelic, Apr 4, 2004
    #4
  5. Thank you Mike and Branko, your replies definitely put me on the right
    track.

    At the moment I only use Photoshop 7.0, does anybody have a small
    working example for that? (The docs from the Adobe website only deal
    with the CS version. I think there are major differences in the object
    model between those versions)

    I do not know how to get that whole thing started. I tried Visual Studio
    and looked at the OLE/COM Object Viewer (is that what you meant
    Branko?). What is the differnce of the scripting approach anyway, is
    that something else than using the COM objects? (my impression is that
    this is the same.)

    btw, i know how to programm VB, but this is my first step into the
    OLE/COM/Active X world.

    thanks a lot!

    michael

    I only got this far: (Opens Photoshop, loads a file into PS and closes PS)

    Public Class Form1
    Inherits System.Windows.Forms.Form

    #Region " Windows Form Designer generated code "

    <snip>

    #End Region

    Dim aaa As New PhotoshopTypeLibrary.PhotoshopApplication()

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
    System.EventArgs) Handles Button1.Click
    aaa.Open("C:\Dokumente und
    Einstellungen\fuze\Desktop\template.psd")
    End Sub

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As
    System.EventArgs) Handles Button2.Click
    aaa.Quit()
    End Sub
    End Class
     
    Michael Fuchs, Apr 4, 2004
    #5
  6. I've been playing around with VBScript and your code snippet seems rather
    odd to me. What version of VB are you using? VB6 works pretty much the same
    way as VBScript, and there was no need for such bulky code when I was
    scripting InDesing. Then again, if it works, that's just fine with me.
    With InDesign, I'd usually go like

    ==============code================
    Dim myInDesign As InDesign.Application
    ' VBScript makes no use of "As" keyword, tho.

    Set myInDesign = CreateObject("InDesign.Application.2.0")
    'Open InDesign

    Set myActiveDocument = myInDesign.ActiveDocument
    'Gets the active document, and so on...
    ==============end=================

    I don't have the VisualStudio right here, so I can't tell you where exactly
    was "Object Browser" (or whatever the name was) located... It's something to
    do with References, I think.

    You should probably check the Visual Basic news group. It's slow, but you'll
    be able to get your answers.
     
    Branko Vukelic, Apr 4, 2004
    #6
  7. Thanks for your reply!

    The code I posted is not really well structured in terms of OO
    programming, I know. (And there is a lot of overhead in it as this
    displays a form with two buttons and stuff.) I am using Visual Studio
    ..NET (and VB.NET). The object browser [1] in VS.NET gives you
    information on which methods, properties, constants etc. are declared in
    those millions of class libraries you find in the .NET environment and
    other refereced libraries like the PhotoshopTypeLibary.

    The code I tried works for Photoshop 7.0, and the objects for Photoshop
    CS are pretty well documented on the Adobe website. But 7.0 seems to be
    different, and I can't find any reference guide.

    My problem now is, that I have no idea on how to address the layers in
    the file I opened. (I would like to get a text layer and change the text
    in there to automate the process of making lots of gifs or jpgs from a
    psd template which look the same but have different text on them.)

    I am now trying microsoft.public.vb.com, maybe someone over there can
    help. I am just wondering that this does not seem to be a standard
    problem on the web.

    When you're scrpting in InDesign, where do you "run" your scripts? (I
    figured that PS CS provides the possibility to execute scripts via the
    File>Scripts menu which I cannot find in 7.0.)

    Thanks,
    Michael

    PS: Maybe I am just thinking too complicated. Is there another approach
    to my problem???


    [1]
    http://msdn.microsoft.com/vstudio/productinfo/overview/academic/overview/default.aspx

    Object Browser Window

    Similar to the Class View window, the Object Browser dialog box shows
    you a list of classes and their respective properties and methods. The
    main difference between these two tools is the Object Browser allows you
    to browse all referenced components, not just the components for the
    current project like the Class View window does. A nice feature of the
    Object Browser is that it also shows you the full declaration for the
    method or property. To bring up the Object Browser, on the View menu,
    click Other Windows and then Object Browser.

    Tip If you wish to see components that are not referenced by your
    projects, you can add them using the "customize" button on the toolbar.
    They will not be added as references, only shown in the Object Browser
    for your convenience
     
    Michael Fuchs, Apr 5, 2004
    #7
  8. As for scripting, VBScript, JScript, Perl and some other scripts require
    only a scripting host running on your machine in order to be executable.
    That means that if you have a proper host, you can treat those scripts as
    executable files. VBScript and JScript are treated as Windows native, so
    there's no need to install anything separately.

    What I do is I fire up notepad, write the script and then save it as Unicode
    text file with .vbs or .js extension, thus making it executable. If you copy
    this script into the "Scripts" folder of any Adobe product, it can be
    exec'ed from the script pallette or whatnot.

    I find that scripts (as opposed to full apps that you make with VB6 or
    VB.NET) are much faster and allow many functions that are WSHost-based
    (supported natively by the scripting host) and not available implicitly in
    the VStudio package. (Like RegExps.)

    InDesign, Illustrator, InCopy, and Acrobat are fully scriptable. You can
    address all aspects of the apps from the scripts. But Photoshop seems to
    allow access only to the actions "engine", which is, IMO, enough to allow
    you much flexibility.

    What can you do?

    You can put the reference to the Photoshop app:

    Dim aaa As New PhotoshopTypeLibrary.PhotoshopApplication()

    i.e., "aaa" variable into Watch list. Place a break point just after the
    line I cited above. This will halt the execution when the parser reaches the
    line after this one, and you'll be able to view the contents of the "aaa"
    variable through the Watch window. I don't know about Photoshop, but when I
    was writing simple apps for InDesign, I used to be able to see the entire
    object model "live" (that is, with all the variables set and documents
    loaded, etc) through the Watch list.

    Hey, this is getting quite OT, don't you think? E-mail me at
    . I'll install the VStudio 98 in meantime and see
    what's in it.

     
    Branko Vukelic, Apr 5, 2004
    #8
  9. Michael Fuchs

    Animal Guest

    Hi, When writing Photoshop scripts in VB.Net, how and where do you
    find the Photoshop CS object library.

    I would greatly appreciate someone telling me what is the best way to
    read a pixel's color,

    What I want to do is open a file in PS, read a individuals pixel's
    color then reset it to another predefined color.

    Not that I have looked at the problem in great yet but on initial
    looking at the PS object library I wasnt sure which object to use.

    Does anybody have any good web links

    ( I have read the Photoshop web site regarding scripts for VB.Net)

    DW
     
    Animal, Apr 8, 2004
    #9
  10. You said you read the Adobe webpage on scripting - there you find the
    Photoshop CS Visual Basic Reference Guide, a list of all objects and
    their properties and methods.

    Or are you talking about actual programming: Reference the Photoshop
    library (in Visual Studio .NET: Right click on References -> Add
    Reference -> Change to the COM tab -> Select Adobe Photoshop 7.0/CS
    Object Library -> OK; then you can go through the objects in the Object
    Browser;)
    After having done that, you can use the objects; If you use early
    binding you even have the IntelliSense functionality in Visual Studio .NET.

    <snip>
    Dim appRef As New Photoshop.Application()
    Dim docRef As Photoshop.Document
    docRef = appRef.Documents.Add(4, 4)
    I do have the same problem, I could not find anything.
    -michael
     
    Michael Fuchs, Apr 11, 2004
    #10

  11. you can't do it directly. you need to 'export' a layer and then work on
    the bitmap in a separate memory array, then send it back to PS.

    it's too damn early right now for the full explanation.
    --JC
     
    James Connell, Apr 11, 2004
    #11
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.