Remove unused master spreads

Hello

I need to remove some unused document masters spreads. If there is any unused master then propagates its removal.  But when there is no unused master spreads, its pop-up below alert. Its deletion pages. I use the code below.

What is my in the code below.

Screen shot 2015-08-22 at 8.03.59 AM.png

function removeUnusedMaster()

{

App.Selection = 1851876449;

If (app.menuActions.itemByID checked (6145) == true)

{

try {}

app.menuActions.itemByID (6151) .invoke ();

app.menuActions.itemByID (6150) .invoke ();

} catch (e) {/ / remove spread all except 1st, when all differences are not used except no.}

app.activeDocument.masterSpreads [1] .select)

app.activeDocument.masterSpreads [app.activeDocument.masterSpreads.length - 1]. Select (Select ionOptions.addTo);

app.menuActions.itemByID (6176) .invoke ();

}

} else

{

try {}

app.menuActions.itemByID (6145) .invoke ();

app.menuActions.itemByID (6151) .invoke ();

app.menuActions.itemByID (6150) .invoke ();

} catch (e) {}

}

}

Thanks in advance,

Sudha K

The alert you see pop up when there is no unused masters gaps, but when you try to delete a master that applies to one or another master page/double. You cannot use menuActions for that I don't think that because you have to be able to tell if a master is applied. With menuActions test is to check if this alert appears, but you cannot script that.

But it is not too difficult to check if the masters are used: create a list of masters applied to the pages of the document, another list of teachers applied to the masters of the document (i.i. a list of masters end of other masters), then delete the masters that do not occur in any of the lists.

(function(){

  var pages;
  var masters;
  var i;
  var appliedToPages = {};
  var appliedToMasters = {};

  // Get the names of the masters applied to document pages
  pages = app.documents[0].pages.everyItem().getElements();
  for (i = pages.length-1; i >= 0; i--) {
    if (pages[i].appliedMaster !== null) {
      appliedToPages[pages[i].appliedMaster.name] = true;
    }
  }

  // Get the names of masters applied to masters (i.e. masters based on other masters)
  masters = app.documents[0].masterSpreads.everyItem().getElements();
  for (i = masters.length-1; i > 0; i--) {
    if (masters[i].appliedMaster !== null) {
      appliedToMasters[masters[i].appliedMaster.name] = true;
    }
  }

  // Delete masters that are not applied to any document pages or other masters
  for (i = masters.length-1; i > 0; i--) {
    if (!appliedToPages[masters[i].name] && !appliedToMasters[masters[i].name]) {
     // $.writeln (masters[i].name);
      masters[i].remove();
    }
  }
}());

Peter

Tags: InDesign

Similar Questions

  • Remove the unused master spread

    Hi all

    Does anyone know how to remove unused in the document master spread.

    Thanks in advance.

    tanshk

    It will work in CS3 at least. It is not very fast, however. It will remove all unused master spreads.

    myDoc=app.activeDocument;
    for (var  n=myDoc.masterSpreads.length-1; n>=0; n--){
         if (isMasterSpreadInUse(myDoc.masterSpreads[n])==false){
              myDoc.masterSpreads[n].remove();
         }
    }
    function isMasterSpreadInUse(myMasterSpread){
         var myDoc=myMasterSpread.parent;
         for (var  n=myDoc.masterSpreads.length-1; n>=0; n--){
              if (myDoc.masterSpreads[n].appliedMaster==myMasterSpread){
                   return true;
              }
         }
         for (var  n=myDoc.pages.length-1; n>=0; n--){
              if (myDoc.pages[n].appliedMaster==myMasterSpread){
                   return true;
              }
         }
         return false;
    }
    
  • 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

  • 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.

  • Cannot upload anything get message that the disc is full... Remove unused files and try again

    I can't download anything. I get a message that the disc is full... Remove unused files and try again... I have deleted many, cleaned the register w/Ccleaner, but doesn't seem to be enough... I don't have the original Windows XP CD... Was already installed. I don't have a recovery CD. Can I use this and start all over again to start on a clean slate? Is there something I can do? I can't yet to update anything.

    I have w/Service pack 3 Windows XP. PC is Dell pentium 4.

    I can't download anything. I get a message that the disc is full... Remove unused files and try again... I have deleted many, cleaned the register w/Ccleaner, but doesn't seem to be enough... I don't have the original Windows XP CD... Was already installed. I don't have a recovery CD. Can I use this and start all over again to start on a clean slate? Is there something I can do? I can't yet to update anything.

    I have w/Service pack 3 Windows XP. PC is Dell pentium 4.

    Please do these two simple things and the report on the results.

    A. report of the disc

    1 double click (or click, if it's in the start menu) Workstation

    2. for each drive (you must be at least 'disc' Local (c), right click and select Properties.  Report of the 'space used', 'Free space' and 'capacities '.

    B. know what is using the space

    1. get a USB that has at least 4 MB of space.  You can buy a 4 GB (this is 1,000 times more that you) thumb drive from Staples for $7.99 and connect it to your computer.

    2. download JDiskReport.  Go to http://www.jgoodies.com/downloads/index.html, make a right click on the link 'Win', choose ' save link under ', navigate to your USB key and save the file.

    3. in the installation: uncheck the 3 boxes on the screen "select components"; on the "Choose installation location" screen, click the Browse button and navigate to your USB key so that all the files will be installed on the USB.

    4. when the installation is complete, click on my computer, open the USB key, open the folder named JDiskReport and double-click on the file named jdiskreport - 1.3.2.jar (you don't see the .jar extension).

    5 scan C: and see what is taking place.

  • How to remove unused files from my account site live hotmail?

    original title: unused files

    How to remove unused files from my account site live hotmail?

    The question you have posted is bound using Windows Live (hotmail) and would be better suited to the Windows Live Help Solution . Please visit this link to find a community that will provide the support you want.

  • remove unused pages after copyng to previous pages

    original title: remove unused pages after coptyng to previous pages

    Hi, I have vopy oand CPAST info frompages to prreevios of pages but can not remove unused pages. Can you help me?

    Thank you

    Vicki

    Hello

    A few questions will help us better to solve your problem. Please answer these questions for us:

    1. what operating system do you use?

    2. what programs you have problems with?

    3. is there an error message generated?

    4. what type of file you go when this happens?

    5 How long this issue is past?

    6. is there anything changed/added/deleted before this issue popped up?

    It's basically the who, what, when, where and why of troubleshooting.
    b Eddie

  • Remove the master repository ODI

    Hi, I installed the odi on my system and did some work. Now I want to reinstall ODI and start my work from scratch. I tried uninstalling, then put it back, once again. When I try to import the master repository I do not import by saying that there are already. How can I remove my master repository?

    I have no remote control. My version of odi is 11.1.1.6

    Kind regards.

    Yes, you should be able to do so, if this is a new installation of ODI. (which has no references to the old install-config)

    Take the new schema master will allow fresh configuration.

    Kind regards

    Santy.

  • Removing unused columns - pre and post checks

    Friends...

    DB: 11.2.0.3

    OS: Linux

    I have a few quick questions in relation to removing unused columns which I intend to do on the production database (5 tables 20 GB each)

    The columns are already defined as unused tables, but I'm trying to get a backup plan for this tables if something goes wrong, while editing the table.

    Could some experts share their experience with me?

    1. What backup plan, I can have 5 tables to retrieve them in case something goes wrong?

    (I thought about import export, but I think import will fail if I try to import after that "alter table drop unused column" did not order)

    Also some tables have 500 lines and taking the export compliance will be problematic.

    2. any request to know in advance which package could be invalid after the fall of the column?

    3. statistical does is invalid?

    (According to my knowledge, I think that it won't affect his stats and also tested this and stale_stats column was not after a column.)

    4. do I need to scan the table or rebuild indexes to ensure that this drop column does not affect the performance of the application?

    5. any other minor/major that keep them in check after a fall unused column?

    Thank you

    Mike

    @rp0428... I understand your doubts and yes it's true, there were 5 tables of 20 GB each and additionally 5 tables, there are a few smaller tables I thought won't create a problem. For large tables, I did used control point.

    As always, I have tested plan in dev environment with the same size/data lines but a unused fall was quick and no problem with cancellations is why during production, it took me surprise.

    I had cancellation of 32 GB, so obviously, I was confident of small tables)<5 gb)="" should="" definitely="" fit="" in="" 32gb="" (but="" it="" wasn't="" the="">

    OK - but we can only go through the information you post and you don't post anything of this.

    If you had my question would be why you do not use "checkpoint" when you tested and why you didn't used it for this 5 GB table in production that generated 100 GB of REMAKING?

    My next question would be: what PROBLEM have you tried to solve by dropping the unused columns? Your application was working fine so why was the decision taken?

    And the reason for this question is that ANY significant changes to a table (standard partitions, add virtual columns, split partition, etc.) is ONLY suitable for technical purposes.

    There are almost always other changes that could / should be made and it is usually beneficial to make all these changes as a whole. Common examples include 1) get rid of the old data (dilation), 2) addition of such constraints as NOT NULL, 3) a table partitioning, 4) adding new columns - perhaps with NOT NULL value and/or default values constraints.

    Since 'other' someof these changes can be problematic if done online, it is generally advised to do a thorough analysis to make sure that you have identified ALL the changes you want, you can then do all at once. Often the best solution is to re-create the table and data using the DEC.

    1. a normal 'drop unused' rewrites all the blocks. It's not moving lines to other blocks - it essentially tightens just online content in order to remove all the content of the unused column.

    2. a normal 'drop unused', even if you use control points, leaving the "unusable" table until the WHOLE picture was treated. This means you NEED to perform the operation before normal re-use of this table, you can resume

    3. a normal life 'unused drop' will NOT free space which can be used by other objects - the same lines occupy the same blocks - the lines are just "small". Therefore, there is NO space to release.

    Creating a table (e.g. DEC) you can use a bulk loading and parallel operations and move lines of new blocks. It can also if take care of these 'other' I mentioned with little or no extra charge of the changes.

  • Remove unused paragraph Styles - without basedOn styles

    Hi all

    I have remove the unused paragraph style, re-flow the pattern content also deleted "basedOn" style.

    How to avoid remove basedOn styles.

    Example here:

    1. I have not used the '06 extract"style of paragraph directly in paragraphs (texts), so it's the unused paragraph style.

    2. I applied "06 extract 1 P" style of paragraph directly in paragraphs (texts), but connected the pstyle "06 extract" to indirectly ' 06 1 P "(avec l'option basedOn) see below excerpt.". "

    Removing unused styles, the "06" excerpt has also removed and affects '06 extract 1 P. So, re-flow occurring in this document, how to avoid this? No need to remove by using the 'basedOn' styles (example: "06 extract").

    Screen shot 2015-10-12 at 3.27.12 PM.png

    myDoc var = app.activeDocument;

    var myParStyles = myDoc.paragraphStyles;

    var myCharStyles = myDoc.characterStyles;

    for (I = myParStyles.length - 1; i > = 2; i--) {}

    removeUnusedParaStyle (myParStyles [i])

    }

    for (I = myCharStyles.length - 1; i > = 2; i--) {}

    removeUnusedCharStyle (myCharStyles [i])

    }

    function removeUnusedParaStyle (myPaStyle) {}

    app.findTextPreferences = NothingEnum.nothing;

    app.changeTextPreferences = NothingEnum.nothing;

    app.findTextPreferences.appliedParagraphStyle = myPaStyle;

    var myFoundStyles = myDoc.findText ();

    If (myFoundStyles == 0) {}

    myPaStyle.remove ();

    }

    app.findTextPreferences = NothingEnum.nothing;

    app.changeTextPreferences = NothingEnum.nothing;

    }

    function removeUnusedCharStyle (myChStyle) {}

    app.findTextPreferences = NothingEnum.nothing;

    app.changeTextPreferences = NothingEnum.nothing;

    app.findTextPreferences.appliedCharacterStyle = myChStyle;

    var myFoundStyles = myDoc.findText ();

    If (myFoundStyles == 0) {}

    myChStyle.remove ();

    }

    app.findTextPreferences = NothingEnum.nothing;

    app.changeTextPreferences = NothingEnum.nothing;

    }

    Thank you in advance,

    Dev

    before checking if the paragraph style is in use, check if all other models are based on it. something on the lines of (warning code, bad, inefficient to come):

    for (i = myParStyles.length - 1; i >= 2; i--) {
        for (var z = 0; z < myDoc.allParagraphStyles.length; z++) {
            var goodToRemove = true;
            if (myDoc.allParagraphStyles[z].basedOn == myParaStyles[i]) {
                //mark the parastyle as not to remove
                goodToRemove = false;
                break;
            }
        }
        if (goodToRemove) {
            removeUnusedParaStyle(myParStyles[i]);
        }
    }
    
  • Remove unused Styles using measures

    Hello

    I need to remove paragraph styles not used in the document by using action, until the unused style count is 0.

    I saw the url below in this forum.  I can do this, use the action?

    remove unused styles from a single action...

    Thanks in advance,

    Sudha K

    Hello

    It won't make any change. However, please create pdf and compare with an old to check this. If my answer is correct, please mark it as correct response so that it is reference to others.

    Thank you

    Ramesh K

  • How can Hello I remove unused assets please

    How can Hello I remove unused assets please

    Hello

    In this scenario, select "go to trump" among the options that you get to drop down.

    Once you click on "go to trump" Muse will open the page in design mode that has this very special and will choose this asset.

    Now you can remove it by pressing the button DELETE in the keyboard.

    Concerning

    Vivek

  • remove unused resources, while being sensitive to the related assets

    How can I remove unused assets from my library?

    Of course, the easy answer is to verify the account of its use and remove anything from scratch.

    But, how can ensure me that I don't remove an asset that has a counter for the use of zero, BUT is loaded by Actionscript?

    Is the library > select unused items sensitive to this?

    Thanks for your comments.

    Hi Greg,.

    In Flash Pro when you right-click in the library and choose "Select unused items" symbols with link names get selected. Thus the cases you mentioned above is supported.

  • Script to apply the master spread

    Hello

    This Script is for the page master opener co applying everywhere where CN is applied, when we run the script, it warns Sucess.But master spread is not applied. Please resolve.

    var mydoc=app.activeDocument; 
    var mypara = mydoc.stories.item(0).paragraphs.everyItem().getElements();
    for(i=0; i<mypara.length; i++){
        if (myPara[i].appliedParagraphStyle.name=="CN"){
               mypara[i].parentTextFrames[0].parent.appliedMaster = mydoc.masterSpreads.item("CO-Opener");
            }
        }
    alert("Master Page applied Sucessfully")
    

    Hi Math,

    I hope that your code is correct, but it seems [0] stories have no Styles "CN".

    Change the threshold:

    var = mydoc.stories.item mypara (0).paragraphs.everyItem () .getElements ();

    in

    var mypara = mydoc.stories.everyItem ().paragraphs.everyItem () .getElements ();

    Thanks Jongware and Green4ever...

    and also the use of the below url to get coding right for CS4 and CS5 and higher

    Apply the Master Page by using the paragraph Style

    var myDocument = app.activeDocument;
    var myParas = myDocument.stories.everyItem().paragraphs.everyItem().getElements();
    var myPage = myDocument.pages;
    for(i=0; i
    

    Concerning

    Siraj

  • How to get the master spread all the names and UIDRefs

    I create a document from a template. I have a list of pages to be added to the model, as well as the names of master pages which should apply to the pages.

    Looking through the SDK, it seems to me that BuildMasterSpreadList would give me what I want - an ID user name mapping. But I can work on how to call correctly, because I'm pretty new to the InDesign API.

    The first parameter of BuildMasterSpreadList is IStringListControlData * which must be transmitted to empty and should return a list of names. But I can't find out how to create an empty IStringLIstControlData object, since all the code sample appear to create from a dialog Widget.

    Help with this specific part of my task, or suggestions on how better to approach creation of pages and appointed master pages that are applicable would be much appreciated.

    Hello pdurrant,

    You can use the IMasterSpreadList interface on kDocBoss to iterate over a document master spreads. With the UID of each mask be spread, you can access its IMasterSpread interface.

    Markus

Maybe you are looking for