1 2 Previous Next 41 Replies Latest reply on Nov 4, 2014 5:19 PM by oleh.melnyk

    Override elements by script problems

    tomas8

      I need to override elements by script and have them end up at the same place they were in master. Now it overrides and puts them to the new page but it changes their position. Here is my function:

       

      function loadPagesAndOverrideElements(document, csvData) {

          // add pages defined in CSV and correct layout

          for (var i=0; csvData.numberOfRows>i; i++) {

              var masterSpread = document.masterSpreads.itemByName(csvData["master"][i]);

       

       

              document.pages.add();

              document.pages[i+1].appliedMaster = masterSpread;

              var allItems = document.pages[i+1].appliedMaster.pageItems.everyItem().getElements();

       

       

              for(var j=0;j<allItems.length;j++){

                  try {

                      allItems[j].override(document.pages[i+1]);

                  } catch(e) {

                      // alert(e);

                  }

              }

          }

       

       

          document.pages[0].remove();

       

       

          return document;

      }

        • 1. Re: Override elements by script problems
          Peter Spier Most Valuable Participant (Moderator)

          I've moved your question tot he scripting forum, but you should understand that once overridden, the object will be part of the regular stacking order for that layer, and in front of any other master page objects that are not overridden.

          • 2. Re: Override elements by script problems
            tomas8 Level 1

            The layer order is not a problem, problem is the element position. When I use override from indesign menu element stayes in its position, but when I use script it moves to some random position.

            • 3. Re: Override elements by script problems
              Peter Spier Most Valuable Participant (Moderator)

              I'm not a scripter, so I can't help with writing the script, but what you describe sounds like a bug in ID, not your script. Do you have the latest update for your version of ID installed?

              • 4. Re: Override elements by script problems
                tomas8 Level 1

                Yes I do, I am using creative cloud and latest version of ID. Its hard to say if it's a bug or there is some another way in scripting for overriding. Is there any scripter to help?

                • 5. Re: Override elements by script problems
                  Peter Spier Most Valuable Participant (Moderator)

                  This is where the scripters hang out. Have a little patience.

                  • 6. Re: Override elements by script problems
                    Kai Rübsamen Level 4

                    Are you really sure, that your items move to a random value? I would assume, that the items do not move, instead the problem occurs, when you delete a page and your left pages get applied a right master page and so on!

                     

                    Otherwise please provide a .idml-file, a runnable snippet of your script (incl. the csv-part).

                    • 7. Re: Override elements by script problems
                      tomas8 Level 1

                      I would send you the files you need but I don't have your mail. I did not find any option to upload file in here.

                      • 8. Re: Override elements by script problems
                        Kai Rübsamen Level 4

                        You see the mail of a user, if you are logged in and hover over the name of the user.

                        • 9. Re: Override elements by script problems
                          Peter Spier Most Valuable Participant (Moderator)

                          Kai Rübsamen wrote:

                           

                          You see the mail of a user, if you are logged in and hover over the name of the user.

                          That's true for ordinary users ONLY if the other user has made their email public. You can however, send a link to a file on Dropbox or another share service by clciking a user's name and sending a private message or email through the forum systems. You can also post a link publicly here.

                          • 10. Re: Override elements by script problems
                            Harbs. Level 6

                            Is your master spread a single page or multiple pages?

                             

                            If it's multiple pages, you need to make sure that the object is on the same master page location as the local page. If it's simple facing pages, you can compare the side property...

                             

                            Harbs

                            • 11. Re: Override elements by script problems
                              Laubender Adobe Community Professional & MVP

                              @tomas8 – Can you post some screen shots to give a "before" and "after" of a positive example what you like to do (without scripting)?

                               

                              I have an idea what's going wrong, but need a visual representation of a positive example first…

                               

                              Uwe

                              • 12. Re: Override elements by script problems
                                tomas8 Level 1

                                It looks like pretty much the same, before and after.

                                 

                                Screen Shot 2014-04-24 at 21.53.21.png

                                 

                                This is what I want to do

                                Screen Shot 2014-04-24 at 21.53.35.png

                                 

                                And this is what it does by script

                                 

                                Screen Shot 2014-04-24 at 22.00.12.png

                                • 13. Re: Override elements by script problems
                                  Harbs. Level 6

                                  Without seeing your document, I can't think off-hand why it would be doing that.

                                   

                                  This workaround should help:

                                   

                                  function loadPagesAndOverrideElements(document, csvData) {
                                      // add pages defined in CSV and correct layout
                                      for (var i=0; csvData.numberOfRows>i; i++) {
                                          var masterSpread = document.masterSpreads.itemByName(csvData["master"][i]);
                                          document.pages.add();
                                          document.pages[i+1].appliedMaster = masterSpread;
                                          var allItems = document.pages[i+1].appliedMaster.pageItems.everyItem().getElements() ;
                                  
                                          for(var j=0;j<allItems.length;j++){
                                              try {
                                                  var bounds = allItems[j].geometricBounds
                                                  var obj = allItems[j].override(document.pages[i+1]);
                                                  obj.geometricBounds = bounds;
                                              } catch(e) {
                                                  // alert(e);
                                              }
                                          }
                                      }
                                      document.pages[0].remove();
                                      return document;
                                  }
                                  

                                   

                                  Harbs

                                  • 14. Re: Override elements by script problems
                                    Laubender Adobe Community Professional & MVP

                                    @Harbs – hm, I'd rather store the x/y values of the objects on the master pages and move the elements to that position after overriding them.

                                     

                                    Reason: As I see from your screen shots they contain linked images. Changing the geometric bounds will only position their container objects and not the linked image contents. (That said without testing.)

                                     

                                    So I'd suggest the following workaround (using your code):

                                     

                                    function loadPagesAndOverrideElements(document, csvData) {
                                        // add pages defined in CSV and correct layout
                                        for (var i=0; csvData.numberOfRows>i; i++) {
                                            var masterSpread = document.masterSpreads.itemByName(csvData["master"][i]);
                                            
                                            document.pages.add();
                                            
                                            document.pages[i+1].appliedMaster = masterSpread;
                                            var allItems = document.pages[i+1].appliedMaster.pageItems.everyItem().getElements() ;
                                    
                                            for(var j=0;j<allItems.length;j++){
                                                try {
                                                    var bounds = allItems[j].geometricBounds
                                                    
                                                    //Get x and y of position:
                                                    var xB = bounds[1];
                                                    var yB = bounds[0];
                                                    
                                                    var obj = allItems[j].override(document.pages[i+1]);
                                                    
                                                    //Move object to original position:
                                                    obj.move([xB,yB]);
                                                    
                                                } catch(e) {
                                                    // alert(e);
                                                }
                                            }
                                        }
                                        document.pages[0].remove();
                                        return document;
                                    }
                                    

                                     

                                    Without having the original files hard to say, what the real culprit is and if the workaround will work…

                                     

                                    Uwe

                                    • 15. Re: Override elements by script problems
                                      Harbs. Level 6

                                      Yeah. move() is probably safer.

                                      • 16. Re: Override elements by script problems
                                        tomas8 Level 1

                                        Hi guys,

                                         

                                        thanks for tips but none of them worked. I have uploaded my test code with @Laubenders fix on github, you can download and try it by yourselfs.

                                         

                                        https://github.com/tomde/Indesign-Test-Script

                                        • 17. Re: Override elements by script problems
                                          Kai Rübsamen Level 4

                                          Uwes script will work, if you unlock your layer "Layer1".

                                           

                                          However: I think there is something wrong with your document or with your masterPages.

                                           

                                          Try the following test: New doc 500 x 300 px, 3 masterpages. Copy your contents from your doc in the new doc. Create 2 additional document pages and apply the masterpages by hand. Then run

                                           

                                           

                                          var curDoc = app.activeDocument;
                                          var allPages =  curDoc.pages;
                                          
                                          for ( var p = 0; p < allPages.length; p++ ) {
                                              var allObjects = allPages[p].masterPageItems;
                                              for ( var n = 0; n < allObjects.length; n++ ) {
                                                  allObjects[n].override( allPages[p] );
                                              }
                                          }
                                          

                                           

                                          I would assume, that this should work with your document too, but this produce the error as well.

                                          • 18. Re: Override elements by script problems
                                            Marc Autret Level 4

                                            Hi tomas8,

                                             

                                            Leaving aside coding wordkarounds already provided by my fellows, and the 'locked' layer problem that Kaï pointed out above, I suspect that the main issue is not in your code. Instead, we seem to have here a slightly corrupted document in terms of coordinate spaces—which may explain the unexpected shift of master items during overrides.

                                             

                                            Considering your document in its original state, let's study the affine map of the first master page:

                                             

                                            var page = app.activeDocument.spreads[0].pages[0],
                                                mx = pg.transformValuesOf(CoordinateSpaces.parentCoordinates)[0];
                                            
                                            alert( mx.matrixValues );   // =>  1,0,0,1,-400,-300   (!)
                                            
                                            

                                             

                                            In a document based on 500×300 the default page mapping should be [1,0,0,1,-250,-150], since the origin [0,0] of the page (i.e. top-left corner) should be expressed [-250,-150] in the spread coordinate space.

                                            But in your case, the origin of pages is mapped to [-400,-300] so we have something of a hidden translation (dx = –150, dy = –150) that makes things go wrong under various circumstances. Note that overriden items are unexpectedly moved by (+150px,+150px) when the script invokes myMasterItem.override(myPage).

                                             

                                            The issue is visible in IDML export as well. Extracting the spread-related XMLs you see that all page elements have the following attributes:

                                             

                                            GeometricBounds="150 150 450 650" ItemTransform="1 0 0 1 -400 -300"
                                            

                                             

                                            while correct values should be:

                                             

                                            GeometricBounds="0 0 300 500" ItemTransform="1 0 0 1 -250 -150"
                                            

                                             

                                            Whether this is an ID bug, I don't know. Since Page supports transformations the user can alter many parameters (via the Page tool, etc) without even realizing some underlying effects.

                                             

                                            How to fix this?

                                            (a) The best thing you can do is to edit those XML files so that all pages have the correct geometric attributes, then to re-zip the package and open the fixed IDML into InDesign to get a fresh document.

                                            (b) I'm pretty sure that we could as well repair page matrices through scripting, but this is not as easy as I originally thought! For the time being I've not managed to get happy results by this method Perhaps my colleagues will find a way…

                                             

                                            Once the document is clean you can use your loadPagesAndOverrideElements() function without error. (Sorry I don't know how to upload the corrected IDML file.)

                                             

                                            BTW, here is a shorter form of your original function:

                                             

                                            function loadPagesAndOverrideElements(document, csvData)
                                            {
                                                // Assumed that layers and master objects aren't
                                                // locked and allow override...
                                                
                                                var i, n=csvData.numberOfRows, ms;
                                            
                                                for( i=0 ; i < n ; ++i )
                                                    {
                                                    ms = document.masterSpreads.itemByName(csvData["master"][i]);
                                                    ms.pageItems.everyItem().override( document.pages.add({appliedMaster:ms}) );
                                                    }
                                            
                                                document.pages[0].remove();
                                            }
                                            
                                            

                                             

                                            @+

                                            Marc

                                            • 19. Re: Re: Override elements by script problems
                                              Laubender Adobe Community Professional & MVP

                                              @Marc – very interesting this all…

                                               

                                              I did some tests with the provided files.

                                              1. Exporting to IDML, not editing the IDML

                                              2. Opened the IDML in InDesign CS5.5 v7.5.3

                                              3. Ran the following script (just using your minimized code adding a line where all layers are set to locked = false)

                                               

                                              /**
                                              * @@@BUILDINFO@@@ 140505-1_LoadMasterSpread-Override-Test.jsx !Version! Mon May 05 2014 11:13:17 GMT+0200
                                              */
                                              
                                              var document = app.activeDocument;
                                              
                                              var csvData = {
                                                  "master" : ["A-Master", "B-Master", "C-Master"],
                                                  "numberOfRows" : 3
                                                  };
                                              
                                              document = loadPagesAndOverrideElements(document, csvData);
                                              
                                              
                                              function loadPagesAndOverrideElements(document, csvData){
                                                  
                                                  //EDIT: unlock ALL layers of the document before doing anything:
                                                  document.layers.everyItem().locked = false;
                                                  
                                                  //Marc Autret's minimized code:
                                                    
                                                  var i, n=csvData.numberOfRows, ms;  
                                                
                                                  for( i=0 ; i < n ; ++i )  
                                                      {  
                                                      ms = document.masterSpreads.itemByName(csvData["master"][i]);  
                                                      ms.pageItems.everyItem().override( document.pages.add({appliedMaster:ms}) );  
                                                      }  
                                                
                                                  document.pages[0].remove();  
                                              };
                                              

                                               

                                               

                                              Result with CS5.5 v7.5.3: No problems. No shifting page items!

                                               

                                              Ok. I redid the test with an edited IDML according to the values for GeometricBounds and ItemTransform you suggested.

                                              Also no problems. That I had expected.

                                               

                                              Next test:

                                              Opened the unedited IDML with InDesign CS6 v8.0.2, ran the script.

                                               

                                              Result with CS6 v8.0.2: Page items shifted.

                                               

                                              Then I opened the edited IDML with InDesign CS6 v8.0.2, ran the script again:

                                              NO PROBLEM (as expected).

                                               

                                              So it seems, something has changed between InDesign CS5.5 and CS6.

                                              I'd call it a bug…

                                               

                                              Uwe

                                              • 20. Re: Re: Re: Override elements by script problems
                                                Laubender Adobe Community Professional & MVP

                                                And another test:

                                                 

                                                Used the following code – the one I proposed in my answer #14 that stores the positions and move all the overridden page items to their initial positions with InDesign CS6 v8.0.2:

                                                 

                                                /**
                                                * @@@BUILDINFO@@@ 140505-1_MOVE-TO-INITIAL-LOCATION-LoadMasterSpread-Override-Test.jsx !Version! Mon May 05 2014 11:35:18 GMT+0200
                                                */
                                                
                                                var document = app.activeDocument;
                                                
                                                var csvData = {
                                                    "master" : ["A-Master", "B-Master", "C-Master"],
                                                    "numberOfRows" : 3
                                                    };
                                                
                                                document = loadPagesAndOverrideElements(document, csvData);
                                                
                                                function loadPagesAndOverrideElements(document, csvData) { 
                                                   
                                                    document.layers.everyItem().locked = false;
                                                   
                                                    // add pages defined in CSV and correct layout 
                                                    for (var i=0; csvData.numberOfRows>i; i++) { 
                                                        var masterSpread = document.masterSpreads.itemByName(csvData["master"][i]); 
                                                         
                                                        document.pages.add(); 
                                                         
                                                        document.pages[i+1].appliedMaster = masterSpread; 
                                                        var allItems = document.pages[i+1].appliedMaster.pageItems.everyItem().getElements() ; 
                                                
                                                        for(var j=0;j<allItems.length;j++){ 
                                                            try { 
                                                                var bounds = allItems[j].geometricBounds 
                                                                 
                                                                //Get x and y of position: 
                                                                var xB = bounds[1]; 
                                                                var yB = bounds[0]; 
                                                                 
                                                                var obj = allItems[j].override(document.pages[i+1]); 
                                                                 
                                                                //Move object to original position: 
                                                                obj.move([xB,yB]); 
                                                                 
                                                            } catch(e) { 
                                                                // alert(e); 
                                                            } 
                                                        } 
                                                    } 
                                                    document.pages[0].remove(); 
                                                    return document; 
                                                }
                                                

                                                 

                                                That did the trick after opening the un-edited version of the IDML with InDesign CS6 v8.0.2.

                                                A workaround. But obviously, according to Kai, not working with InDesign CC v9.2.0. Cannot test that right now with this version.

                                                 

                                                Uwe

                                                • 21. Re: Override elements by script problems
                                                  Marc Autret Level 4

                                                  @ Uwe,

                                                   

                                                  Thanks, very enlightening.

                                                   

                                                  So we now have a user-friendly way to fix all this:

                                                   

                                                  (c) Open the IDML in ID CS5/5.5 (or even ID CS4!) then "Save as" the document (or export as IDML). The resulting file is then repaired and can be used in CS6/CC. [In CS4 this fact is obvious, since Pages haven't transform attributes at all.]

                                                   

                                                  The workaround of moving shifted items by script after override() is still an option, but I consider this wouldn't actually solve the problem, I mean, under the hood.

                                                   

                                                  Option (b) —that is, fixing the page matrix through scripting— remains an open question to me. I'd really like to have feedback if anyone makes progress in that direction.

                                                   

                                                  @+

                                                  Marc

                                                  • 22. Re: Override elements by script problems
                                                    Laubender Adobe Community Professional & MVP

                                                    @Marc – unfortunately opening the IDML in CS5.5, saving it and open the document in CS6 or exporting to IDML from CS5.5 and opening that in CS6 will not repair the file (just tested). The only way to go is editing the IDML. Or using CS5.5 and stop there.

                                                     

                                                    Oh. Another one: One option that could repair the file is opening the IDML in CS4.
                                                    Let's see…

                                                     

                                                    A quick test with CS4 is showing, that this is the way ;-)

                                                     

                                                    Uwe

                                                    • 23. Re: Override elements by script problems
                                                      Laubender Adobe Community Professional & MVP

                                                      @all – this might be a bit off-topic, but I thought the new functionality of this forum software will allow to upload files.

                                                      At least the following screenshot will suggest that:

                                                       

                                                      1. I can upload a file to the Forums (or community, whatever that means):

                                                       

                                                      OptionToUploadAFile.png

                                                       

                                                      2. I can select a file for uploading or dropping it to the interface for uploading:

                                                       

                                                      SelectAFileToUpload.png

                                                       

                                                      3. But I got stuck in the middle of the process (after filling out the required form):

                                                       

                                                      StuckInTheProcessUploadingAFile.png

                                                       

                                                      The new forum's software is a mess…

                                                       

                                                      Uwe

                                                      • 25. Re: Override elements by script problems
                                                        Laubender Adobe Community Professional & MVP

                                                        @Trevor – hmm, using an emoticon like you did, generated an empty e-mail for me (I will be notified via e-mail if a new post will be added to this thread). Sorry for being OT again…

                                                         

                                                        Here the mail that came in:

                                                         

                                                        EmptyEMailUsingAnEmoticonByTrevor.png

                                                         

                                                        Uwe

                                                        • 26. Re: Override elements by script problems
                                                          Laubender Adobe Community Professional & MVP

                                                          @Marc – back from OT to the real issue behind this case…

                                                           

                                                          I had another look at the provided document. One thing what was making me suspicious is the fact that the dimensions of the pages are 500 x 300 px while a look to the Pages Panel states the name for the Alternate Layout is "800 x 600 H".

                                                           

                                                          The initial layout for this document was "800 x 600 px" for Digital Publishing. Later in the process this was changed to 500 x 300 px. Not by the Pages Tool, but in the GUI for the Document Setup. (A clear indication for that fact is the uniformity of Master Spread [None] to the rest of the master spreads and the first page.)

                                                           

                                                          I just did that with a version of InDesign CC:

                                                           

                                                          Creating a new document with 800 x 600 px and changing it to 500 x 300 px using Document Setup.

                                                          And running the script. Bam. There is it: translation!!

                                                           

                                                          Now we know WHY it happened.

                                                           

                                                          If we have used the Pages Tool this problem would not occur…

                                                           

                                                          Uwe

                                                          • 27. Re: Override elements by script problems
                                                            Laubender Adobe Community Professional & MVP

                                                            Did the same experiment with InDesign CS5.5 and CS6:

                                                             

                                                            CS5.5 was ok.

                                                            CS6 was showing the issue.

                                                             

                                                            So I conclude this bug (or strange behavior) sneaked in with CS6.

                                                             

                                                            Uwe

                                                            • 28. Re: Re: Override elements by script problems
                                                              Laubender Adobe Community Professional & MVP

                                                              Just showing some numbers:

                                                               

                                                              var page = app.documents[0].spreads[0].pages[0];
                                                              var pageMatrix = page.transformValuesOf(CoordinateSpaces.parentCoordinates)[0];
                                                              var pageMatrixValues = pageMatrix.matrixValues;
                                                              
                                                              $.writeln(pageMatrixValues+"\t"+"PageBounds:"+" "+page.bounds);
                                                              
                                                              //Results CS5.5:
                                                              
                                                              //NEW DOCUMENT WITH 1 PAGE: SIZE 800 x 600 px:
                                                              //1,0,0,1,-400,-300    PageBounds: 0,0,600,800
                                                              
                                                              //AFTER RESIZE in GUI with Document Setup to size 500 x 300 px:
                                                              //1,0,0,1,-250,-150    PageBounds: 0,0,300,500
                                                              
                                                              //AFTER RESIZE in GUI with Pages Tool on applied Masterpage A:
                                                              //1,0,0,1,-250,-150    PageBounds: 0,0,300,500
                                                              
                                                              
                                                              //Results CS6 and above:
                                                              
                                                              //NEW DOCUMENT WITH 1 PAGE: SIZE 800 x 600 px:
                                                              //1,0,0,1,-400,-300    PageBounds: 0,0,600,800
                                                              
                                                              //AFTER RESIZE in GUI with Document Setup to size 500 x 300 px:
                                                              
                                                              //NUMBERS NOT CHANGED! OPPOSED TO InDesign CS5.5:
                                                              //1,0,0,1,-400,-300    PageBounds: 0,0,300,500
                                                              
                                                              //AFTER RESIZE in GUI with Pages Tool on applied Masterpage A:
                                                              //1,0,0,1,-250,-150    PageBounds: 0,0,300,500
                                                              
                                                              

                                                               

                                                              I think, this case is quite clear now.

                                                               

                                                              Uwe

                                                              • 29. Re: Override elements by script problems
                                                                Laubender Adobe Community Professional & MVP

                                                                And two screenshots to illustrate the difference of changing document page sizes in InDesign CS6 (and above):

                                                                 

                                                                1. "Wrong" or "dangerous" approach with the Document Setup GUI:

                                                                 

                                                                Was800x600now500x300_DocumentSetup_CS6.png

                                                                 

                                                                2. "Appropriate" approach with the Pages Tool:

                                                                 

                                                                Was800x600now500x300_PagesTool_CS6.png

                                                                 

                                                                "Wrong", "dangerous" and "appropriate" in the sense, that scripting will work as expected without moving overridden page items to their original positions.

                                                                 

                                                                To correct the problematic example #1, just use the Document Setup GUI and go back to the original size and change size again by using the Page Tool.

                                                                 

                                                                Uwe

                                                                • 30. Re: Override elements by script problems
                                                                  Trevorׅ Adobe Community Professional

                                                                  Hi Uwe

                                                                   

                                                                  Just clarifying / summarizing things.

                                                                  When one wants to change the page dimensions of a clean non-messed up document use the page tool and not the document page setup GUI.

                                                                  Screen Shot 2014-05-06 at 19.21.30.png

                                                                  • 31. Re: Re: Override elements by script problems
                                                                    Marc Autret Level 4

                                                                    Uwe, Trevor, tomas8,

                                                                     

                                                                    Thanks to Uwe's investigations/tests I finally came up with a scripted solution that sounds clean to me—but it still needs to be tested in CS5/5.5.

                                                                     

                                                                    My main finding is that the matrix Page.masterPageTransform (property available in CS5 and later) accurately reflects the shift we are trying to circumvent.

                                                                    When a new page is created in the 'corrupted' document based on any master spread, CS6 and CC show the following result:

                                                                     

                                                                    alert( myNewPage.masterPageTransform.matrixValues );
                                                                    
                                                                    // => 1,0,0,1,-150,-150      Here it is!
                                                                    

                                                                     

                                                                    As far as I understand this matrix determines the transformation "applied to the master page before it is applied to Page," that is, how the page is mapped to its master page. In normal case that should be—I suppose—the IDENTITY matrix.

                                                                    My guess is that CS6/CC improperly uses those matrix values during scripted overrides, so that we have to explicitly apply the inverse matrix to the newly created page, as follows:

                                                                     

                                                                    var document = app.activeDocument;  
                                                                    var csvData = {
                                                                        "master" : ["A-Master", "B-Master", "C-Master"],
                                                                        "numberOfRows" : 3
                                                                        };
                                                                      
                                                                    loadPagesAndOverrideElements(document, csvData);
                                                                      
                                                                      
                                                                    function loadPagesAndOverrideElements(document, csvData)
                                                                    {
                                                                        // Constants
                                                                        // ---
                                                                        const CS_INNER = +CoordinateSpaces.innerCoordinates,
                                                                              ORIGIN = [[0,0],CS_INNER];
                                                                        
                                                                        // Variables
                                                                        // ---
                                                                        var i, n = csvData.numberOfRows,
                                                                            ms, pg, mx;
                                                                    
                                                                        // Unlock ALL layers
                                                                        // ---
                                                                        document.layers.everyItem().locked = false;
                                                                    
                                                                        // Page creation loop
                                                                        // ---
                                                                        for( i=0 ; i < n ; ++i )
                                                                            {
                                                                            // Select the master spread
                                                                            // ---
                                                                            ms = document.masterSpreads.itemByName(csvData["master"][i]);
                                                                            
                                                                            // Create new page and override master items
                                                                            // ---
                                                                            ms.pageItems.everyItem().override( pg=document.pages.add({appliedMaster:ms}) );
                                                                    
                                                                            // Revert the masterPageTransform if needed
                                                                            // ---
                                                                            (mx=pg.properties.masterPageTransform) && pg.transform(CS_INNER, ORIGIN, mx.invertMatrix());
                                                                            }
                                                                        
                                                                        // Remove the 1st page
                                                                        // ---
                                                                        document.pages[0].remove();
                                                                    };
                                                                    
                                                                    
                                                                    

                                                                     

                                                                    Seems to work for me.

                                                                    What about CS5?

                                                                     

                                                                    @+

                                                                    Marc

                                                                    • 32. Re: Re: Override elements by script problems
                                                                      Laubender Adobe Community Professional & MVP

                                                                      @Trevor – oh, how drastic. ;-)

                                                                       

                                                                      Now, we need a good scripting solution to:

                                                                       

                                                                      1. Detect cases like that

                                                                      2. "Correct" or "normalize" the transformation matrix for all master pages ?!

                                                                       

                                                                      I'm a little clueless how to get that together by scripting… I'm glad to do it in the GUI. If there are clues like the naming of the Alternate Layout, ok. But can we rely on that? No. The user could renamed the Alternate Layout. So, is inspecting the transformation matrix of a page, of a master page enough?

                                                                       

                                                                      We can consider us lucky, that the document is a single sided one.

                                                                      Let's check the 6 numbers of the matrix ( a - f ):

                                                                       

                                                                      1,0,0,1,-400,-300
                                                                      

                                                                       

                                                                      The first 4 numbers, a,b,c and d indicate, that principly everything is well in order. It's values are showing Identity: 1,0,0,1.

                                                                      No scaling, no rotation, no shear. Good.

                                                                      e and f will give the translation part of the matrix, a hint when compared to the bounds, that something could be wrong.

                                                                       

                                                                      Let's look at the bounds of page one:

                                                                       

                                                                      PageBounds: 0,0,300,500
                                                                      

                                                                       

                                                                      Can we always assume that these numbers are in direct relation to the values in the matrix?

                                                                       

                                                                      A formula, that says:

                                                                       

                                                                      - (bounds[3] / 2) should always be equal to e in the matrix, if a,b,c,d equals 1,0,0,1

                                                                      and:

                                                                      - (bounds[2] / 2) should always be equal to f in the matrix, if a,b,c,d equals 1,0,0,1

                                                                       

                                                                      And if not, expect a translation of page items that will be overridden…

                                                                       

                                                                      ( Setting my high hopes in Marc )

                                                                       

                                                                      Uwe

                                                                      • 33. Re: Re: Override elements by script problems
                                                                        Laubender Adobe Community Professional & MVP

                                                                        @Marc – ah. I summoned you ;-) To the rescue!

                                                                        Will try your script with CS5 and CS5.5…

                                                                         

                                                                        Did not read your recent comment before sending mine; was logged out inadvertently several times the last hour (arrgh!).

                                                                         

                                                                        Will be back again soon…

                                                                         

                                                                        Uwe

                                                                        • 34. Re: Re: Override elements by script problems
                                                                          Laubender Adobe Community Professional & MVP

                                                                          @Marc – your code is working very well in InDesign CS5 and CS5.5.

                                                                          Just added the line that unlocked all layers in the document.

                                                                           

                                                                          Wow. What a journey to the world of matrices…

                                                                           

                                                                          A toast to Marc Autret, the Master of the Matrix!

                                                                          (Got a glass of wine in my hand: A 2009 Rosso di Montalcino)

                                                                           

                                                                          Uwe

                                                                          • 35. Re: Re: Override elements by script problems
                                                                            Laubender Adobe Community Professional & MVP

                                                                            Oops. Unlocking the layers was already provided in Marc's code…

                                                                             

                                                                            Now. I have to digest the code. Will take a while…

                                                                             

                                                                            Uwe

                                                                            • 36. Re: Override elements by script problems
                                                                              Marc Autret Level 4

                                                                              Laubender wrote:

                                                                               

                                                                              Let's look at the bounds of page one:

                                                                               

                                                                              1. PageBounds: 0,0,300,500 

                                                                               

                                                                              Can we always assume that these numbers are in direct relation to the values in the matrix?

                                                                               

                                                                              By no means! Never assume that myPage.bounds—or myPageItem.geometricBounds—can lead to anything reliable when you deal with transformations. There are too many ways to retrieve confusing 'bounds.' Those values only reflect the current top-left-bot-right locations of a some spread-relative bounding box according to the current user units, the current ruler coordinate system, the current custom zero-point and so on. Coordinate spaces and transformations require some learning and training, but they definitely allow you to remove those contextual hazards. (The biggest problem with InDesign coordinates, IMHO, is that pathpoints are all given relative to ruler space!)

                                                                               

                                                                              @+

                                                                              Marc

                                                                              • 37. Re: Override elements by script problems
                                                                                Marc Autret Level 4

                                                                                Laubender wrote:

                                                                                 

                                                                                (Got a glass of wine in my hand: A 2009 Rosso di Montalcino)

                                                                                 

                                                                                Please upload

                                                                                • 38. Re: Override elements by script problems
                                                                                  Trevorׅ Adobe Community Professional

                                                                                  Best I could do, not to refreshing but the best I could do.

                                                                                  Cheers

                                                                                  Wine.png

                                                                                  • 39. Re: Override elements by script problems
                                                                                    tomas8 Level 1

                                                                                    Thank you guys, I will test your fixing code tomorrow. From @Laubender tests I would say it is a bug in Indesign. Is there a way how to give adobe a notice about this issue?

                                                                                    1 2 Previous Next