3 Replies Latest reply on Nov 19, 2011 6:52 AM by Paul Riggott

    Detecting open images or force close through script

    Perarg513

      Hello,

       

      i would like to find a way to force closing all opened images if there is any opened. So i should find a way to detect if one or more images are opened and then force closing them. I need to use it in a C# application. Is there any way to do that with scripting or any other way ??

       

      Thank you very much

        • 1. Re: Detecting open images or force close through script
          Paul Riggott Level 6

          This how it's done in JavaScript..

           

           

          while (app.documents.length) { 
              app.activeDocument.close(SaveOptions.DONOTSAVECHANGES); 
          }
          
          

          In c# you could run the code with a app.DoJavaScript();

          1 person found this helpful
          • 2. Re: Detecting open images or force close through script
            Perarg513 Level 1

            That may be correct. Thank you very much

             

            I use late binding in C# and i am searching a way to get app.documents or app.DoJavaScript() method. Any idea ?

            • 3. Re: Detecting open images or force close through script
              Paul Riggott Level 6

              Sorry but I don't use C# that much and don't know what "late binding" means.

               

              Here is an example that works for me...

               

               

              using System;
              using System.Collections.Generic;
              using System.Linq;
              using System.Text;
              using ps = Photoshop;
              using System.Windows.Forms;
               
               
              namespace Photoshop_Test
              {
                  class Program
                  {
                      static void Main(string[] args)
                      {
                          string Code = "while (app.documents.length) {app.activeDocument.close(SaveOptions.DONOTSAVECHANGES);}";
                          ps.Application app = new ps.ApplicationClass();
                          ps.Documents doc_arr = app.Documents;
                          MessageBox.Show(app.Documents.Count.ToString(),"Number of open documents");
                          String RC = app.DoJavaScript(Code, null, null);
                          MessageBox.Show(app.Documents.Count.ToString(), "Number of open documents");
                      }
                  }
              }