Photoshop activeDocument

I am writing Photoshop in ActionScript 3.

I have a very confusing and annoying problem with app.activeDocument. My code works fine with Photoshop for Windows, but on Mac I get "General Photoshop errooccreded. This functionality may not be available in this version of Photoshop." mistake.

To try and get to the root of the problem, I wrote a class to get a link to the document and called it from the test panel. The cool call worked great. Then I included the same class in my main panel project and it breaks.

This is my class: -

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

    public class DocRefPhotoshop
    {

        public static function getDocRef():Document
        {
            var app:Application = Photoshop.app;

            var thisDoc:Document = app.activeDocument;
            //var thisDoc:Document = app.documents.index(0);  //Tried this method too

            return thisDoc;

        }
    }
}

      

For posting here, I've simplified a bit, i.e. I've removed things like "try, catch", but essentially this is code that doesn't work in the context of my panel. I also tried an equivalent JSX call with exactly the same result, worked great on Windows, worked in a test panel on a Mac, wouldn't work in my main project on a Mac.

As I said, inside the test it works fine. Here is the mxml test code: -

<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" historyManagementEnabled="false">
    <mx:Script>
        <![CDATA[
            import DocRefGetter.DocRefPhotoshop;

            import com.adobe.photoshop.Document;

            [Bindable]
            private var hostName:String = HostObject.mainExtension;

            protected function button1_clickHandler(event:MouseEvent):void
            {
                var thisDocRef:Document = DocRefPhotoshop.getDocRef();
                testLabel.text = String(thisDocRef);
            }

        ]]>
    </mx:Script>
    <mx:VBox height="100%" width="100%" verticalAlign="middle" horizontalAlign="center">
        <mx:Button label="Run PS code" click="button1_clickHandler(event)" />
        <mx:Label id="testLabel" width="182" text="Label"/>
    </mx:VBox>
</mx:Application>

      

I cannot post the main application in which it does not work as it is very large and complex, so I ask if anyone, having run into the situation before, is there something conflicting with this type of document links? I've been trying to fix this issue for over a week now. I tried many different solutions but nothing worked. Mac Photoshop just doesn't want to see an open document.

Any suggestions are greatly appreciated, but I hope most of all someone has come across this specific situation before and has an exact solution.

Thanks so much for your concern to take a look at this.

+3


source to share


1 answer


so what I'm asking is, does anyone run into a situation before something conflicts with this type of document links somewhere?

Use one of the following checks:

  • Is docref null

    ?

  • Is the document loaded asynchronously?

  • Is the document large enough to warrant a timeout?



Links

0


source







All Articles