Copy link to clipboard
Copied
Using extend script I want to direct select objects that are contained within a container (group). If I select the group, I get this:
What I want to have happen is:
I have the code so far:
{
var obj = (this.textFrame.parent.toString() == "[object Group]") ? this.textFrame.parent : this.textFrame;
if (obj.toString() == "[object Group]")
{
for (i= 0; i < obj.allPageItems.length; i++)
{
try {
obj.allPageItems.select();
} catch (e)
{
logger.warn("item in group " + obj.toString() + " can not be selected: " + e);
}
}
} else {
obj.select();
}
}
How to ensure that the selection is extended to ensure that all items within the group are selected?
Thanks
Hi,
Use an option of method object.select()
Assuming some group is selected and your goal is to select ONLY textFrames from this group:
var
mGroupItems = app.selection[0].allPageItems,
cItem;
app.selection[0] = null;
while (cItem = mGroupItems.pop())
if (cItem.constructor.name == "TextFrame")
cItem.select(SelectionOptions.ADD_TO);
Notice: You can use object.constructor.name to detect which object is targeted currently.
Jarek
Copy link to clipboard
Copied
Hi,
Use an option of method object.select()
Assuming some group is selected and your goal is to select ONLY textFrames from this group:
var
mGroupItems = app.selection[0].allPageItems,
cItem;
app.selection[0] = null;
while (cItem = mGroupItems.pop())
if (cItem.constructor.name == "TextFrame")
cItem.select(SelectionOptions.ADD_TO);
Notice: You can use object.constructor.name to detect which object is targeted currently.
Jarek
Copy link to clipboard
Copied
Can you please explain what kind of var is cItem? It keeps breaking for me and I am trying to understand what it is instantiated to.
Also, I can't find any reference to app.select in the Official reference... did it change since?
Copy link to clipboard
Copied
Hi,
look for Application in the reference.
There you'll see that select() is also a method of application.
https://www.indesignjs.de/extendscriptAPI/indesign-latest/#Application.html
https://www.indesignjs.de/extendscriptAPI/indesign-latest/#Application.html#d1e42185__d1e48212
FWIW: variable cItem in Jump_Over's code is a single pageItem.
It's coming from the allPageItems array of the first item of the selection, a group in this example, that will contain all page items of the selected group regardless of the depth they are nested.
Regards,
Uwe
Copy link to clipboard
Copied
Thank you. I have been trying to make this work in Ilustrator, but to no avail. 😕 Was hoping that ExtendScript would be similar between the two applications.
Copy link to clipboard
Copied
Copy link to clipboard
Copied
Hi Bill,
if you want to select:
1. All level one pageItems inside a group:
// A group is selected:
app.select(app.selection[0].pageItems.everyItem().getElements());
Example screenshot:
2. If you want to work with allPageItems :
// A group is selected:
app.select(app.selection[0].allPageItems);
Example screenshot:
Note: Also the grouped group itself is selected and also the pasted inside rectangle (yellow) inside that grouped group is selected.
Regards,
Uwe
Copy link to clipboard
Copied
But this might not what you want.
As I can see from your second screenshot the path points of some objects are highlighted.
You could turn to the Direct Selection Tool first and then do the selection of some of the objects inside of the group.
Example:
// NOTHING IS SELECTED, BUT YOU HAVE IDENTIFIED THE GROUP:
var group = app.documents[0].groups[0];
// Make the Direct Selection Tool the current one:
app.toolBoxTools.currentTool = UITools.DIRECT_SELECTION_TOOL;
// Then do the selection:
app.select([group.pageItems[1], group.pageItems[2]]);
Screenshot:
Regards,
Uwe
Copy link to clipboard
Copied
Here the result, if you are using the Selection Tool:
// In this variant a [object Group] IS selected:
var item1 = app.selection[0].pageItems[1];
var item2 = app.selection[0].pageItems[2];
// Define your selection tool:
app.toolBoxTools.currentTool = UITools.SELECTION_TOOL;
// Alternatively use the Direct Selection Tool:
// app.toolBoxTools.currentTool = UITools.DIRECT_SELECTION_TOOL;
// Deselect everything first:
app.select(null);
// Then select the two items of interest:
app.select( [ item1 , item2 ] );
It depends what you want to do as next step, if the Selection Tool or the Direct Selection Tool is the right one for you to use if you selectively doing a selection:
Regards,
Uwe