38 Replies Latest reply on Dec 8, 2016 9:36 AM by cameronmcefee

    How to get bounds of largest possible document area?

    cameronmcefee Level 1

      Hello!

       

      I'm trying to improve GuideGuide's handling of Illustrator guides. So far I haven't found a built-in way to add guides, so I draw a path and then set it's guides value to true. While this works, it has the drawback that I have to figure out the boundary locations of the guides in addition to where I want to place them.

       

      For my example, I'm using a horizontal guide.

       

      Looking at how Illustrator handles things, it appears to add guides at the max left and max right bounds of the document. Mind you, it's possible to place objects even farther beyond those bounds, but they're the bounds that Illustrator visually shows. This is the behavior I'm trying to emulate.

       

      So far I haven't found a scripted way to extract those boundaries from Illustrator, but my testing has thus far shown that the document max height and width is 16383pts. One would think that it would be as simple as placing a guide edge at 0 and 16383, however the document origin appears to be in the center. One would then think that (16383/2) * -1 would be the document edge, but this also does not turn out to be true. So far, in my testing the document origin is fluid, sometimes in the center, sometimes offset. I tried incorporating the document pageOrigin, but that has also not proven to be helpful. I'm even taking into account the artboard/document coordinate system differences and have found no obvious solution yet.

       

      Am I missing some obvious details that can be used to pull these values from Illustrator? This seems like something that would be relatively easy to do.

       

      GPU Preview)  2016-09-13 09-04-36.png

        • 1. Re: How to get bounds of largest possible document area?
          Silly-V Adobe Community Professional

          You know, good question- since an artboard can be moved all around the pasteboard.

          • 2. Re: How to get bounds of largest possible document area?
            o-marat Level 3

            maybe so:

            • previously make a template ai-file with a group of 2 guides (horizontal + vertical)
            • [you can even include it into a script as a binary string]
            • copy this group to target document
            • take geometricBounds of this guides-group...
            • 3. Re: How to get bounds of largest possible document area?
              Silly-V Adobe Community Professional

              You still will have problems with edges - the pasted guides seem to revert to having their edges cropped to the paste board and the origin of their location is determined by the artboards

              • 4. Re: How to get bounds of largest possible document area?
                akinuri Level 1

                UI in illustrator uses local coordinate system (Artboard Rulers). Scriping uses global coordinate system (Global Rulers). Also the cartesian system used in both differs. UI uses a modified one, 90° CW rotated. Scripting uses the actual one. See the difference in the quadrants.

                 

                Max document area is 16383 (2^14 - 1), as you pointed out. So, if you were to resize your artboard and make it as large as this, you'd assume (0,0) would be the center of the artboard. Wrong. For some reason, there's an offset. Center of the artboard would be (306.5, -396.5).

                 

                Capture.JPG

                 

                If you want to add a horizontal guide using the top left of the artboard as the origin, first you need to get the artboard's global position using "artboard.artboardRect". Try the following code. Create a document. Resize and reposition the artboard however you want, and then run the script. It'll add two guides that intersect at the center of the artboard. Guides' width and length equal to max document size (16383).

                 

                function calcRect(rectArray) {
                    var rect = {
                        topLeft : {
                            x : rectArray[0],
                            y : rectArray[1],
                        },
                        bottomRight : {
                            x : rectArray[2],
                            y : rectArray[3],
                        },
                    };
                    rect.width  = Math.abs(rect.bottomRight.x - rect.topLeft.x);
                    rect.height = Math.abs(rect.bottomRight.y - rect.topLeft.y);
                    rect.center = [
                        rect.topLeft.x + (rect.width / 2),
                        rect.topLeft.y - (rect.height / 2)
                    ];
                    return rect;
                }
                
                
                var document  = app.activeDocument;
                var boardRect = calcRect(document.artboards[0].artboardRect);
                
                
                var horizontal = document.pathItems.add();
                horizontal.setEntirePath([ [-7885, boardRect.center[1]], [8498, boardRect.center[1]] ]);
                horizontal.guides = true;
                
                
                var vertical = document.pathItems.add();
                vertical.setEntirePath([ [boardRect.center[0], 7795], [boardRect.center[0], -8588] ]);
                vertical.guides = true;
                

                 

                Capture2.JPG

                2 people found this helpful
                • 5. Re: How to get bounds of largest possible document area?
                  cameronmcefee Level 1

                  Thanks akinuri! This is great.

                   

                  > For some reason, there's an offset. Center of the artboard would be (306.5, -396.5).

                   

                  Any theories about why this is? I actually came to the same conclusion but by a slightly different calculation on the ferry this morning. As of the end of my ferry ride I'd figured out the 306.5, and my plan for the ride home was to figure out the vertical offset and why both exist (to ensure that they don't change due to other factors).

                   

                  I think your method feels cleaner, but for posterity, the method by which I came to the horizontal result was roughly:

                   

                  (((docMax / 2) - docOriginLeft - 306.5) + artboardLeft) * -1

                  • 6. Re: How to get bounds of largest possible document area?
                    akinuri Level 1

                    I recently started scripting in Illustrator and as of now, I have none. But these values are not random. (306.5, -396.5) corresponds to half of the default document size (Letter) that is (612,792). Further examination is required to make sense of this.

                     

                    It'd be safer to use artboardRect since we don't know the nature of this offset. It might not be fixed, might be different or not exist in other versions. Nevertheless, pick whatever works for you :)

                    • 7. Re: How to get bounds of largest possible document area?
                      Silly-V Adobe Community Professional

                      Well this is good, for people who leave their origins alone and don't drag around the document origin (using the square at the intersection of the rulers) - which would be most people, but there are some wanderers of course.

                      • 8. Re: How to get bounds of largest possible document area?
                        Silly-V Adobe Community Professional

                        The offset values for the center are likely set by the new document profile document.

                        Screen Shot 2016-09-14 at 1.13.31 PM.png

                        1 person found this helpful
                        • 9. Re: How to get bounds of largest possible document area?
                          cameronmcefee Level 1

                          > (306.5, -396.5) corresponds to half of the default document size (Letter) that is (612,792).

                           

                          Oh that's interesting. Seems like an odd thing to tie into the positioning, but worth looking into.

                           

                          > Well this is good, for people who leave their origins alone and don't drag around the document origin (using the square at the intersection of the rulers) - which would be most people, but there are some wanderers of course.

                           

                          Agreed. Not shown in my personal calculation is a helper that adjusts for ruler offsets. Anyone following this thread would likely want to include their own adjustment.

                          • 10. Re: How to get bounds of largest possible document area?
                            akinuri Level 1

                            Tested this with different profiles and you're correct. Offset changes depending on the profile. Now, what we need to figure out is why this happens :)

                             

                            This just proves that using artboardRect is safer than using fixed offset values.

                            • 11. Re: How to get bounds of largest possible document area?
                              Silly-V Adobe Community Professional

                              But, how do you calculate the offsets if the 'root' of the offsets has been changed in the UI?

                              • 12. Re: How to get bounds of largest possible document area?
                                cameronmcefee Level 1

                                Is it possible to change the preset values/sizes in the UI once the document has been created? I haven't been able to find anything so far. It seems like for all intents and purposes on the UI side the presets are only relevant before the document is created despite the fact that the preset stays with the document. I don't know if this is true though.

                                 

                                If they do stay fixed after the document is created, after some testing, it looks like the preset matters but the size preset does not. For example, "print" is different from "web", but "Legal" is not different from "B5". This appears to correlate with the scripting constant DocumentPresetType, which has the following values:

                                 

                                BasicCMYK

                                BasicRGB

                                Print

                                Mobile

                                Video

                                Web

                                 

                                The correlation is not exact though. I'm curious if it's possible to test which preset the document is based on. Then you could just build a table of presets and their corresponding values and use that to adjust.

                                • 13. Re: How to get bounds of largest possible document area?
                                  cameronmcefee Level 1

                                  Ignore that. It looks like these presets could be edited, so feasibly a custom one could be added that have different proportions. There's got to be a way to get these values at runtime…

                                  • 14. Re: How to get bounds of largest possible document area?
                                    pixxxel schubser Level 5

                                    Hi Silly-V and cameronmcefee,

                                    give this snippet a try:

                                    // RectangleMaxPasteboardBounds.jsx
                                    // ArtboardMaxPasteboard2.jsx 
                                    // try to create a rectangle with the max. pasteboard bounds
                                    // regards pixxxelschubser Sept. 2016
                                    
                                    if (app.activeDocument) {
                                        var aDoc = app.activeDocument;
                                        var ABR = aDoc.artboards[0].artboardRect;
                                        var total = Math.pow (2, 14)-1;
                                        var topLeft = Math.ceil (-total/2);
                                        
                                        var maxAB = new Array();
                                        maxAB.centerX = (ABR[2].toFixed(5)-ABR[0].toFixed(5))/2;
                                        maxAB.centerY = (ABR[3].toFixed(5)-ABR[1].toFixed(5))/2;
                                        var xSubstr = (maxAB.centerX < 0) ? Math.floor(maxAB.centerX) : Math.ceil(maxAB.centerX);
                                        var ySubstr = (maxAB.centerY < 0) ? Math.floor(maxAB.centerY) : Math.ceil(maxAB.centerY);
                                        maxAB[0] = topLeft+xSubstr;
                                        maxAB[1] = -topLeft+ySubstr;
                                        var Rect = aDoc.pathItems.rectangle(maxAB[1], maxAB[0], total, total, false);
                                        Rect.stroked = false;
                                        Rect.filled = false;
                                        Rect.selected = true;
                                        alert("Rectangle created");
                                        } else { alert ("no open document"); }
                                    

                                     

                                    Have fun

                                     

                                    • 15. Re: How to get bounds of largest possible document area?
                                      cameronmcefee Level 1

                                      I legitimately don't understand what the missing magic is that you included, but that definitely works. Is it the conditional x/ySubstr value?

                                       

                                      Also, where does Math.pow (2, 14)-1 come from? Presumably there's some underlying reason for it.

                                       

                                      I'll report back once I have it modified for adding guides.

                                      • 16. Re: How to get bounds of largest possible document area?
                                        Silly-V Adobe Community Professional

                                        All good, but still - if someone does change their global rulers then you're blind with no way out

                                         

                                        I wonder if I can really make a dive and try to mess with the SDK to make a very simple educational .aip plugin whose sole purpose is to report the pasteboard coordinates. All these years and I have not yet made this climb - maybe it's time to start!

                                        • 17. Re: How to get bounds of largest possible document area?
                                          Silly-V Adobe Community Professional

                                          The Math.pow is 2 ^ 14 = 16384, and then -1 to get the 16383. Not sure the benefit of this style, wonder about that mi-self

                                          • 18. Re: How to get bounds of largest possible document area?
                                            akinuri Level 1

                                            Math.pow(2, 14) - 1 yields 16383 which is the max size of the document. I've pointed that out in my answer ((2^14) -1). I've used that instead of 16383, because one might think 16383 is just some random value. It's not. Almost all software uses powers of two for space. Also I think this value is absolute. There is no need to calculate it. However, the origin changes. There's an offset. As Silly-V pointed out, this offset depends on the document profile.

                                             

                                            When you create a document, the artboard is placed at (0,0) using its top left as the reference point. This would look like this:

                                             

                                            org.jpg

                                             

                                            The origin is the center of the document area and the artboard is at (0,0). All quadrants are equal in area. But this is not what actually happens. In the above image, the artboard isn't centered in the document area. Illustrator centers the artboard in the document area. To do that, coordinate system needs to be shifted by half the size of the artboard. The artboard is in the quadrant 4, and its opposite quadrant is 2, so the shift happens from quadrant 4 to 2. This would look like this:

                                             

                                            offset.jpg

                                             

                                            See the quadrant sizes have changed, the origin shifted, and the artboard is centered in the document area. To understand this better, imagine the max document size as a viewport. The actual space is infinite, but you can look at this space from a limited viewport (16383 x 16383). When you add a document, the artboard is placed at (0,0) and it is not centered in the viewport, because viewport is focused at (0,0). Illustrator wants to focus on the artboard, not at the origin. So it moves the viewport from (0,0) to the center of the artboard. Thus the offset is always the half size of the artboard.

                                             

                                            So, to sum it up, max document size is absolute and always is 16383 x 16383. Offset is not absolute. Do not use fixed values. Calculate it.

                                            • 19. Re: How to get bounds of largest possible document area?
                                              Silly-V Adobe Community Professional

                                              So I still want to know if there's any way you guys can get the global ruler offset if someone manually changes that in the UI.

                                               

                                              UI in illustrator uses local coordinate system (Artboard Rulers). Scriping uses global coordinate system (Global Rulers).

                                               

                                              They can simply change the rulers to Global by right-clicking the rulers.

                                              • 20. Re: How to get bounds of largest possible document area?
                                                cameronmcefee Level 1

                                                Here's what I ended up putting together. You'll have to forgive my coffeescript and proprietary stuff. DOC_MEASURE is 2^14 - 1. I also had to adjust the coordinate calculation a bit because path creation (coordinates) works differently than rectangle creation (origin + size).

                                                 

                                                 

                                                # Calculate the maximum boundaries of the document.
                                                #
                                                # Returns a rect array
                                                pasteboardRect = ->
                                                  artboards = activeDocument.artboards
                                                  i = artboards.getActiveArtboardIndex()
                                                  abRect = artboards[i].artboardRect
                                                  abWidth = abRect[2] - abRect[0]
                                                  abHeight = abRect[3] - abRect[1]
                                                  topLeft = Math.ceil(-DOC_MEASURE / 2)
                                                  centerX = (abRect[2].toFixed(5) - abRect[0].toFixed(5)) / 2
                                                  centerY = (abRect[3].toFixed(5) - abRect[1].toFixed(5)) / 2
                                                  xSubstr = if centerX < 0 then Math.floor(centerX) else Math.ceil(centerX)
                                                  ySubstr = if centerY < 0 then Math.floor(centerY) else Math.ceil(centerY)
                                                  [
                                                    topLeft + xSubstr  # left
                                                    -topLeft + ySubstr  # top
                                                    -((topLeft + xSubstr) - abWidth)  # right
                                                    -((-topLeft + ySubstr) - abHeight) # bottom
                                                  ]
                                                
                                                # Add a guide to the document.
                                                #
                                                #   str - guide string like 'h:10'
                                                #
                                                # Returns nothing.
                                                addGuide = (str) ->
                                                  return if activeDocument.activeLayer.locked
                                                  guide = _.guideToObject str
                                                  abLocation = _.a2d([guide.location, guide.location * -1])
                                                  _.log "Adding guide: #{ str }"
                                                  _.log JSON.stringify guide
                                                
                                                
                                                  pb = pasteboardRect()
                                                  path = activeDocument.activeLayer.pathItems.add()
                                                  path.guides = true
                                                  if guide.orientation is 'h'
                                                    path.setEntirePath [[pb[0], abLocation[1]], [pb[2], abLocation[1]]]
                                                  else
                                                    path.setEntirePath [[abLocation[0], pb[1]], [abLocation[0], pb[3]]]
                                                

                                                 

                                                Not shown is _.a2d and _.d2a which convert coordinates between the two systems. Thats where I do the ruler origin offset compensation. From my tests, artboard vs global origin is moot. My suspicion is that if you toggle on global rulers, artboard ruler origin still works, it's just tied to the global value instead.

                                                 

                                                # getActiveArtboard() is a custom method that gets a reference to the active artboard
                                                ruler = getActiveArtboard().rulerOrigin
                                                
                                                • 21. Re: How to get bounds of largest possible document area?
                                                  Silly-V Adobe Community Professional

                                                  Okay, not sure how to test this code - but using the above examples from pixxxel and akinuri I always got the following:

                                                  • change the artboard location : works
                                                  • change the artboard origin : works
                                                  • change the artboard origin and location : works
                                                  • switch to global rulers and change that origin : doesn't work

                                                   

                                                  My question is since our 'root' origin is the global rulers- what can we do about users messing with that origin?

                                                  • 22. Re: How to get bounds of largest possible document area?
                                                    cameronmcefee Level 1

                                                    > switch to global rulers and change that origin : doesn't work

                                                     

                                                    Can you clarify how you're doing that? So far my tests based on what I *think* you mean work fine.

                                                    • 23. Re: How to get bounds of largest possible document area?
                                                      akinuri Level 1

                                                      Do you mean changing the position of the global origin by dragging a new origin from the top left of the ruler? This would surely complicate the calculation of the offset.

                                                      • 24. Re: How to get bounds of largest possible document area?
                                                        Silly-V Adobe Community Professional

                                                        Yes, you (1) change the ruler to use global rulers, and (2) then drag the intersection corner.

                                                         

                                                        I think we'd be well off if it merely complicated the calculations, I am afraid though that altering the root origin makes calculation impossible.

                                                        • 25. Re: How to get bounds of largest possible document area?
                                                          akinuri Level 1

                                                          Theoretically, it can still be calculated. We have the initial offset that is the half size of the document profile. You can get the position of an artboard and save it, drag a new origin, and get the artboard's position again. Then calculate the difference between two positions. That'd give the offset.

                                                           

                                                          But the trouble is implementing this in Illustrator. I don't know if there are event listeners in Illustrator. For example, adding an event listener to "drag a new origin" and doing the calculation at that moment would really help.

                                                          • 26. Re: How to get bounds of largest possible document area?
                                                            Silly-V Adobe Community Professional

                                                            The users can drag their own origins, create their own document profiles and change the artboards and do so at any time, so I think it would be up to an .aip plugin to get that pasteboard- I'm going to get reading that PDF now, it's been a long time coming.

                                                            • 27. Re: How to get bounds of largest possible document area?
                                                              cameronmcefee Level 1

                                                              tl;dr: Illustrator bases the measurement on some sort of "original document size" value, not the current artboard size. Does anyone know how to find this value?

                                                               

                                                              Following up here, this code has been running in production for a few months now and hasn't had any origin related issues as feared, however I've discovered a pretty strange quirk. Before I get into the next phase of this discussion, here's the coffeescript that is powering it:

                                                               

                                                              DOC_MEASURE = 16383

                                                               

                                                              pasteboardRect = ->

                                                                artboards = activeDocument.artboards

                                                                i = artboards.getActiveArtboardIndex()

                                                                abRect = artboards[i].artboardRect

                                                                abWidth = abRect[2] - abRect[0]

                                                                abHeight = abRect[3] - abRect[1]

                                                                topLeft = Math.ceil(-DOC_MEASURE / 2)

                                                                centerX = (abRect[2].toFixed(5) - abRect[0].toFixed(5)) / 2

                                                                centerY = (abRect[3].toFixed(5) - abRect[1].toFixed(5)) / 2

                                                                xSubstr = if centerX < 0 then Math.floor(centerX) else Math.ceil(centerX)

                                                                ySubstr = if centerY < 0 then Math.floor(centerY) else Math.ceil(centerY)

                                                               

                                                                [

                                                                  topLeft + xSubstr   # left

                                                                  -topLeft + ySubstr  # top

                                                                  -((topLeft + xSubstr) - abWidth)  # right

                                                                  -((-topLeft + ySubstr) - abHeight) # bottom

                                                                ]

                                                               

                                                              The idea here is essentially:

                                                               

                                                              1. Get the rect of the artboard

                                                              2. Determine the center of the artboard

                                                              3. Subtract half of the document width/height from half of the max pasteboard width/height.

                                                               

                                                              This works perfectly… if you don't change the artboard size from the original value. However, if you resize the artboard, it throws the math off. This is not because the math is wrong, it's because the position appears to be tied to *the original artboard size*, not the current artboard size. I've tested this by swapping out the calculations for hard coded measurements based on the original size of the document and the guides go back to lining up.

                                                               

                                                              Does anyone know if there's some store of data in Illustrator documents that record the original size of the document when it was created? One would think that since this is part of the calculation, it would also be part of the APIs, but I've come to always assume the worst.

                                                              • 28. Re: How to get bounds of largest possible document area?
                                                                Silly-V Adobe Community Professional

                                                                Well, the code from akinuri above seems to not have this issue. Pixxxel's does however.

                                                                In fact, the only time akinuri's code fails is in my above outlined scenario where the user changes their global ruler origin - changing artboard size, position, or artboard origin are ok.

                                                                 

                                                                Otherwise, about your question - it may be possible - as long as the document has been saved, to glean the preset's name from the XMP data.

                                                                 

                                                                When I open a saved document and go to File > File Info, in the "Basic" section, there I can see the preset's name.

                                                                Problem is, not only does it have to be saved, but files that are created with any other way besides New File dialog, will have this field blank. These could be files generated by other programs or image files opened with AI too.

                                                                Screen Shot 2016-12-02 at 12.12.30 PM.png

                                                                • 29. Re: How to get bounds of largest possible document area?
                                                                  moluapple Level 4

                                                                  Hello all!

                                                                   

                                                                  You know, when rearrange artboards, it always center them in the Canvas. So I get this.(the sample code only deal with document with one artboard)

                                                                   

                                                                  var doc = activeDocument,
                                                                      rect = doc.artboards[0].artboardRect,
                                                                      rect2;
                                                                  
                                                                  doc.artboards.add([0, 0, 100, -100]);
                                                                  doc.artboards.add([0, 0, 1, -1]);
                                                                  doc.artboards[0].remove();
                                                                  doc.rearrangeArtboards(DocumentArtboardLayout.Row, 1, 0, false);
                                                                  
                                                                  rect2 = doc.artboards[0].artboardRect;
                                                                  doc.pathItems.rectangle(rect2[1] - 50 + 16383 / 2 + 24.5, rect2[0] + 50 - 16383 / 2 - 24.5, 16383, 16383).guides = true;
                                                                  
                                                                  doc.artboards.add(rect);
                                                                  doc.artboards[0].remove();
                                                                  doc.artboards[0].remove();
                                                                  
                                                                  • 30. Re: How to get bounds of largest possible document area?
                                                                    Silly-V Adobe Community Professional

                                                                    This works! I also realize that the code from akinuri also was susceptible to this issue, but I didn't happen to test with any other document than a default Print one, for which the values from that code were built to fit.

                                                                    • 31. Re: How to get bounds of largest possible document area?
                                                                      o-marat Level 3

                                                                      I use this:

                                                                      /**
                                                                       * Adobe ExtendScript for Illustrator CS4+
                                                                       * (c)Marat Shagiev
                                                                       * m_js@bk.ru
                                                                       * 04.12.2016
                                                                       * */
                                                                      //@target illustrator
                                                                      try {
                                                                        getWorkAreaBnds();
                                                                      } catch (e) {}
                                                                      /**
                                                                       * get the Illustrator's Document work area maximal bounds
                                                                       * work in document with multiple artboards, shifted center and selected objects
                                                                       *
                                                                       * this method using:
                                                                       * * copy-past max-size-rectangle (16383*16383 pt)
                                                                       * * the Document.view properties (zoom, centerPoint, screenMode)
                                                                       *
                                                                       * @return{Array} workAreaBnds - Illustrator's Document work area maximal bounds
                                                                       * */
                                                                      function getWorkAreaBnds() {
                                                                        var sel = _deselAll();
                                                                        var WORK_AREA_SIZE  = 16383,
                                                                            d               = activeDocument,
                                                                            rect            = d.pathItems.rectangle(0, 0, WORK_AREA_SIZE, WORK_AREA_SIZE),
                                                                            workAreaBnds,
                                                                            screenModeStore = d.views[0].screenMode,
                                                                            zoomStore       = d.views[0].zoom,
                                                                            centerPntStore  = d.views[0].centerPoint;
                                                                        rect.stroked  = false;
                                                                        rect.selected = true;
                                                                        cut();
                                                                        d.views[0].screenMode = ScreenMode.FULLSCREEN;
                                                                        d.views[0].zoom       = 64;
                                                                        d.views[0].zoom       = 0.0313;
                                                                        paste();
                                                                        rect         = selection[0];
                                                                        workAreaBnds = rect.geometricBounds;
                                                                        rect.remove();
                                                                        d.views[0].zoom        = zoomStore;
                                                                        d.views[0].screenMode  = screenModeStore;
                                                                        d.views[0].centerPoint = centerPntStore;
                                                                        for (var i = 0; i < sel.length; i++) {
                                                                          var item      = sel[i];
                                                                          item.selected = true;
                                                                        }
                                                                        function _deselAll() {
                                                                          var sel = selection;
                                                                          for (var i = 0; i < activeDocument.layers.length; i++) {
                                                                            activeDocument.layers[i].hasSelectedArtwork = false;
                                                                          }
                                                                          return sel;
                                                                        }
                                                                        return workAreaBnds;
                                                                      }
                                                                      
                                                                      
                                                                      • 32. Re: How to get bounds of largest possible document area?
                                                                        Silly-V Adobe Community Professional

                                                                        Wow, that's very creative! It really works!

                                                                        • 33. Re: How to get bounds of largest possible document area?
                                                                          cameronmcefee Level 1

                                                                          So far all of the examples are susceptible to the artboard resize issue with the exception of o-marat's version. That one works well, but unfortunately I'm not thrilled about the flash of UI that comes with it. The search continues…

                                                                          • 34. Re: How to get bounds of largest possible document area?
                                                                            moluapple Level 4

                                                                            Only tested with CS6 but it works, no matter artboards been resized or not.

                                                                            var d = activeDocument,
                                                                                rect,
                                                                                rects = [],
                                                                                abs = d.artboards,
                                                                                z = d.views[0].zoom,
                                                                                cp = d.views[0].centerPoint,
                                                                                i;
                                                                            
                                                                            abs.add([0, 1, 1, 0]);
                                                                            abs.add([0, 1, 1, 0]);
                                                                            
                                                                            for (i = abs.length - 3; i >= 0; i--) {
                                                                                rects.push([abs[i].artboardRect, abs[i].name]);
                                                                                abs[i].remove();
                                                                            }
                                                                            
                                                                            d.rearrangeArtboards(DocumentArtboardLayout.Row, 1, 0, false);
                                                                            
                                                                            rect = abs[0].artboardRect;
                                                                            d.pathItems.rectangle(rect[1] - 0.5 + 16383 / 2, rect[0] + 0.5 - 16383 / 2, 16383, 16383).guides = true;
                                                                            
                                                                            for (i = rects.length - 1; i >= 0; i--) {
                                                                                abs.add(rects[i][0]).name = rects[i][1];
                                                                            }
                                                                            
                                                                            abs[0].remove();
                                                                            abs[0].remove();
                                                                            
                                                                            d.views[0].zoom = z
                                                                            d.views[0].centerPoint = cp;
                                                                            
                                                                            
                                                                            2 people found this helpful
                                                                            • 35. Re: How to get bounds of largest possible document area?
                                                                              cameronmcefee Level 1

                                                                              Ah nice, that one does seem to work on the test file I'm using. While I generally understand what's happening with the code, I'm curious what prevents it from actually rearranging the artboards?

                                                                              • 36. Re: How to get bounds of largest possible document area?
                                                                                moluapple Level 4

                                                                                Well, let's add some comments:

                                                                                Line 13: log the position and name of original artboards,

                                                                                Line 14: remove them, so rearranging (Line 17) only affect 2 new added artboards,

                                                                                Line 23: Re-create artboards.

                                                                                • 37. Re: How to get bounds of largest possible document area?
                                                                                  Silly-V Adobe Community Professional

                                                                                  A great puzzle of our time, solved with the means we have! Wonderful!

                                                                                  • 38. Re: How to get bounds of largest possible document area?
                                                                                    cameronmcefee Level 1

                                                                                    Ah, ok that makes sense now. I was wondering why the name was being set. Thanks a lot moluapple!