How to remove each layer except the selected layer?

Hello

I would like to delete all layers including the background sets and layer except for the selected layer.

It seems easy to first, but it stops... I tried in several ways; What I am doing wrong?

#target photoshop
cTID = function(s) { return app.charIDToTypeID(s); };
sTID = function(s) { return app.stringIDToTypeID(s); };

app.bringToFront();
var doc = app.activeDocument;
var currentLayer = doc.activeLayer; // remember the selected layer
var selectedlayername = currentLayer.name;
currentLayer.move( activeDocument, ElementPlacement.PLACEATBEGINNING );  

  function DeleteLayer(layername) {  var desc1 = new ActionDescriptor();
    var ref1 = new ActionReference();   ref1.putName(cTID('Lyr '), layername);
    desc1.putReference(cTID('null'), ref1);     var list1 = new ActionList();
    list1.putInteger(17);  desc1.putList(cTID('LyrI'), list1);  executeAction(cTID('Dlt '), desc1, DialogModes.NO);
  };

function DeleteBackground() { var desc1 = new ActionDescriptor();  var ref1 = new ActionReference();   ref1.putProperty(cTID('Lyr '), cTID('Bckg')); desc1.putReference(cTID('null'), ref1);     var list1 = new ActionList();     list1.putInteger(1);   desc1.putList(cTID('LyrI'), list1);    executeAction(cTID('Dlt '), desc1, DialogModes.NO); };

function initial () {
for(var i = 0 ; i < doc.layers.length;i++){    if (doc.layers[i].isBackgroundLayer == true ) {  DeleteBackground();} }
var layerNum = doc.layers.length;
for(var  s = 1 ; s <= layerNum;s++){
   if ( doc.layers[s].name != selectedlayername ) {   
       DeleteLayer (doc.layers[s].name);
       }
   else if ( doc.layers[s].name == selectedlayername ) {
       }
   }
}

initial();

Thank you

Best regards.

Hi arteangelus,

Try this Code...

#target photoshop
var docRef = app.activeDocument;
var layName = docRef.activeLayer.name
var l = Number(docRef.layers.length)+1;
while(--l){
    if(docRef.layers[l-1].name!=layName && docRef.layers[l-1].name!="Background"){
        docRef.layers[l-1].remove();
    }
else{continue;}
}

-yajiv

Tags: Photoshop

Similar Questions

  • How to remove a city from the weather app in IOS 9.2.1?

    I have an IPhone6S that I bought recently and am running IOS 9.2.1. I can't understand how to remove a city from the weather app. I tried to go to settings, where there is a list of all the applications on my phone except the weather app, so no help there. Any body can help me with this?

    You must tap on the small set of lines in the lower right to get list view. Then you can find the city that you want to delete, drag to the left to see the button Delete.

    See you soon,.

    GB

  • How to remove a page of the PDF document?

    How to remove a page from the PDF?

    Tools > Pages > delete

    Select that range from the page to remove

    Click on the OK button

  • How to remove a user from the application

    How to remove a user from the EBS application?

    12.1.3 R

    Hello

    You can put an end to the user date

    Connect to Oracle Applications - select the responsibility of the system administrator - security - user - define - query with the username - and then you can give the end date in the effective Date column.

  • How to remove unused objects from the webcatalogs?

    Hi friends,

    How to remove unused objects from the webcatalogs?
    is there a utility like the removal of unused objects of the physical layer in RPD?

    Thank you

    Hello

    Click link responses to the left of the answers click on the catalog button manage manage catalog, you can delete the unused objects

    Concerning

    NGO

  • How to remove a Word from the default dictionary of firefox?

    How to remove a Word from the default dictionary of firefox?
    If I wanted to remove the word 'dog' or 'and' for example

    There may be a range of reasons for wanting to do this, including the deletion of the words you use rarely as similar to other common spellings used words for example. "minute" and "Minuet", delete the words that you find personally offensive, or removing words that, because of linguistic or cultural background, you would not consider words at all.

    Note that I'm not asking how to remove my 'dictionary' words, words that I added myself.

    Hello

    I talked to a few people and I think I'm able to help you with this.

    There are two dictionary files, the default that comes with your version of Firefox and personal 'custom' that you create yourself with phrases and words.

    If you want to change the personal;

    1. Copy Subject: support and paste into the address bar.
    2. Next to the profile folder, click the marked File Show
    3. Find the file persdict.dat. Rename a text file, open, modify, re save it as persdict.dat and replace.

    If you want to change the default dictionary, it could be more of a problem and a lot more technique to do. I would recommend that you look at the problem differently and consider filtering of pages based on inappropriate content using Add-ons such as ProCon Latte Content Filter.

    I hope this helps, but if not, please come back here and we can look at another solution for you.

  • If time machine is incremental how it removes previous versions when the disk is full, without breaking the chain, so do not be able to restore all changes since the first full file

    If time machine is incremental how it removes previous versions when the disk is full, without breaking the chain, so do not be able to restore the file with any changes made since the full backup first file...

    If the TM drive storage is full TM automatically deletes the version the oldest files for the new incremental backups can be made. Thus, in this case you cannot restore the versions that TM deleted because it takes more storage.

  • How to remove "Skype available" from the top of the notification page?

    How to remove "Skype available" from the top of the notification page - useless promotion!

    Hello!

    Disable the Skype status under Notification settings in Skype.

    All best
    Siim

  • How to remove a shortcut with the command line?

    How to remove a shortcut with the command line?

    How to make a backup of the local users and groups with command line?

    You delete a shortcut, just as you would remove any other file.  A shortcut will end with the extension ".lnk".  So assuming you are trying to remove the shortcut named "Shortcut.lnk" which appears to the user 'Bob's Office, you use the button Delete (del) or 'clear' command by specifying the full path to the file.  (Remember to put filename in quotes if there is a space anywhere in the path or name) as in:

    del "C:\documents and settings\Bob\Desktop\Shortcut.lnk".

    What kind of a backup 'users and groups' you want to do?  If there is a backup of the users and groups as written in the registry, a good registry as C:\WINDOWS\ERUNT backup program that will make the command line.  If you are trying to backup all users and their data as well, then you are better off with a backup program.

    HTH,
    JW

  • How to remove all information from the computer so I can sell it?

    How to remove all information from the computer so I can sell it?

    Hello

    You will want to format the hard disk:

    1. you can use DBAN - http://www.dban.org/

    or

    2. you can follow this tutorial to clean install up to the step where you format the disk, in which you would then STOP (because you just want to get rid of the files on the hard drive, do not install Windows) - http://www.sevenforums.com/tutorials/1649-clean-install-windows-7-a.html

    Kind regards

    Patrick

  • How to change each color of the illustrator vector object in 2013 of PowerPoint?

    When my client want different colors on vector graphical objects in PowerPoint.

    For example, I created graphics in Adobe Illustrator CS6 element, and then save as .emf file with color RGB, once exported mode then I insert the image from that file in PowerPoint 2013, after that I used separate both times. When I click on the different color theme, but it has not changed color.

    See video screenshot: 2015-10-03_1414 - fatech library

    I'm trying to understand how to change each color of the illustrator vector object in 2013 of PowerPoint? Please help me!

    Thank you

    FATECH wrote:

    But I want other options...

    There is no all.

    Illustrator and MS-Office share not all the graphics features of construction at the file level. There is no universal edit-ability between the two.

    .. which is the best export (eps, emf, or svg), then insert a vector file into PowerPoint?

    If your Illustrator illustration is vector of 100% and contains no live effects, complex gradients, blends, etc., the first thing to try is copy > paste special > enhanced metafile.

    Otherwise, SPE may work, or you can use the pixelation in PNG. Personally, I do not consider export raster format Illustrator to be a stable workflow method, so I'd be inclined to use Photoshop as an intermediate step: Illustrator > Save As PDF > open in Photoshop > save in PNG. Just my preference.

  • How can remove my account from the cloud to adobe

    How can remove my account from the cloud to adobe

    I would like to unsubscribe the service

    Hi mehranr34543413,

    Please contact the customer service. A customer service agent can help you with this request.

    Best,

    Sara

  • How to remove a step with the polygon Lasso tool

    How to remove a step with the polygon Lasso tool

    In PS, all you have to do is to hit the DELETE key and you can go back a little with the polygon Lasso tool. How to accomplish this in Fireworks?

    Another option that gives you a lot of control is to use the tool pen instead of the polygon lasso. Because it's a vector path, you can refine the outline very easily using the tools of feather and Subselects and when you are satisfied with the result, click on modify > convert a path to the top. You can even choose to keep or delete the vector path in the preferences panel.

    HTH

  • 2 How to remove an element from the tree and the database block tree?

    Hello

    2 How to remove an element from the tree and the database block tree?

    Kind regards

    Abdetu...

    The problem is caused by not sending forms is not a VALIDATION of the database because he thinks that there is no changes to save.

    Forms does know that changes to the data block, he does not know the changes made by the PLSQL INSERT, UPDATE, DELETE calls and procedure.

    Try to remove the line to block, rather than using a DELETION like that...

    go_block ('INSP_EQUIPMENT_TYPE');if form_success then   do_key ('DELETE_RECORD');end if;
    
    
    

    If you wish to continue using your original DELETE instead of my change above code, you can use different techniques to force forms to issue the COMMIT to the database, including this one...

            DELETE ...        FORMS_DDL ('COMMIT');
    

    Be careful... This will be the VALIDATION of the database, but the changes to the data block will not be sent to the database!

    I posted a few other ways to issue a VALIDATION of forms here
    www.seeristic.com/Forum_Posts/Forms_COMMIT.txt

  • Fireworks for wireframing - how to remove a layer of a page?

    Hello

    I use Fireworks for the first time to create a wireframe.  Have come some tutorials on adobe.com, I always get a grip on the behavior of the fireworks (I'm used to Photoshop and Illusrtator).

    I created all the General layers of the wireframe as a Master Page.  All pages are to display a sidebar, with the exception of a single page.  I understand how to add additional layers to the other pages, but I can't seem to find how to remove the layer of the sidebar of a page, unless it is removed from all pages.

    If anyone has any advice, they are greatly appreciated. Thank you.

    -Court

    In the layers panel, choose Remove Master Page in the menu options (in the top right of the Panel). This will remove all items in this page's master page; You cannot choose what parts of a page master to keep; It's a case of all or nothing.

    For the kind of flexibility you want, you can consider the use of shared layers.

    HTH

Maybe you are looking for

  • Safari / OSX needs to be updated

    My mother has problems to access accounts online on Safari. Such as banking, insurance, etc. She made a mistake on various Web sites, that it seeks to access telling him that his version of safari is too old and sites prevent him from doing anything

  • Satellite A205 with Vista will not start

    Hi, need help. Trying to help a friend with his laptop which is not booting. Its an A205 with Vista. Machine boots only a blank screen (not blue) with a mouse cursor.I tried safe mode and it does the same thing. I tried the Toshiba recovery disc supp

  • MR CH

    I USED TO USE WINDOWS 7 ON MY LAPTOP, ONCE I LOADED WI NDOWS 10 COMPUTER BECAME SLOW & HAS DONE THE WORK IS NOT SO THAT FRONT.  MY OFFICE SIMILARLY BEHAVED BADLY, SO I RELOADED WINDOWS 7 ON IT WITHOUT PROBLEM. I WENT BACK TO WINDOWS 7 ON MY LAPTOP &

  • File selector?

    Hello Is there a way to FilePicker select and display only the records (or any other class of cascades?) I tried the save mode. It seems perfect, except for the fact that we need to define a name of file at the end. Can we make do not ask the file na

  • PC does not work with the charger also

    My laptop is hard to give a beep, I know I need to change the battery, but the PC does not work with the charger also Original title: laptop Dell Inspiron M5030