• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Layers prototype?

Valorous Hero ,
Jan 24, 2013 Jan 24, 2013

Copy link to clipboard

Copied

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?

TOPICS
Scripting

Views

759

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe
Community Expert ,
Jan 24, 2013 Jan 24, 2013

Copy link to clipboard

Copied

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?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Valorous Hero ,
Jan 25, 2013 Jan 25, 2013

Copy link to clipboard

Copied

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;

    }

};

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guru ,
Jan 27, 2013 Jan 27, 2013

Copy link to clipboard

Copied

LATEST

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;

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines