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

Using .js scripts to launch Photoshop

New Here ,
Feb 24, 2010 Feb 24, 2010

Copy link to clipboard

Copied

Hi I'm kind of new to this Photoshops scripts field

and would like to  write an external application (.NET based) that would be able to invoke  the Photoshop application and run Photoshop .js scripts on it and then return the reply to some other external application.

I would like to now if and how it is possible to executes scripts  that  way? It is obvious that I could launch the Photoshop application by  calling the .exe file. But how do I run the script and retrieve data  such as status of the script, errors, etc.

Any  idea's???

Thanks

TOPICS
Actions and scripting

Views

6.4K

Translate

Translate

Report

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
Valorous Hero ,
Feb 24, 2010 Feb 24, 2010

Copy link to clipboard

Copied

If you are going to run external JavaScript from .NET you will not be able to get the details unless the script writes the details to a file and you read that. The alternative is to use .NET to talk to Photoshop direct, then you can get the results/errors and pass on the data to your other apps.

Votes

Translate

Translate

Report

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
Community Beginner ,
Feb 25, 2010 Feb 25, 2010

Copy link to clipboard

Copied

OK

But how can I do this? (use the .NET to invoke and operate Photoshop functions)

Do I need to use the SDK or are there other Photoshop API's that I can use?

Yair

Votes

Translate

Translate

Report

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
Valorous Hero ,
Feb 25, 2010 Feb 25, 2010

Copy link to clipboard

Copied

Here is an example of getting some details of an open document and putting the results in an Excel worksheet.

It also shows how to run JavaScript from within C# and how to show messages.

It's very basic but should get you started.

To get started you can dowload the FREE version of Microsoft® Visual C# :-

http://www.microsoft.com/express/Windows/

Create a new Console Application and paste in the following code..

using System;
using System.Runtime.InteropServices;
using Excel = Microsoft.Office.Interop.Excel;
using System.Windows.Forms;
using ps = Photoshop;

namespace PSexample
{
    public class PSdata
    {
        static void Main(string[] args)
        {
            ps.ApplicationClass app = new ps.ApplicationClass();
            app.Preferences.RulerUnits = ps.PsUnits.psPixels;
            ps.Documents doc_arr = app.Documents;
            if (app.Documents.Count == 0) return;
            double Width = app.ActiveDocument.Width;
            double Height = app.ActiveDocument.Height;
            double PixelCount = Width * Height;
            app.DoJavaScript("alert('Message from within Photoshop\\nTotal Pixels " + PixelCount + " ');", null, null);
            int mess = app.ActiveDocument.Layers.Count;
            MessageBox.Show("Document Name = "+app.ActiveDocument.Name, "PS Example");
            MessageBox.Show("This document has "+Convert.ToString(mess)+ " layers","PS Example");
            Excel.Application app2 = new Excel.ApplicationClass();
            app2.Visible = true; //change to false when tested
            var excelWorkbook = app2.Workbooks.Add(VarEnum.VT_NULL);
            app2.ActiveCell.set_Value(Excel.XlRangeValueDataType.xlRangeValueDefault, " ");     
                app2.Cells[1, 1] = app.ActiveDocument.Path;
                app2.Cells[1, 2] = app.ActiveDocument.Name;
                app2.Cells[1, 3] = Width;
                app2.Cells[1, 4] = Height;
                app2.Cells[1, 5] = app.ActiveDocument.Layers.Count;
        }
    }
}

You now need to add a couple of COM references one for Photoshop and one for Excel.

On the menu bar select Project - Add Reference -Select The COM tab

Now select the COM object..

Adobe Photoshop CS# Object Libary          //CS# depends on what version of Photoshop you want to use (This is the API)

Microsoft Excel 12.0 Object Library          // The Number may be different depending on your version of Excel

Now select .NET tab and select

System.Windows.Forms

With a document open in the CORRECT version of Photoshop you can run the script from C# by pressing the F5 function key.

Hope this helps.

Votes

Translate

Translate

Report

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 ,
Jun 06, 2013 Jun 06, 2013

Copy link to clipboard

Copied

Hi,

Any help is highly appreciated.

I had develop external application (c# application ) that list all opened photoshop files.

Issues I am facing:

1) Different photoshop version needs different interop.photoshop.dlls

2) depend on the computers i.e few computers worked and few not

3) Also dependent with the photoshop bit version

Questions:

1) Is there a single interop.photoshop.dll for all versions and 32/64 bit versionsof photoshop?

2) how to make workable to all photoshop versions?

Thanks,

Biran

Votes

Translate

Translate

Report

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
Valorous Hero ,
Jun 06, 2013 Jun 06, 2013

Copy link to clipboard

Copied

I don't think you can. One way would be to call a VBScript  and get it to write the details to a file, then read that.

Votes

Translate

Translate

Report

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 ,
Jun 06, 2013 Jun 06, 2013

Copy link to clipboard

Copied

Thanks Paul.

I am using C# language.

ya I researched more to use single interop for all versions of photoshop, but im not success.

so loaded interop on one by one trying to access applicationclass, I had interop files from CS1 to CS6.

But Again there is another problem, that is these interop not worked on all computers I have, I used to test on minimum 10 computers.

some of them work and some of them not, I am confused about how this happens.

Is there any factors causing problem of not working on all computers?

Please let me know that if there is any possibilities of listing opened psd files from photoshop software best on c# language.

I just want to list all opened psd files from photoshop that work for all photoshop version along with their bit versions

Votes

Translate

Translate

Report

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
Valorous Hero ,
Jun 06, 2013 Jun 06, 2013

Copy link to clipboard

Copied

You could get the number of open files via most of the Adobe applications Illustrator, Indesign etc. using BridgeTalk but you will still have the problem of a different interop for each version.

I know there were problems with some registry entries not been present and the fix was to run Photoshop as Admistrator (Just the once so that the registry entries could be updated) It would be worth a try to see if it fixs the problem PCs.

The only way I can think of to get the number of opened files would be to call a script jsx/vbs etc. to write the information to a file.

Votes

Translate

Translate

Report

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 ,
Jun 07, 2013 Jun 07, 2013

Copy link to clipboard

Copied

Is there any way to find the photoshop version with CSharp from photoshop process details?

If I able to find the photoshop version like cs1 to cs6, I can use interop to solve my problems

Votes

Translate

Translate

Report

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
Valorous Hero ,
Jun 07, 2013 Jun 07, 2013

Copy link to clipboard

Copied

If you can get the path of the running Photoshop process, you might be able to tell which version is running?

Votes

Translate

Translate

Report

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 ,
Jun 07, 2013 Jun 07, 2013

Copy link to clipboard

Copied

LATEST

Ya I got the photoshop version, I will implement and will publish result

Votes

Translate

Translate

Report

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