Skip to main content
Known Participant
March 5, 2008
Question

[js ][cs2] Move graphic to other layer

  • March 5, 2008
  • 9 replies
  • 776 views
Hi,

Does aynone know how to specify the location on moving a graphic?

if (app.activeDocument.layers.item('Graphics')== false){
app.activeDocument.layers.add ({name: 'Graphics', layerColor: UIColors.blue});
}

for(var z=0;app.activeDocument.allGraphics.length>z;z++){
app.activeDocument.allGraphics.move({'Graphics'});
}

Thanks a lot any feedback,

Tim
This topic has been closed for replies.

9 replies

Inspiring
March 6, 2008
Use constructor.name and then use capitalized names:

switch(app.activeDocument.allGraphics.parent.parent.constructor.name){
case 'Page':
// do something
break;
case 'Character':
// do something
break;
}

Dave
Known Participant
March 6, 2008
Hi Dave,

I've checked your findings and it's true that the parent object is different if the graphic is inline, grouped, grouped inline...

It returns everytime a different kind of object... So it can be used as parameter ...

But when trying the code the solution a stumble on a problem...

switch(app.activeDocument.allGraphics.parent.parent){
case 'page':
// do something
break;
case 'character':
// do something
break;
}

This doesn't work. Do you have any suggestions on how to check the object type?

Tim
Inspiring
March 6, 2008
To determine if a graphic is inline, check the parent of its frame. If that's a character, it's inline. (Watch out for graphics in inline groups -- when writing scripts to handle this kind of stuff, you have to carefully weigh the extent to which you can make simplifying assumptions. The more general you try to be, the more complicated your script becomes.)

Dave
Known Participant
March 6, 2008
Hi Dave,

Again, your completly right... Sometimes, when spending to mutch time in the scripts, I forget the remaining few limitations of the application... :-)

When reading the reference guide, I couldn't find any reference on checking if a graphic is an inline graphic or not and if so, removing it from the text frame and placing it on the same location on top of the rest. As a professional, do you think this can be done or is this also a limitation?

Kind regards

Tim
Inspiring
March 6, 2008
And so it should. The layer of an inline graphic is constrained by the layer occupied by the text frame holding the anchor "character" that in turn contains the inline graphic.

So, just as you can't change the layer of an inline in the UI, neither can you in a script.

Dave
Known Participant
March 6, 2008
Hi Olav,

Thanks for the info...

this works great ....

myGraphic.parent.itemLayer = app.activeDocument.layers.item('Graphics');

However, when an inline graphic has been used, an error occures...

Tim
Known Participant
March 5, 2008
Hi Tim,

The parent of the graphic is the frame. The frame has a property "itemLayer". So...

//Given a reference to a graphic "myGraphic"
//and a layer "myLayer"
myGraphic.parent.itemLayer = myLayer;

Thanks,

Ole
Known Participant
March 5, 2008
Dear Olav

I can't find any frame property or collection. Could you give any hints?

Thanks

Tim
Known Participant
March 5, 2008
Hi Tim,

Set the item layer of the frame containing the graphic to the layer you want to move it to. You don't use move() to move objects from one layer to another.

Thanks,

Ole