Copy link to clipboard
Copied
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
Another way:
Deselect all, select the groupItem, then loop through activeDocument.pageItems, if pageItems.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.
Copy link to clipboard
Copied
Hello, sounds like an interesting and frustrating problem. Can you post the recursive function?
Copy link to clipboard
Copied
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
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
if (back == false ){
if (curGroup
curGroup
}
else if (curGroup
curGroup
}
else if (a2 == "" && x == 0) {
var preGroup = [[curGroup], [curGroup.length], [curGroup.length]]
a2 = curGroup
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
aaa = leftgroupcontent (a2, 0, preGroup)
}
}
else{
if (curGroup
curGroup
}
else if (curGroup
curGroup
}
else if (a2 == "" && x == 0) {
var preGroup = [[curGroup], [curGroup.length], [curGroup.length]]
a2 = curGroup
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
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
}
}
}
}
}
}
Copy link to clipboard
Copied
Another way:
Deselect all, select the groupItem, then loop through activeDocument.pageItems, if pageItems.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.
Copy link to clipboard
Copied
interesting idea.
I find the groupitems structure very difficult to work with.
maybe page items are easier.
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
daneJ wrote
The code did work just fine for simpler groups.
just fine meaning 10x slower than moluapple's solution.
Copy link to clipboard
Copied
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.move( aGroup, ElementPlacement.INSIDE);
aSelection.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
if (a.typename == "GroupItem" && a.controlBounds[0] > aHalfWidth) {
a.selected = false
}
else if (a.typename != "GroupItem" && a.controlBounds[2] > aHalfWidth){
a.selected = false
}
}