3 Replies Latest reply on Jan 27, 2013 6:06 AM by Muppet Mark

    Layers prototype?

    Silly-V Adobe Community Professional

      I am looking to learn something new because I have been at my wits' end trying to add a prototype to the Layers object so I can do something like try{ .getByName(name) catch{ return null.   For when the named layer doesn't exist.  (It gives an error for me in CS5). So unfortunately me trying to go Layers.prototype. my method  doesn't seem to work at all.  Anyone have insights?

        • 1. Re: Layers prototype?
          CarlosCanto Adobe Community Professional & MVP

          I think I read somewhere, I guess it was a the Indesign forum that native objects can't be extended, you can only do that with your own objects.

           

          can't you do the same with try-catch the way you have it?

          • 2. Re: Layers prototype?
            Silly-V Adobe Community Professional

            Yes that's what is going on I suppose.  Having gotten home and looked at the data browser on Windows, it shows the "_proto_" with a circle-strike-through icon next to it, does that confirm you're not supposed to be able to extend this?

             

            Well, next best thing is doing this which seems to work:

             

            Document.prototype.layerLook=function(what){

                try{

                    return this.layers.getByName(what);

                } catch(e){

                    return null;

                }

            };

             

            Document.prototype.layerLook_lvl2=function(where,what){

                try{

                    return this.layers.getByName(where).layers.getByName(what);

                } catch(e){

                    return null;

                }

            };

            • 3. Re: Layers prototype?
              Muppet Mark Level 5

              To be honest I don't prototype objects myself… I've seen mixed responces on wether this is a good or bad thing… So I've just kept clear… I do know that you can prototype objects in Photoshop but in order to do it you need to access the object before prototyping it… It may be the same with AI but I have not tried any tests… In PS you make a variable to the object class to load it only then can it be prototyped… Kind of…

               

              var lay = app.activeDocument.activeLayer;