/ Id-Extras Forum / Object Styles and Object Layer Options

  • Author
  • #6191 Reply
    Wonderboy

    Is there a way to loop through all pages in document, select an object by object style name, and change the Object Layer Options to show a specific layer that is turned off? Or show all layers using the Object Layer Options?

    This would prevent me from having to go to each linked PDF on each page and turning on the layers using the Object Layer Options.

    • This topic was modified 11 months, 1 week ago by ~~Ariel~~.
    #6397 Reply
    ~~Ariel~~
    Participant

    Yes, there is, but I would set up an object find query (just as one would do with the UI) to find all such objects based on object style.
    Something like this:

    Code:
    app.findObjectPreferences = null;
    app.findObjectPreferences.appliedObjectStyles = myDoc.objectStyles.itemByName(“YourStyleNameGoesHere”);
    app.findChangeObjectOptions.objectType = ObjectTypes.ALL_FRAMES_TYPE;
    f = document.findObject();
    #6398 Reply
    Wonderboy

    I was thinking the same thing but couldn’t figure out the proper syntax.

    Does the script you provided turn on all the layers for the Object Layer Options?

    I’ve seen some stuff about graphicLayers.GraphicLayerOptions but im just not sure whats the right syntax and how to write it out.

    #6399 Reply
    ~~Ariel~~
    Participant

    No, the script just gets a list of found objects.
    To switch layer visibility on and off I think (from memory) it’s something like

    Code:
    myObject.itemLayer.visible = true; // or false

    EDIT: I fixed the syntax, the above is now correct.

    #6400 Reply
    Wonderboy

    im still confused at how to write all this up so that it will turn off a layer within the Object Layer Options window

    #6401 Reply
    ~~Ariel~~
    Participant

    Not sure what the confusion is.
    If you have a page item (say a text frame, or rectangle or whatever), it has a property called itemLayer, which will give you a reference to the layer that the item is on.
    And setting a layer to true or false will turn it on or off in the layers panel, e.g.:

    Code:
    myItem.itemLayer.visible = true;

    Obviously you don’t have to get a reference to a layer through a page item, you can access all the layers in the document through the

    Code:
    document.layers

    collection.

    #6402 Reply
    Wonderboy

    Does document layers also affect layers in a linked document?

    for example – i have a illustrator file that i have placed on a page. i right click on the illustrator link and select Object Layers Options. This brings up the illustrator file layers and i can turn on or off different layers to this illustrator file. Now lets say i have 10 indesign pages, each page has a linked illustrator file with an assigned object style “Artwork”.

    Is it possible to write a script that will look for any object style name Artwork within the indesign document, and turn on or off a specific layer to the illustrator file?

    #6403 Reply
    ~~Ariel~~
    Participant

    Ah, I misunderstood, I thought you were talking about regular document layers.
    What you’re asking should be doable.
    A graphic item has a graphicLayers property, and each layer can be turned on or off with myLayer.currentVisibility which is r/w.
    That’s where I’d start playing around.

    #6404 Reply
    Wonderboy

    so far i’ve been trying to mess around with this

    Code:
    var myDocument = app.activeDocument;
    var docLength = myDocument.pages.length;
    var myPages = myDocument.pages

    for (var i = 0; i < docLength; i++) { alert("hello") var labelPlaceholder = myDocument.allGraphics; var labelArtwork = labelPlaceholder[0]; var artworkLayers = labelArtwork.graphicLayerOptions.graphicLayers; artworkLayers.item("Die Copy").currentVisibility = true; }

    i keep getting Object is Invalid on the currentVisability line

    #6405 Reply
    Wonderboy

    after playing around i made progress….

    Code:
    var myDocument = app.activeDocument;
    var docLength = myDocument.pages.length;
    var myPages = myDocument.pages

    for (var i = 0; i < docLength; i++) { var labelPlaceholder = myDocument.allGraphics; var labelArtwork = labelPlaceholder[0]; var artworkLayers = labelArtwork.graphicLayerOptions.graphicLayers; // artworkLayers.item("Die Copy").currentVisibility = true; // alert(artworkLayers.length) artworkLayers[0].currentVisibility = true; }

    this works at communicating with the pdf layers, not i just need to loop through each page and do the same thing to each pdf on each page.

    #6406 Reply
    Wonderboy

    got it working…

    Code:
    var myDocument = app.activeDocument;
    var docLength = myDocument.pages.length;
    var myPages = myDocument.pages

    for (var i = 0; i < docLength; i++) { var labelPlaceholder = myPages[i].allGraphics; var labelArtwork = labelPlaceholder[0]; var artworkLayers = labelArtwork.graphicLayerOptions.graphicLayers; artworkLayers[0].currentVisibility = true; }

    #6407 Reply
    ~~Ariel~~
    Participant

    Well done!
    The code here will only work on the first graphic on each page. Is that what you wanted?

Viewing 12 posts - 1 through 12 (of 12 total)

Tagged: 

Reply To: Object Styles and Object Layer Options
Your information: