Skip to main content
Inspiring
April 14, 2016
Answered

app.select with group problem

  • April 14, 2016
  • 2 replies
  • 456 views

I'm having a problem with selecting groups in a script: when I use app.select it selects the COMPONENTS of the group, not the group itself.

myGroup=[]

myGroup.push(obj1);

myGroup.push(obj2);

currentPage.groups.add(myGroup);

which creates the group.

app.select(myGroup)

does NOT select the group -- instead i selects obj1 and obj2

(I want to make the group an anchored object, so I need to select, cut, select insertionPoint, paste -- but you can't paste 2 selected objects...)

Anyone now what's wrong?

Thanks

This topic has been closed for replies.
Correct answer Vamitul

myGroup=[]

myGroup.push(obj1);

myGroup.push(obj2);

myInddGroup=currentPage.groups.add(myGroup);

app.select(myInddGroup)

___edit__

Take note that using things like copy() and paste() is quite a bad way to do a script.

Better would be something like:

myInddGroup.anchoredObjectSettings.insertAnchoredObject(insertionPoint, AnchorPosition.INLINE_POSITION);

2 replies

Community Expert
April 14, 2016

Hi Akiva,

your variable myGroup is a simple Array object where two pageItems seem to be stored.

If you do app.select(myGroup) you infact do:

app.select([pageItem,pageItem]);

and that will select the listed items, not the group you are building out of them.

Just change the names of the variables to see this more clearly:

var myArrayOfPageItems = [];

myArrayOfPageItems.push(obj1);

myArrayOfPageItems.push(obj2);

// the method add() of object Group returns a Group object:

var myGroup = currentPage.groups.add(myArrayOfPageItems);

app.select(myGroup);

And if you want to anchor the group, you could use the anchoredObjectSettings of the group like that:

// Tested with values in millimeters

var doc = app.documents.add();

var pageItemOne = doc.rectangles.add({geometricBounds : [0,0,20,20]});

var pageItemTwo = doc.rectangles.add({geometricBounds : [20,20,40,40]});

var group = doc.pages[0].groups.add( [ pageItemOne , pageItemTwo ] );

var textFrame = doc.textFrames.add({geometricBounds : [ 50,50,100,100 ] });

var insertionPoint = textFrame.insertionPoints[0];

// InDesign CS5.5 and above:

group.anchoredObjectSettings.insertAnchoredObject(insertionPoint , AnchorPosition.ANCHORED);

Hope that helps,

Uwe

Inspiring
April 14, 2016

Thanks -- I can't believe I made that mistake...

Vamitul
VamitulCorrect answer
Legend
April 14, 2016

myGroup=[]

myGroup.push(obj1);

myGroup.push(obj2);

myInddGroup=currentPage.groups.add(myGroup);

app.select(myInddGroup)

___edit__

Take note that using things like copy() and paste() is quite a bad way to do a script.

Better would be something like:

myInddGroup.anchoredObjectSettings.insertAnchoredObject(insertionPoint, AnchorPosition.INLINE_POSITION);

Community Expert
April 14, 2016

Hi Vamitul,

yes indeed and while working with selections one has to work within a single spread, because InDesign cannot select pageItems simultaniously on different spreads. Also, InDesign Server does know nothing about active objects or selections.

Uwe