7 Replies Latest reply on Nov 14, 2010 11:49 AM by DBarranca Branched to a new discussion.

    Channel operations (porting ES to AS)

    DBarranca Level 4

      Hello,

      I'm having troubles porting some ExtendScript code to ActionScript.

       

      I duplicate a channel, rename it, and apply Median filter. Easy task in ES:

       

      var myDoc = app.activeDocument;

      var myChannel = myDoc.channels[0].duplicate();

      myChannel.name = "Median"

      myChannel.applyMedianNoise (5);

       

      In AS I'm stuck here:

       

      var app:Application = Photoshop.app;

      var myDoc:Document = app.activeDocument;

      var myChannel:Channel = myDoc.channels.index(0).duplicate();

      myChannel.name = "Median"

       

      and I don't know how to apply a filter to it, because
      myChannel.applyMedianNoise(5)
      throw this error:
      1061: Call to a possibly undefined method applyMedianNoise through a reference with static type com.adobe.photoshop:Channel.
      As far as I know, I can apply filters only to ArtLayers, for instance in a different code section I've learnt to cast a Layer with "as":

      var myLayer:ArtLayer = docRef.activeLayer as ArtLayer;

       

      There's probably something similar for channels: I did some naive tries:

       

      (myChannel as ArtLayer).applyMedianNoise(5)

       

      or

       

       

      var goo:ArtLayer = max as ArtLayer;

      goo.applyMedianNoise(5);

       

       

      they don't throw any error, but don't do anything either.
      So... what's the correct syntax?
      Thanks in advance,
      Davide Barranca
        • 1. Re: Channel operations (porting ES to AS)
          Michael L Hale Level 5

          The javascript you posted will also throw an error becase applyMedianNoise is not a channel method. With js you need to do something like this.

           

          var myDoc = app.activeDocument;

          var myChannel = myDoc.channels[0].duplicate();// makes the duped channel the only active channel

          myChannel.name = "Median"

          myDoc.activeLayer.applyMedianNoise (5);// because the duped channel is the only one active the filter is applied only to it.
          // you may want to restore the activeChannels to the component channels i.e for RGB

          myDoc.activeChannels = [myDoc.channels[0],myDoc.channels[1],myDoc.channels[2]];// make the RGB channel active

           

          Not sure how that ports to AS, but the key is applyMedianNoise is a layer method. You can work with seperate channels if needed by making them active before calling the filter.

          • 2. Re: Channel operations (porting ES to AS)
            DBarranca Level 4

            Hi Michael,

            you're right, I took that code excerpt from a script that actually contained the activeLayer that you mention.

             

            I still have to understand how to port properly in AS - which is a picky language.

            Documentation for JS is extended, I hope Adobe will integrate AS in the Scripting Guide soon - since I'm far from being the best coder in town, I'm having some hard times ;-)

             

            Thanks for your answer anyway,

             

            Davide

            • 3. Re: Channel operations (porting ES to AS)
              c.pfaffenbichler Level 9

              Edit:

              I hope Adobe will integrate AS in the Scripting Guide soon

              Say what?

              »Photoshop CS5 Scripting Guide.pdf« does contain AS-examples and »Photoshop CS5 AppleScript Ref.pdf« doesn’t seem to shabby either.

               

              Sorry, I understood AS to mean AppleScript, when you are talking about ActionScript – my mistake.

              • 4. Re: Channel operations (porting ES to ActionScript)
                DBarranca Level 4

                Sorry for the misunderstanding!!

                 

                AS in my intention should mean ActionScript for use with the new CS SDK, not AppleScript...

                Best,

                 

                Davide

                • 5. Re: Channel operations (porting ES to AS)
                  c.pfaffenbichler Level 9

                  My bad, I had read your original post inattentively.

                  • 6. Re: Channel operations (porting ES to ActionScript)
                    Harbs. Level 6

                    What I do when I bump into in a part of the DOM which does not translate well into strongly typed ActionScript, is ususally to just throw in the towel...

                     

                    I create an ExtendScript function to do the work and imbed it. I then call the ExtendScript function using jsxInterface.doSomethingTheEasyWay().

                     

                    Harbs

                    1 person found this helpful
                    • 7. Re: Channel operations (porting ES to ActionScript)
                      DBarranca Level 4

                      Thanks Harbs,

                      this makes perfect sense

                       

                      I don't think I will fall in love with AS3. Here is the workaround I've found:

                       

                      var app:Application = Photoshop.app;

                      var myDoc:Document = app.activeDocument;

                      var myChannel:Channel = myDoc.channels.index(0).duplicate();

                      myChannel.name = "Median";

                      var myChannelBis:ArtLayer = myDoc.activeLayer as ArtLayer;

                      myChannelBis.applyMedianNoise(5);

                       

                      that is, a new variable will contain the channel (as activeLayer) as ArtLayer.

                       

                      Davide as AS newbie