Copy link to clipboard
Copied
This seems like it'd be an extremely easy thing to do, but I'm unable to figure it out after searching forums, google, and the scripting documentation. I'm trying to just group whatever items are selected when I run the script. Some of the things I've tried are:
var document = app.activeDocument;
var selection = document.selection;
//this doesn't work, I get 'invalid parameter'
//for the groups.add() function.
var group = document.groups.add(selection);
//same here, I get invalid parameter on groups.add()
var itemArray = new Array;
for (var i in selection) {
itemArray.push(i);
}
var group = document.groups.add(itemArray);
//also doesn't work. Debugging shows that the itemArray.push()
//is never reached, so the isPrototypeOf isn't working like I expect.
var itemArray = new Array;
for (var i in selection) {
if (i.prototype.isPrototypeOf(PageItem)) {
itemArray.push(i);
}
}
var group = document.groups.add(itemArray);
Do I just have something fundamentally wrong with how I'm trying to approach this? I'm new to Javascript, I've worked a lot with Java (Don't worry, I know they're completely unrelated), but I've got a few other scripts working, this particular issue I can't seem to figure out, though.
Thoughts?
Thanks!
groups.add indeed only accepts an array of page items.
//same here, I get invalid parameter on groups.add()
var itemArray = new Array;
for (var i in selection) {
itemArray.push(i);
}
var group = document.groups.add(itemArray);
//also doesn't work. Debugging shows that the itemArray.push()Your "for" loop syntax is wrong. Use this:
for (var i=0; i<selection.length; i++)
itemArray.push (selection);
That ought to make it work, methinks.
I guess you don't have to explicitly check if your selectio
...Copy link to clipboard
Copied
groups.add indeed only accepts an array of page items.
//same here, I get invalid parameter on groups.add()
var itemArray = new Array;
for (var i in selection) {
itemArray.push(i);
}
var group = document.groups.add(itemArray);
//also doesn't work. Debugging shows that the itemArray.push()Your "for" loop syntax is wrong. Use this:
for (var i=0; i<selection.length; i++)
itemArray.push (selection);
That ought to make it work, methinks.
I guess you don't have to explicitly check if your selection are page items -- or perhaps you only have to check the very first item. It's impossible to select both a text range and page items ![]()
Copy link to clipboard
Copied
I could have sworn I'd tried that already to the same effect! Yet, it worked.
![]()
Thank you very much, that did the trick. Figures it was something simple!
Copy link to clipboard
Copied
Also, you can't make group in "document" you need to target "page" instead.
So this would work:
myObj = app.selection;
app.activeWindow.activePage.groups.add(myObj);
Or this:
myObj = app.selection;
app.activeDocument.pages[0].groups.add(myObj);
Hope that helps.
--
tomaxxi
http://indisnip.wordpress.com/
http://inditip.wordpress.com/
Get ready! An upgraded Adobe Community experience is coming in January.
Learn more