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

Move Multiple selected items to new layer

Contributor ,
Feb 19, 2019 Feb 19, 2019

Copy link to clipboard

Copied

Hi,

    

     I need to move selected objects into new layer.  When I do this, moved objects are gone back and showing like empty textframes and rectangle. But when i do this in manual, there is no changes in visibility and its all moved to new layer.  When i try in script having issue. I don't know what should i do or follow any other steps?

     Selection contains multiple kinds of objects (Textframes, rectangles). How to do this without changing visibility of objects like as manual process moving?

Code:

if(app.selection.length > 0)

{

   

var newLayer = app.activeDocument.layers.add({name:"Test"});
newLayer.move ( LocationOptions.AT_END );

   

var Objs = app.selection;
for(var cnt = 0; cnt < Objs.length; cnt++)
{
     Objs[cnt].itemLayer = newLayer;
    //Objs[cnt].bringToFront();
    alert("Objs[cnt]" +Objs[cnt].constructor.name)
}
alert("Moved")

}

Thanks,

Sudha K

TOPICS
Scripting

Views

1.8K

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

Community Expert , Feb 20, 2019 Feb 20, 2019

Hi Sudha,

the reason is that the stacking order of elements changed when your scrpt run is done.

Selection order not necessarily means stacking order. Your background rectangle simply obscures your two text frames.

Since you are working with InDesign CS6 you can simply do:

1. Loop all items selected and store them in an array.

2. Add a new group to the active spread. As argument for method add() of groups.add() use the array with your selected items.

3. Use itemLayer of the new group to assign the gro

...

Votes

Translate

Translate
Community Expert ,
Feb 19, 2019 Feb 19, 2019

Copy link to clipboard

Copied

Can you add some screenshots on what you get when doing the operation manually and what happens with your script

-Manan

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 ,
Feb 19, 2019 Feb 19, 2019

Copy link to clipboard

Copied

Hi Manan,

I guess Sudha likes to access property itemLayer for every selected object and the stacking order of objects should remain the same. If the selected objects are not nested inside a group or nested otherwise one could do the following:

1. Group all selected objects.

2. Set itemLayer of the group to the new layer.

3. Ungroup the group.

That would require:

app.generalPreferences.ungroupRemembersLayers = false;

( Available at least for InDesign CC 2015 and above )

Or one would see into the stacking order of spread.allPageItems to identify the selected items in the reverse order that itemLayer should be applied.

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 ,
Feb 19, 2019 Feb 19, 2019

Copy link to clipboard

Copied

Hi Sudha,

what's your version of InDesign?

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
Contributor ,
Feb 20, 2019 Feb 20, 2019

Copy link to clipboard

Copied

Hi,

     Thank you for your reply..

     I am using InDesign CS6. What I am doing is.

     1. Select all objects between the bounds in the indesign file.

     2. Adding new layer and moving the selected objects into the new layer.

     When i do it in manual no issue, but in automation objects i think objects were gone back. So could not able to view the objects same as manual process done . Please refer the below screenshots.

Before.png

After.png

     When i select the objects and move it to new layer, there is no change in view.  I need to retain it in script. used bring to front in script but no difference. I don't know the reason.

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 ,
Feb 20, 2019 Feb 20, 2019

Copy link to clipboard

Copied

Hi Sudha,

the reason is that the stacking order of elements changed when your scrpt run is done.

Selection order not necessarily means stacking order. Your background rectangle simply obscures your two text frames.

Since you are working with InDesign CS6 you can simply do:

1. Loop all items selected and store them in an array.

2. Add a new group to the active spread. As argument for method add() of groups.add() use the array with your selected items.

3. Use itemLayer of the new group to assign the group to the new layer.

4. Ungroup the group and you are done.

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 ,
Feb 20, 2019 Feb 20, 2019

Copy link to clipboard

Copied

Also note, that you are moving your new layer to the bottom of all other layers.

Don't know if that is intended.

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
Contributor ,
Feb 20, 2019 Feb 20, 2019

Copy link to clipboard

Copied

Hi,

     I will check that the process which you said above and get back.

     layer.png

          I have tried this option due that issue.  Layer order is not an issue then i don't want this.

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
Contributor ,
Feb 20, 2019 Feb 20, 2019

Copy link to clipboard

Copied

Hi,

     Thank you.. its working...

     Issue is the order of the elements which i selected.  when i selecting image frame is overlapped and its came front so all objects gone back right?

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 ,
Feb 20, 2019 Feb 20, 2019

Copy link to clipboard

Copied

Hi Sudha,

the only way I know to control selection order with InDesign's UI is to select one object, then hold the Shift key and add a new item to the selection by clicking a different object. If you do that in stacking order your first script will run ok if you run the loop in reverse.

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
Contributor ,
Feb 20, 2019 Feb 20, 2019

Copy link to clipboard

Copied

Hi,

     Thank you... How to hold the shift key in script? I thought select all object is shift selection.

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 ,
Feb 20, 2019 Feb 20, 2019

Copy link to clipboard

Copied

You could add an item to a selection like that:

var currentSelection = app.selection;

var somethingToAdd = app.documents[0].layoutWindows[0].activeSpread.rectangles.add({ geometricBounds : [0,0,50,50]});

app.select( somethingToAdd , SelectionOptions.ADD_TO );

See the second argument of method select().

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
Contributor ,
Feb 20, 2019 Feb 20, 2019

Copy link to clipboard

Copied

Thank you for your sample code...

I have used the below method to select the objects.

if(itmCnt == 0)

{

     cPgItm.select();

}else{

     cPgitm.select(SelectionOptions.addTo);

}

Is it different from shift selection?

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 ,
Feb 20, 2019 Feb 20, 2019

Copy link to clipboard

Copied

Hi Sudha,

don't know what you are aiming at…

What is itmCnt in your snippet? The length of you current selection?

That does not matter. Even if nothing is selected cPgitm.select( SelectionOptions.ADD_TO ) should work if the item in variable cPgitm is selectable. Or even if it already 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
Contributor ,
Feb 20, 2019 Feb 20, 2019

Copy link to clipboard

Copied

LATEST

Hi,

     itmCnt is searching object count (within bounds) and cPgitm is pageItem.

     Process:

          1. Select objects within specific bounds.

          2. Move into new layer.

     Its working in the way which you said.  But i wanted to know my error.

     Steps followed in Code:

          1. Search and select the pageitems using allPageItems using select method which i said above.  itmCnt is used to count the objects within the bounds and also used for select methods.

          2. Once selected multiple objects, i have used my old code to move into new layer.

     When i follow this process in code, i got that issue.  Your solution is working but i want to know reason of issue occurred in my side. Becuase i have used that method to select the objects.  if it is different from shift selection then i will check what it is. For my understanding only raising so many ques. Sorry...

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