9 Replies Latest reply on Sep 5, 2017 7:48 AM by daneJ

    stack overflow limit

    daneJ Level 1

      Hello all

       

      having a problem.

      I have recursive script that runs through a groupitem of groupitems and seelets the left half of the group. Groups with in groups with in groups with in . . .

      This works on simpler illustrations but some of the groupitems recursively call the function so many times that i get a stack overflow. Obviouly designed to protect your computer etc, however in my case i simply need more recursion then is allowed.

      How can i change the stack limit. or any kind of workaround for overflow limits.

       

      Many thanks in advance.

       

      Dane

        • 1. Re: stack overflow limit
          Silly-V Adobe Community Professional

          Hello, sounds like an interesting and frustrating problem. Can you post the recursive function?

          • 2. Re: stack overflow limit
            moluapple Level 4

            Another way:

            Deselect all, select the groupItem, then loop through activeDocument.pageItems, if pageItems[i].selected == true, it belongs to the groupItem, then check it's groupItem or not, is not, go ahead to see it's left half or not.

            • 3. Re: stack overflow limit
              daneJ Level 1

              below is the recursive bit.

              I may not be so tidy. Sorry about that.

              Ain't no profi.

              thanks for taking a look.

               

              function leftgroupcontent(a2,lateralCounter, preGroup,more){

                  var y= 0

                  var x = 0

                  while (this.more != false){

                      for (x = (aSelectItems.length -1); x > -1 ; x--){ 

                          var a1 = aSelectItems[x]

                         

                          if (a2 == ""){

                              var curGroup = aGroup[a1]

                          }

                          else {

                               var curGroup = a2[a1]

                          }

                          if (curGroup.length>0){

                              for (y = 0; y < curGroup.length; y++){

                                  var abc = curGroup[y]

                                  if (back == false ){

                                      if (curGroup[y].controlBounds[2] > aHalfWidth && x != 0) {

                                          curGroup[y].selected = false                   

                                          }

                                      else if (curGroup[y].controlBounds[0] > aHalfWidth) {

                                          curGroup[y].selected = false

                                          }

                                      else if (a2 == "" && x == 0) {

                                          var preGroup = [[curGroup], [curGroup.length], [curGroup.length]]

                                          a2 = curGroup[y]

                                          aaa = leftgroupcontent (a2, 0, preGroup)

                                          }

                                      else if (a2 != "" && x == 0) {

                                          if (curGroup.length != 0) {

                                          preGroup[0].push(curGroup)

                                          preGroup[1].push(curGroup.length)

                                          preGroup[2].push(curGroup.length)

                                          }

                                          a2 = curGroup[y]

                                          aaa = leftgroupcontent (a2, 0, preGroup)

                                          }

                                      }

                                  else{

                                        if (curGroup[y].controlBounds[2] < aHalfWidth && x != 0) {

                                          curGroup[y].selected = false                   

                                          }

                                      else if (curGroup[y].controlBounds[2] < aHalfWidth) {

                                          curGroup[y].selected = false

                                          }

                                      else if (a2 == "" && x == 0) {

                                          var preGroup = [[curGroup], [curGroup.length], [curGroup.length]]

                                          a2 = curGroup[y]

                                          aaa = leftgroupcontent (a2, 0, preGroup)

                                          }

                                      else if (a2 != "" && x == 0) {

                                          if (curGroup.length != 0) {

                                          preGroup[0].push(curGroup)

                                          preGroup[1].push(curGroup.length)

                                          preGroup[2].push(curGroup.length)

                                          }

                                          a2 = curGroup[y]

                                          aaa = leftgroupcontent (a2, 0, preGroup)

                                          }

                                      }

                                  }

                              }

                          if (a2 != "" && x == 0){

                                     

                                      while (this.more != false){

                                          var lateralCounter = lateralCounter+1

                                           if ( preGroup[1][(preGroup[1].length - 1)] > 0 && lateralCounter <  preGroup[1][(preGroup[1].length - 1)]  && preGroup[2][(preGroup[1].length - 1)] > 0){

                                              a2 = preGroup[0][(preGroup[0].length -1)]

                                              var aab=a2[lateralCounter]

                                              var preLeftOver = lateralCounter

                                              preGroup[2][(preGroup[1].length - 1)] = preGroup[2][(preGroup[1].length - 1)] - 1

                                              aaa = leftgroupcontent (a2[lateralCounter],lateralCounter, preGroup, more)

                                          }

                                          else if (preGroup[1].length - 1 == 0) {

                                              this.more = false

                                              }

                                          else{

                                              preGroup[2].pop()

                                              preGroup[1].pop()

                                              preGroup[0].pop()

                                              var lateralCounter = 0

                                              }

                                          

                                       }

                               }

                      

                          }

                  }

              }

              • 4. Re: stack overflow limit
                daneJ Level 1

                interesting idea.

                I find the groupitems structure very difficult to work with.

                maybe page items are easier.

                • 5. Re: stack overflow limit
                  Loic.Aigon Adobe Community Professional

                  Probably possible to lighten your code. Nested loops are always not a good idea.

                  Feel free to share a sample document and a capture of what you want to achieve.

                  • 6. Re: stack overflow limit
                    Silly-V Adobe Community Professional

                    I think there's probably some bug which prevents "this.more != false" from being false some some situations.

                    What I'd do is use approach of moluapple, if selections are allowed, or capture all needed items in one linear array which can be processed for deciding what's on the right/left.

                    • 7. Re: stack overflow limit
                      daneJ Level 1

                      Amazing.

                      This solution is so simple and light and slick.

                      Thank you very much.

                       

                      the new code:

                       

                      var aiApp = app.activeDocument;

                      var aSelection = aiApp.selection;

                      var aGroup = app.activeDocument.groupItems.add();

                      var aPages = aiApp.pageItems

                      aGroup.name = "NewStyle"

                      for (i=0; i < aSelection.length; i++){

                      aSelection[i].move( aGroup, ElementPlacement.INSIDE);

                      aSelection[i].move( aGroup, ElementPlacement.PLACEATEND); 

                      }

                      aGroup.translate(0,700)

                      aGroup.resize(200, 200, true , true, true, true, 200)

                      var aHalfWidth= aGroup.controlBounds[2] - ((aGroup.controlBounds[2] - aGroup.controlBounds[0]) / 2)

                      for (x = 0; x < aPages.length ; x++){

                           var a = aPages[x]

                           if (a.typename == "GroupItem" && a.controlBounds[0] > aHalfWidth) {

                              a.selected = false

                              }

                          else if (a.typename != "GroupItem" && a.controlBounds[2] > aHalfWidth){

                              a.selected = false

                           }

                      }

                      • 8. Re: stack overflow limit
                        daneJ Level 1

                        well "this.more != false" actually seemed to work.

                        The code did work just fine for simpler groups.

                        but you are right. moluapple was the way to go.

                        very simple.

                        • 9. Re: stack overflow limit
                          daneJ Level 1

                          daneJ  wrote

                           

                          The code did work just fine for simpler groups.

                           

                          just fine meaning 10x slower than moluapple's solution.