9 Replies Latest reply on Apr 21, 2011 5:57 PM by Suchys

    Working with Guides using ActionScript in Photoshop

    Suchys

      I am facing some troubles when working with Guides in Photoshop (AS/Flash extension)

       

      Let's create guides showinglayer bounds:

                      var bounds:Array = activeDocument.activeLayer.bounds;
                      var guide_a:Guide = activeDocument.guides.add(Direction.VERTICAL, bounds[0]);
                      var guide_b:Guide = activeDocument.guides.add(Direction.HORIZONTAL, bounds[1]);
                      var guide_c:Guide = activeDocument.guides.add(Direction.VERTICAL, bounds[2]);
                      var guide_d:Guide = activeDocument.guides.add(Direction.HORIZONTAL, bounds[3]);

       

      This works fine. Layer bounds are marked correctly.

      If I try to remove individual guides, I am facing an issue:

                      guide_a.remove();
                      guide_b.remove();
                      guide_c.remove();
                      guide_d.remove();

       

      PS starts throwing strange errors:

      Error: General Photoshop error occurred. This functionality may not be available in this version of Photoshop.
      - The object "guide 8 of document 35" is not currently available.

      It is not clear, what document 35 really means (it is not name of actual document .. internal name?). Also interesting that remove() is not availabel in JavaScript API's.

       

      Also if I try to bind on "coordinate" property of Bound, no changes seems to be propagated.

      Any idea?

      Thanks,

      --Petr

        • 1. Re: Working with Guides using ActionScript in Photoshop
          zak.nelson Level 3

          Petr,

           

          Yea that feels like a bug to me. You can even pare down your example to:

           

          var guide_a:Guide = activeDocument.guides.add(Direction.VERTICAL, bounds[0]);

          guide_a.remove();

           

          I've filed a bug on the issue. In the meantime you can use the workaround (which seems to work for me):

           

          var guide_a:Guide = activeDocument.guides.add(Direction.VERTICAL, bounds[0]);

          activeDocument.guides.index(0).remove();

           

           

          For your other question. Binding is not going to work on CSAW objects. To get the behavior you're looking for, listen for the appropriate PS event and then update Bindable properties you've defined in your application.

           

          Zak

          1 person found this helpful
          • 2. Re: Working with Guides using ActionScript in Photoshop
            Suchys Level 1

            Thanks. Does guide fire any event?

             

            Well some more observation. I need to remove guide by reference, if I do by index, I can mess up guides if user made some changes meanwhile. When trying to do something around, I probably found couple more issue, at least one is well reproducible:

                            guides = new Array();                           
                            guides[0] = activeDocument.guides.add(Direction.VERTICAL, bounds[0]);

            //the guide stored here in array returned by add(..) has direction = null and coordinate == null


                            guides[0] = activeDocument.guides.index(activeDocument.guides.length - 1);

            //here I asked immediatelly again, here by last index, whoaa, direction and coordinate have correct values.

             

            I keep going on,

            --Petr

            • 3. Re: Working with Guides using ActionScript in Photoshop
              Suchys Level 1

              Zak,

              Here are more questions:

              - I can toggle guides visibility by this code app.runMenuItem(charIDToTypeID("Tgld"));, but am I able to seek if guides are currently on/off anyhow?

              - Is there a way to attach listener on guide coordinate value? Seems like HostObject maybe right one, but I am not sure how to investigate event name.

              --Petr

              • 4. Re: Working with Guides using ActionScript in Photoshop
                zak.nelson Level 3

                Yes it definitely looks like there is a problem with the reference returned by add(). Looks like you can work around it though by getting the guide by reference immediately after adding it using the known index.

                 

                For your question about events. The easiest way to see if there is some event you can listen for is to use the ScriptListener in Photoshop. With that, you can quickly see whether or not an event fires when you expect (there may not be one available to scripting). Once you know the event fires, you can add the handler, using this as a reference: http://cssdk.host.adobe.com/sdk/1.0/docs/WebHelp/app_notes/photoshop.htm.

                 

                I don't see a clear way to check the visibility of guides. Although there may be some magic you can do using descriptors. Maybe we'll get some help from a real Photoshop scripting expert

                 

                Zak

                1 person found this helpful
                • 5. Re: Working with Guides using ActionScript in Photoshop
                  Suchys Level 1

                  Zak,

                  Scripting listener my old friend, but for such cases, it is silent (and useless). Investigating C++ headers sometimes gives you more info, but for this case, I am almost lost. Only thing I have in my mind is (guide as CSHostObject).hostObjectDelegate.addEventListener(....) but what should I listen for?

                  Also Guides are strange - if I dump entire ActionDescriptor for everything in Photoshop, nothing is recorded for Guides - they seems to stored only in file and probably some private property, but not exposed anywhere even for low level access. But I can be mistaken.

                  --Petr

                  • 6. Re: Working with Guides using ActionScript in Photoshop
                    zak.nelson Level 3

                    I see. Unfortunately I don't think using CSHostObject.addEventListener will get you anywhere currently.

                     

                    If you are catching the event from the C++ layer then you could send the event to the ActionScript layer using CSXS events. This post has a little information: http://forums.adobe.com/thread/725049, essentially you'll need the native application toolkit.

                    • 7. Re: Working with Guides using ActionScript in Photoshop
                      Bob Stucky Adobe Employee

                      I've got a "Event Watcher" extension that allows developers to see what events fire and when.

                       

                      Lemme see if I can get that turned into a cookbook example or something in the next day or two.

                       

                      Regards

                      • 8. Re: Working with Guides using ActionScript in Photoshop
                        Suchys Level 1

                        Not yet, but it may be comming. Thanks

                        • 9. Re: Working with Guides using ActionScript in Photoshop
                          Suchys Level 1

                          Thanks, this can be really useful.

                          --Petr