4 Replies Latest reply on Jul 28, 2017 12:28 PM by SuperMerlin

    Opening a document from a different application

    i73 Level 1

      Originally I wrote a C++ SDK plugin that would contain a external function that would open a document, the problem is I'm unable to pass or get the Photoshop memory address (Application) from a .dll for me to use sSPBasic suite, to open a document.

       

       

      So I am looking for a way to do it with JS, I just need to open a document from C# OpenDocumentInPhotoshop("FilePath"). But I have a few questions, I have not used Javascript too much, so I don't know the limitations.

       

       

      1. Would I be able to invoke a Open document function from C# either with command line or some other pipe?

      2. Does PS treat scripts like plugins? Do they have to be triggered or can they be fired off anytime?

      3. Does this sound possible?

       

        • 1. Re: Opening a document from a different application
          SuperMerlin Level 5

          I haven't done much with c# but...

          Basics  C sharp:-

          dynamic app = Activator.CreateInstance(Type.GetTypeFromProgID("Photoshop.Application"));

          app.Load(@"D:/pictures/fileName.jpg");

           

          This is late binding so will select the latest version of Photoshop.

          Yes you should be able to pass the file path via args.

          • 2. Re: Opening a document from a different application
            i73 Level 1

            SuperMerlin, I spent 6 hours trying to pipe this in with c++ and all it took was you. Man I owe you a beer, thank you so much! Take care!!!

            • 3. Re: Opening a document from a different application
              i73 Level 1

              SuperMerlin I have a follow up question for you, how did you end up getting the COM from Photoshop, was there documents on it?

               

              Thanks again!

              • 4. Re: Opening a document from a different application
                SuperMerlin Level 5

                I,am not sure what you are asking here, using "Late Binding" dosen't use COM in the normal way, it is more akin to JavaScript so there is no auto completing of code and No Interop DLL is required.

                It also only selects the latest version.

                I.E:-

                if (app.Documents.Count == 0) return;

                MessageBox.Show(app.ActiveDocument.ActiveLayer.Name);

                You can use script listen code with some slight modifcations ...

                 

                MessageBox.Show(isVis().ToString());

                 

                /// <summary>

                        /// returns if active Layer is visible

                        /// </summary>

                        /// <returns></returns>

                        static Boolean isVis()

                        {

                            dynamic app = Activator.CreateInstance(Type.GetTypeFromProgID("Photoshop.Application"));

                            ps.ActionReference ref1 = new Photoshop.ActionReference();

                            ref1.PutEnumerated(app.CharIDToTypeID("Lyr "), app.CharIDToTypeID("Ordn"), app.CharIDToTypeID("Trgt"));

                            return app.ExecuteActionGet(ref1).GetBoolean(app.CharIDToTypeID("Vsbl"));

                        }

                 

                Sorry if I have got it totally wrong.

                Edit:- I have a couple of helper files to help with conversion from scriptListner to COM format or Late Binding format.

                Wikisend: free file sharing service