• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

How using Extendscript to direct select items in a group?

Explorer ,
Nov 17, 2016 Nov 17, 2016

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:

DirectSelection-0.png

What I want to have happen is:

DirectSelection-2.png

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

TOPICS
Scripting

Views

5.9K

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Mentor , Nov 17, 2016 Nov 17, 2016

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

Votes

Translate

Translate
Mentor ,
Nov 17, 2016 Nov 17, 2016

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Nov 27, 2018 Nov 27, 2018

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?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Nov 27, 2018 Nov 27, 2018

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Nov 27, 2018 Nov 27, 2018

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Nov 27, 2018 Nov 27, 2018

Copy link to clipboard

Copied

LATEST

There is a specialized forum for Illustrator scripting:

Illustrator Scripting

Regards,
Uwe

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Nov 18, 2016 Nov 18, 2016

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:

Select-Group.pageItems.everyItem.png

2. If you want to work with allPageItems :

// A group is selected:

app.select(app.selection[0].allPageItems);

Example screenshot:

Select-Group.allPageItems.png

Note: Also the grouped group itself is selected and also the pasted inside rectangle (yellow) inside that grouped group is selected.

Regards,
Uwe

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Nov 18, 2016 Nov 18, 2016

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:

Select-TwoPageItems-of-Group-with-DirectSelectionTool.png

Regards,
Uwe

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Nov 18, 2016 Nov 18, 2016

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:

Select-TwoPageItems-of-Group-with-SelectionTool.png

Regards,
Uwe

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines