IDCS6 MACOSX JS: script of 'remove unused layer' is not from masters of the masters

Hello everyone.

I have an old script I've used several times to remove the unused layers. Until today, I thought that worked well:

var layers = app.documents[0].layers.everyItem().getElements();
for(var i=layers.length-1;i>=0;i--){
  if(layers[i].pageItems.length==0){
    layers[i].remove();
  }
}

However, today, I used the script on a document that was a never used layer once on a master page to which other master pages have taken place on the basis. To my surprise, when the script is run, this specific layer has been removed.

my knowledge of the script is poor, but looking at the script, it seems that the script is looking at all the layers that have something in them and any layer comprising any element should be removed. However, I think that only made pageItems refers to the regular pages or template, not masters BASED ON other masters.

I think that the problem is similar to another that I had recently where I had a script that has removed the unused masters, but deleted that other masters masters took place on the basis, and I think that the principles are the same. This thread can be found at:

http://forums.Adobe.com/message/5922004#5922004

In short, the script that worked there were as follows:

xUnusedMasters(myDoc);

function xUnusedMasters( docRef ) {
var mpNames = new Object () ;
var allPages = docRef.pages ;
for ( var pIndex = allPages.length - 1 ; pIndex >= 0 ; pIndex-- ) {
mpNames = addMasterName ( mpNames , allPages[pIndex] ) ;
}

var allMasterPages = docRef.masterSpreads ;
for ( var mpIndex = allMasterPages.length - 1 ; mpIndex >= 0 ; mpIndex-- ) {
if ( ! mpNames[allMasterPages[mpIndex].name] ) {
allMasterPages[mpIndex].remove() ;
}
}
return ; 

function addMasterName ( MPDB , pageRef ) {
if ( pageRef == null ) { return MPDB ; }
if ( pageRef.constructor.name == 'MasterSpread' ) {
MPDB[pageRef.name] = true ;
}
return addMasterName ( MPDB , pageRef.appliedMaster ) ;
}
}

is it possible to modify the script above so that instead of remove unused pages of masters, it takes away the layers used in a similar way?

Thank you very much

Colly

Hello

Maybe a little differently...:

Array.prototype.filter = function(collection) {
          var k, i, con, ids = collection.everyItem().id;
          con: for (k = ids.length - 1; k >=0; k--)
                    for (i = 0; i < this.length; i++)
                    if (this[i].id == ids[k]) {
                         ids.splice(k, 1);
                         continue con;
                         }
          return ids;     // array with unmatched ids from collection
          }

var
          mL = app.activeDocument.pageItems.everyItem().itemLayer,
          mUnusedLayersID = mL.filter(app.activeDocument.layers),
          len = mUnusedLayersID.length;

while (len-->0)
          app.activeDocument.layers.itemByID(mUnusedLayersID[len]).remove();

mL is a table with a layer of each pageItem;

filter compared to the collections of doc.layers;

unmatched ways not so used are deleted.

Jarek

Tags: InDesign

Similar Questions

  • TrayApps Message - the component you are trying to use is on a CD-ROM or another removable disk that is not available. Insert the TrayApp disk and click on 'ok '.

    Original title: TrayApps Message

    I get a message, "TrayApp" - the component you are trying to use is on a CD-ROM or another removable disk that is not available.  Insert the TrayApp disk and click on 'ok '.

    Hi BobKern,

    Follow the steps listed in the article mentioned below to solve the problem:

    Resolving MSI startup errors

  • "The feature you are trying to use is on a CD-ROM or another removable disk that is not available. Insert the disc "TrayApp".

    OT: TrayApp disk?
    I get a message after my computer starts "the component you are trying to use is on a CD-ROM or another removable disk that is not available. Insert the 'TrayApp' disk then I have another box that says please wait while the window configures TraApp. They're going away the screen, I'm sure it's something on my beginning of preety menu up which should be removed, but don't know what it is. Please can someone help?

    Hi sandirose,

    1. using HP printer?
    2. don't you make changes to the computer before the issue occur?

    TrayApp disk is a HP printing software, I suggest you perform clean boot and remove the program that is causing the problem.

    How to troubleshoot a problem by performing a clean boot in Windows Vista or in Windows 7
    http://support.Microsoft.com/kb/929135

    Note: follow step 7 of section of boot KB929135 to the computer in normal mode.

  • How to remove tabs, several spaces, quotes from data in the column.

    Hello

    How can we remove legs, several spaces, quotes from data in the column.

    Entry:

    H ope you 'are' Ingo w ell

    Output:

    H ope do you everything - there is a tab in hope and double-spaced in the well. This should be replaced by space. (Tab and multi spaces)

    I found myself with below:

    REGEXP_REPLACE (REGEXP_REPLACE (Replace (col, Chr (9),' '), ' () {2,} ', ' '),'[' ""]', ")

    Can we do more efficiently, your contributions are appreciated.

    I tried

    REGEXP_REPLACE (col,'[^ [a - z, A - Z, 0-9, Chr (0) - Chr (127) [: Space:]]] *', ") but the tabs still exist and that my data have German characters I can't go along with this.

    Thank you

    GVK.

    Hello

    Karthik417 wrote:

    Hello

    Thanks for your suggestion. In the above expression, we still missed to replace the double quotes.

    So thought we must use another regular expression instead of REPLACE.

    Select REGEXP_REPLACE (REGEXP_REPLACE (' H ope you "are" d "Ingo ell w ',' [' |])) CHR (9) | + ',' '),'["" "]') twice;

    I suppose we must use at least 2 REGEXP to achieve and cannot get it with a single expression.

    Thank you

    Sorry, I removed single quotes, not double - quote.  (This shows one of the reasons why having a few lines of sample data is very useful).

    I think you don't need 2 separate functions.  I do not think that the two must be REGEXP_REPLACE; You can use TRANSLATE to remove both types of quotation marks in a single function call:

    TRANSLATE (REGEXP_REPLACE (col

    , '[ ' || CHR (9) | ']+'

    , ' '

    )

    , '?'''"',

    , '?'

    )

    Of course, you can use use REGEXP_REPLACE to remove the quotes, if you really want to.

    Powerful they are, regular expressions are basically only 1 thing, things not 2 or more different.  Sometimes, he can watch as they do several things, because they can operate on character classes, like the series containing the and the and a variable number of characters.  For example, the REGEXP_REPLACE function, I used above is simply changing expression expression x y, where x is 1 consecutive or more characters of a given set.  As we both demonstrated, we can have a separate function that changes from p to q, but I know not all built-in function which, in general, can change x to y at the time that it changes from p to q.  TRANSLATE comes close, but TRANSLATE only works if x, y, p and q are single (or NULL), characters not expressions.

  • When I click on 'File' and then 'new' it keeps open a new file as a layer and not a background. The RGB mode is selected.

    When I click on 'File' and then 'new' it keeps open a new file as a layer and not a background. The RGB mode is selected.

    With the new files to open as a layer and not a background, I'm not able to create multiple layers and it won't let me convert the background layer.

    How what happened. I've used PS yesterday and had no problem. Today, my computer did updates mandatory day and now this.

    Yes. You use the option of Pixel of the Ellipse tool. He's so setting pixels as it is supposed to do without creating a layer.

    Choose the option to the form:

    Also the menu layer > new layer creates layers and paper rolled up at the bottom of your layers palette also creates a new layer. I hope these work.

  • Stretch script for time so layer out-point is set at the time of model determined.

    Hello world!

    After doing some reading on the documentation and thinking through this problem, I thought I would ask some advice.  I'm curious to know if it is possible with ExtendScript, temporal layer such as its land to outpoint s on a point determined in the timeline panel.  I see that we set the value of a layer .stretch property, but I guess I wan to know if there is a way of thinking that this percentage is based on where I want the layer .outPoint meet.

    Let's say I have a layer including inPoint starts at 0 and out-point ends at 5.  Now, let's say I want to stretch the negative layer so the out-point ends at 3.25.  What is the best way to determine the stretch value for the layer?

    Thank you
    Arie

    I guess it depends on how general you need, but for the situation you described, perhaps like this:

    var layer = app.project.activeItem.layer (1);

    var d = layer.outPoint - layer.inPoint;

    Layer.Stretch = (3.5/d) * 100;

    Dan

  • I get this message "the function ar you, try to use is on a CD-ROM or other removable disk that is not available." Insert the floppy disk "solution Center".

    I can't seem to find a "Solution Center" marked drive & I'm not sure what to do.  Can anyone help?

    http://welcome.HP.com/country/us/en/contact_us.html

    HP support.

    http://h30434.www3.HP.com/

    Contact HP or ask their Support Forums.

    This is a problem with their software.

    See you soon. Mick Murphy - Microsoft partner

  • How can I add a layer in summer shown throughout all the compositions of layers?

    I know that I'm not the only one who has never came across this problem, but I can't find anything on the net which gives a solution to this problem. I am trying to add a layer which arises through all layers, I created. From now I can't add a layer to the set design and show it on all layers. For example, I try to add something to my head, and it has nothing to do with Layer Comps, but must be seen on all layers. I think that's the reason why I have not used the front layer comp feature. It's very frustrating, especially if you say 20 layers, because you will be possible have to recreate the file. I hope I'm missing something and it's really easy to do.

    Thank you

    Ryan Wagner

    Ok thank you. After this announcement, I think I may have found the solution. This can be useful for all those who in the future. When I added the new layer and applied for the first composition of layers, it was added correctly. Once I clicked on the other layers Layer was not visible more. The layer I added showed the eye icon as it was visible, but I actually had to open this group and activate the "eye" icon to see the layer and then update. I think that it is a flaw in photoshop. I think that if you have a group and all layers are hidden in this average group don't the icon "eye" group must be active? Weird. Thank you for helping me on this topic. Nice day.

    Ryan

  • Delete the unused layer... ?

    Hello world!

    I'm new baby to indesign scripting and someone to help me find that indesign script below.

    How can I remove a unused layer in indesign CS4? and how do I know the image linked as CMYK, RGB, lab mode

    Thanks in advance.

    -yajiv

    This should remove the empty layers:

    var layers = app.documents[0].layers.everyItem().getElements();
    for(var i=layers.length-1;i>=0;i--){
      if(layers[i].pageItems.length==0){
        layers[i].remove();
      }
    }
    
  • Remove unused shades except for...

    I have a script that cleans my document... one of the features is that it removes the unused nuances. This works well for me most of the time, but in case I'm using a color whose name begins with a "D", I want the script to ignore it.

    In my workflow, "D" represents a digital process and we do not apply a color swatch to the digitally printed illustrations, but a "D" grade is required for our program output to sort the job to the correct printer. Swatch names vary but always begin with a "D" (USB, DGLD, NOTARY...).

    Thoughts, suggestions?

    Thank you very much for your help.

    remove unused shades

    var myIndesignDoc = app.activeDocument;

    var myUnusedSwatches = myIndesignDoc.unusedSwatches;

    for (var s = myUnusedSwatches.length - 1; s > = 0; a--) {}

    var mySwatch = myIndesignDoc.unusedSwatches [s];

    var name = mySwatch.name;

    alert (name);

    If (name! = "") {}

    mySwatch.remove ();

    }

    }

    (I found this little script somewhere in these forums - I apologize for not having available credit information)

    Hello

    Replace the line:

    if (name != ""){
    

    with:

    if (name != "" && name.search(/^D/) == -1){
    

    ... (/ ^ D / i) if not broken...

    Jarek

  • Remove text layer

    Hello

    What is the script to remove a few letters of layer?

    For example I "Layer XYZ" and I want to 'Sex XY'.

    Thank you for helping me!

    I try to explain my problem:

    I have several layers whith different names: I have to delete all three, or the letter at the end of each name.

    How can I do?

    XYZ-> layer Layer x

    ABC of the layer-> layer one

    Home of the layer-> layer hou

    ....

  • Using the crop tool to remove unused pixels or the artboard

    I have a cut picture, I placed a drop shadow (using the layer styles) on a transparent background.  I want to quickly use the crop tool to remove unused pixels or the artboard.

    I tried to enable 'show the edges of the layer', but it ignores the layer style/shade that I placed, and as it disappears when you start using the crop tool itself.  If this does not really work.

    Is there another way to do this?  Other than the eye it?  I too want to crop the image as tight as possible, but I don't want tight, too tight and cut off from the shadow.  Any advice?  Thank you!!

    Try Image - Trim function.  I think it will do exactly what need you.

    -Christmas

  • remove unused styles from a single action...

    Hello world

    Is there a faster and better way to remove unused paragraph styles and character in InDesign without closure styles. Here is my script created. Its working fine.

    //-----------------------------

    var doc = app.activeDocument;
    var pStyle = doc.paragraphStyles;

    for (i = pStyle.length - 1; i > = 2; i--) {}
    app.findTextPreferences = app.changeTextPreferences = null;
    app.findTextPreferences.appliedParagraphStyle = pStyle [i];
    var myFind = app.findText (false);
    If (myFind == 0) {}
    pStyle [i] .remove ();
    }
    }
    Alert ("OK");

    //----------------------------

    But in our documents, we have many styles. So above script takes a few minutes to perform the task. It would be better if she has the action runs in a few seconds. Can someone look into this and provide me with a better solution.

    Thanks in advance

    Indana

    Here is how I could do this:

         ArrayCompress=function(array){
              var str = array.sort().join('\r')+'\r'
              str = str.replace(/([^\r]+\r)(\1)+/g,'$1')
              str = str.replace(/\r$/,'')
              return str.split('\r')
         }
         IsInArray = function (item,array){
             for(var i=0;i=0;i--){
         if(IsInArray(allStyles[i].name,names)){
              allStyles.splice(i,1);
         }
    }
    alert(allStyles.length + " unused styles");
    

    Please note: If your tables are tidy header or footer, cells.everyitem () will not work. You will need to loop through the cells to build the table.

    Substances

  • 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 unused genres

    I'm trying to remove unused genres in my library?

    A few types are predefined in the standard MP3 tags. Others, created by you or inherited as part of the downloaded files can be eliminated by changing all instances of this kind.

    In music > My Music > select songs like point of view. You should see a list of the types near the top of the window > select a type you want to eliminate > select all songs are listed in the main window > read information (cmd + I) > remove or change the type field in the window that appears.

Maybe you are looking for