Skip to main content
Participant
August 20, 2012
Question

Copy anchored object with specific object style to new layer

  • August 20, 2012
  • 2 replies
  • 1962 views

Hi there

i'm new to scripting and been trying to adjust the script below, but without result.

This script i found on Indisnip:

var myItems = app.activeDocument.allPageItems;

var myDoc = app.activeDocument;

var foundObjects = Array();

for(var i = 0; i < myItems.length; i++){

    if(myItems.parent instanceof Character){foundObjects.push(myItems);}

}

if(foundObjects.length > 0){

    try{var myDestLayer = myDoc.layers.add({name:"Anchor/Inline Duplicates"});}

    catch(_){myDestLayer = myDoc.layers.item("Anchor/Inline Duplicates");}

    for(var i = 0; i < foundObjects.length; i++){

        var newDuplicate = foundObjects.duplicate(myDestLayer);

        newDuplicate.geometricBounds = foundObjects.geometricBounds;

        try{newDuplicate.graphics[0].geometricBounds = foundObjects.graphics[0].geometricBounds;}catch(_){}

    }

}

It copy's all the anchored items to a new layer 'Anchor/Inline Duplicates'.

But i only want the anchored objects with a specific object style to be copied. Something like 'appliedObjectStyles.name == "OS-name".

Can someone help me with that?

thx

Arne

This topic has been closed for replies.

2 replies

LeoMari-eL6mBl
Inspiring
February 10, 2016
Jongware
Community Expert
Community Expert
August 20, 2012

(untested!) Change the lines that iterate over found objects and add inline objects, starting at line #5, to the following

for(var i = 0; i < myItems.length; i++){

if(myItems.appliedObjectStyle.name == "OS-name" &&

myItems.parent instanceof Character){foundObjects.push(myItems);}

}

-- the if-clause has been changed here; the second line is added.

To highlight code in a post, you can use the "Advanced" editor, so you can apply Syntax hi-lighting. It makes Javascript ever so slightly more readable

AxenzaAuthor
Participant
August 20, 2012

Hi Jongware

thx for this quick reply!! Wow, that was fast

The script works fine!

many thanx