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

Javascript command: "select content"

New Here ,
Dec 18, 2019 Dec 18, 2019

Hi. I have start to learn write Javascript for InDesign.

And now I have problem.

I have rectangle named "logo" at 2nd page, inside this rectangle is group of objects, I want to remove this rectangle, but leave group at same place. In InDesign, I am use to click at rectangle with black arrow, then click icon "select content", Command+X, Command+Alt+Shift+V.

I tried to write it to script, but it doesn't work. What is wrong?

app.select(app.activeDocument.pages.item(1).rectangles.itemByName ('logo').allGraphics);
app.copy()
app.pasteInPlace();

 

 

Thx for your help. 🙂

TOPICS
Scripting
1.1K
Translate
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 ,
Dec 18, 2019 Dec 18, 2019

It's tempting to write scripts as if you are recording literal keystrokes, and actually this can bring you quite far – but some time you'll have to let go, and learn to manipulate the world without touching it. In other words, "there is no spoon".

 

I don't know what could be wrong with your code but this is the spoon-less way to do it:

app.selection[0].groups[0].duplicate (app.selection[0].itemLayer);

 (with this, you have to select the spoon. But your method of selecting-by-name should also work.)

 

Noteworthy: InDesign complains when you use 'move' instead of 'duplicate'. It specifically says in the error message that you need to select "a single group" ... which is what I do! There must be some other restriction at work. "duplicate", targeting another layer, implicitly does a copy-then-paste-in-place, and so you can delete the original item immediately afterwards.

Translate
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 ,
Dec 18, 2019 Dec 18, 2019

Hi zzero,

your method by selecting something would work if you do not work with the allGraphics array.

Just do it with the first item of the rectangle. Or, if you are sure the first item is indeed a group work with the first group of the rectangle named "logo".

 

app.select( app.activeDocument.pages.item(1).rectangles.itemByName ('logo').pageItems[0] );
app.copy()
app.pasteInPlace();

 

Or:

app.select( app.activeDocument.pages.item(1).rectangles.itemByName ('logo').groups[0] );
app.copy()
app.pasteInPlace();

 

Best practice is:

If you are working with select() define the spread you are working with as the active spread of the layout window.

In your case this could be done like that:

 

app.activeDocument.layoutWindows[0].activeSpread =
app.activeDocument.pages[1].parent;

 

Regards,
Uwe Laubender

( ACP )

Translate
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 ,
Dec 18, 2019 Dec 18, 2019

FWIW: The allGraphics array would contain any number of images and graphics that are contained by an object.

I guess there was no placed image or graphic inside your rectangle. Otherwise you would have copied the image(s) to the clipboard.

 

Below a rectangle with a group of ovals where two ovals contain placed images:

 

Rectangel-PastedInsideGroup-with-Ovals-1.PNG

 

If I now run this little snippet on the selected rectangle:

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

 

InDesign will do what is required to select all graphics ( images as well ) of the selected rectangle.

Something you cannot do in the UI, I think:

 

Rectangel-PastedInsideGroup-with-Ovals-AllGraphics-2.PNG

 

To copy that selection, to remove the rectangle and to do Paste In Place would lead to a result like this:

 

CutTheSelection-of-AllGraphics-PasteInPlace-Result.PNG

 

 

Regards,
Uwe Laubender

( ACP )

Translate
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 ,
Dec 19, 2019 Dec 19, 2019
LATEST

Thx all of you, I will try all methods (I am learning scripting).

As first I tried Laubender's and it solved my problem.

🙂

Translate
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