myDoc is defined.
They are both unsaved documents
item.parent.name returns 16 for both.
And just to add another twist CS3 it throws the same error and in CS5 it works using itemByName.
Hi Fred,
The problem sounds to come from the fact that InDesign does not allow us to group objects from anywhere.
As ID users, we know that the objects must share the same spread. At the scripting level, the statement myDoc.groups.add(arrayOfItems) is potentially defective because there is no guarantee that the objects passed as arguments belong to the same spread. I don't know how the Scripting DOM internally deal with this risk, but I think that the safe way to group objects should be to always invoke .groups.add(...) from the right Spread or Page object.
You indicate that “item.parent.name returns 16 for both [objects],” from which I conclude that your text frames probably belong to Page 16 of your document. When you test your script on a new document that contains a copy of the text frames, it suddenly works because (I suppose) the items now belong to Page 1. And I guess that myDoc.groups.add(...) has a default behavior which consists on delegating the method to the first spread of myDoc. It may be implicitly equivalent to: myDoc.spreads[0].groups.add(...).
If my hypothesis is correct, this explains why myDoc.groups.add( [tf1, tf2] ) fails when the items belong to another spread.
So, give a try to this statement:
tf1.parent.groups.add( [tf1,tf2] );
@+
Marc
EDIT: In CS5, myDoc.groups.add(...) seems to be more tolerant in that it probably finds itself the right parent receiver, and validates the action if grouping is possible.