1 Reply Latest reply on Jun 14, 2011 2:04 AM by ABergman22

    I need help accessing documents in Photoshop CS5 Win

    ABergman22

      Hello,

      Photoshop is crashing when I do multiple calls to a function using the documents member of Photoshop.app.

      One or more images has to be open in PS.

       

      With one or more images open in PS this simple extension crashes PS when the button is pressed:

      main.mxml

      <?xml version="1.0" encoding="utf-8"?>
      <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" historyManagementEnabled="false">
      <mx:Script>
      <![CDATA[
        [Bindable]
        private var hostName:String = HostObject.mainExtension;  
      ]]>
      </mx:Script>
      <mx:VBox height="100%" width="100%" verticalAlign="middle" horizontalAlign="center">
      <mx:Button label="Run PS code" click="HelloWorldPhotoshop.run()" enabled="{hostName.indexOf('photoshop') > -1}"/>
      </mx:VBox>
      </mx:Application>

      HelloWorldPhotoshop.as

      package
      {
      import com.adobe.csawlib.photoshop.Photoshop;
      import com.adobe.photoshop.*;

      public class HelloWorldPhotoshop
      {
        public static function run():void
        {
         doSomeStuff();
         doSomeStuff();
        }
        public static function doSomeStuff():Boolean
        {
         var app:Application = Photoshop.app;
         var docs:Documents = app.documents;
         var doc:Document;
         for each (doc in docs)
         {
          if (doc.fullName)
          {
           return true;
          }
         }
         return false;
        }
       
      }

      The "if (doc.fullName)" line is important. Without this line, there is no crash.

      Thanks for any help.

      Anders