5 Replies Latest reply on Feb 17, 2013 11:36 PM by starjohn2

    script not working in cs6, after working in cs5

    starjohn2

      Hello,

       

      I have a script and when I try to access app.documents.length

      or app.documents[0] or app.activeDocument

       

      then I get the error:

      General photoshop error occurred. This functionality may not be available in this version of Photoshop

      - <no additional info is available>

       

      any idea ?

       

      Thanks

        • 1. Re: script not working in cs6, after working in cs5
          Paul Riggott Level 6

          As you haven't posted any code it is impossible to say what is wrong.

           

          app.document; or app.documents[0]; will always give you an error if there are no documents open.

          What I normally do is to check if any documents are open I.E.

           

          #target photoshop
          main();
          function main(){
          if(!documents.length) return;
          //do what you have to do
          };
          
          
          • 2. Re: script not working in cs6, after working in cs5
            starjohn2 Level 1

            Thanks Paul,

             

            My script is like this:

             

            /*
            <javascriptresource>
            <name>$$$/JavaScripts/ExportGeotiff/Menu=Export Geotiff...</name>
            <about>$$$/JavaScripts/ExportGeotiff/About=Export Geotiff ^r^rCopyright 2011 Company. All rights reserved.^r^rExports document into a Geotiff image.</about>
            </javascriptresource>
            */

             

            try
            {

            alert("OK HERE");
            exportGeoTiff();
            }


            catch(err)
            {
            alert(err.description);
            }

            function exportGeoTiff()
            {
            if (app.documents.length == 0) //***** CRASHES HERE
              error("No document to export.");

            var scriptPath = getScriptPath();
            var geotifcp = getGeotifcp(scriptPath);
            var doc = app.activeDocument;
            var geo = getGeoInfo(doc);
            var inputGeoFile = saveGeoInfo(scriptPath, geo);
            var file = saveDoc(doc);
            var inputTiffFile = prepareInputTiff(scriptPath, file);
            var outputTiffFile = runGeotifcp(geotifcp, scriptPath, file);

            inputTiffFile.remove();
            inputGeoFile.remove();
            outputTiffFile.remove();
            }

             

            function error(err)
            {
            throw new Error(err);
            }

             

            function getScriptPath()
            {
            var path = "C:\\Program Files (x86)\\Company\\Common\\Maps\\";
            var folder = Folder(path);
            if (!folder.exists)
              path = "C:\\Program Files\\Company\\Common\\Maps\\";
            folder = Folder(path);
            if (!folder.exists)
              error("Could not find map common folder.");
            return path;
            }

             

            function getGeotifcp(path)
            {
            var geotifcp = File(path + "geotifcp.cmd");
                if (!geotifcp || !geotifcp.exists)
              error("Could not find geotifcp utility.");
            return geotifcp;
            }

             

            function getGeoInfo(doc)
            {
            var raw = doc.xmpMetadata.rawData;
            var tag = "xmpMM:RenditionParams>";
            var geo = raw.substring(raw.indexOf("<" + tag) + tag.length + 1, raw.indexOf("</" + tag));
            if (!geo || (geo.length == 0))
              error("Document has no Geo-Reference information. Export cancelled.");
            //escape XML:
                geo = geo.replace(/&#xA;/g, "\r\n");
            return geo;
            }

             

            function saveGeoInfo(path, geo)
            {
            var inputGeoFile = File(path + "input.geo");
                if (!inputGeoFile)
              error("Could not create geo input file.");
            if (!inputGeoFile.open("w"))
              error("Could not open geo input file.");
            if (!inputGeoFile.write(geo))
              error("Could not write to geo input file.");
            if (!inputGeoFile.close())
              error("Could not close geo input file.");
            return inputGeoFile;
            }

             

            function saveDoc(doc)
            {
            var file = File.saveDialog("Save As", "Tiff:*.tif");
            if (!file)
              error("Save cancelled");
            doc.saveAs(file, new TiffSaveOptions(), true, Extension.LOWERCASE);
            if (file.length == 0)
              error("Saving to tiff failed. Export cancelled.");
            return file;
            }

             

            function prepareInputTiff(path, file)
            {
            var inputTiffFile = File(path + "input.tif");
                if (!inputTiffFile)
              error("Could not create input file.");
            if (inputTiffFile.exists)
              if (!inputTiffFile.remove())
               error("Could not delete input file.");
            if (!file.copy(inputTiffFile.fsName))
              error("Could not copy image to input file.");
            if (!inputTiffFile.exists)
              error("Problem copying image to input file.");
            return inputTiffFile;
            }

             

            function runGeotifcp(geotifcp, path, file)
            {
            if (!geotifcp.execute())
              error("Failed adding geo info to tiff.");
            $.sleep(1000);//let geotifcp finish
            var outputTiffFile = File(path + "output.tif");
                if (!outputTiffFile || !outputTiffFile.exists)
              error("Could not create geotiff file.");
            if (!outputTiffFile.copy(file.fsName))
              error("Failed replacing tiff image with Geotiff version.");
            return outputTiffFile;
            }

            • 3. Re: script not working in cs6, after working in cs5
              Paul Riggott Level 6

              It sounds as if your preferences are screwed, I would try resetting them and trying again.

              http://forums.adobe.com/thread/375776

              • 4. Re: script not working in cs6, after working in cs5
                shashank saxena Level 2

                Hi.

                Its easy  press n hold

                ctrl + shift + alt and launch your ps

                when prompted please

                delete your setting file.

                It will be resolved

                • 5. Re: script not working in cs6, after working in cs5
                  starjohn2 Level 1

                  Thanks Paul and Shashank! I resetted the preferences and it works now

                   

                  Hope this will be fixed in the next release of photoshop or a better error message will show