Skip to main content
Known Participant
September 27, 2012
Question

Object Layers

  • September 27, 2012
  • 1 reply
  • 1292 views

Hello,

Is it possible to script the visibility of Object Layers (linked AI-files).

It would be handy if a script will take care of switching the visibility of Object Layers for more than hundred linked AI-files in a ID document.

This topic has been closed for replies.

1 reply

csm_phil
Legend
September 27, 2012

Hi Wimkees,

Please try the below js code.

var myDoc = app.activeDocument;

var myGraphics = myDoc.links;

for (var i = myGraphics.length-1; i >= 0; i--){

    var myArt = myGraphics;

    var myStry = myArt.parent;

    app.select(myStry);

    var mySel = app.selection[0];

    try{

        var myGraphs  = mySel.parent.graphics[0].graphicLayerOptions.graphicLayers;

        for (a=myGraphs.length-1; a>=0; a--){

            if(myGraphs.name =='sample'){//here you can as the layer name you want switch off the visibility.

                myGraphs.currentVisibility=false;

                }

            }

        }catch(e){}

        app.selection = null;

        }

   

thx

csm_phil

Known Participant
September 27, 2012

The script does now half the job... All the NL Layers are set to invisible.

But: how do I make the English (EN) Layers visible.

I edited it (see the italics txt) but that doesn't work :-(

var myDoc = app.activeDocument;

var myGraphics = myDoc.links;

for (var i = myGraphics.length-1; i >= 0; i--){

    var myArt = myGraphics;

    var myStry = myArt.parent;

    app.select(myStry);

    var mySel = app.selection[0];

    try{

        var myGraphs  = mySel.parent.graphics[0].graphicLayerOptions.graphicLayers;

        for (a=myGraphs.length-1; a>=0; a--){

            if(myGraphs.name =='NL'){//here you can as the layer name you want switch off the visibility.

                myGraphs.currentVisibility=false;

                }

            if(myGraphs.name =='EN'){//here you can as the layer name you want switch on the visibility.

                myGraphs.currentVisibility=true;

                }

            }

        }catch(e){}

        app.selection = null;

        }

csm_phil
Legend
September 27, 2012

Hello wimkee,

wimkees wrote:

The script does now half the job... All the NL Layers are set to invisible.

But: how do I make the English (EN) Layers visible.

I edited it (see the italics txt) but that doesn't work :-(

var myDoc = app.activeDocument;

var myGraphics = myDoc.links;

for (var i = myGraphics.length-1; i >= 0; i--){

    var myArt = myGraphics;

    var myStry = myArt.parent;

    app.select(myStry);

    var mySel = app.selection[0];

    try{

        var myGraphs  = mySel.parent.graphics[0].graphicLayerOptions.graphicLayers;

        for (a=myGraphs.length-1; a>=0; a--){

            if(myGraphs.name =='NL'){//here you can as the layer name you want switch off the visibility.

                myGraphs.currentVisibility=false;

                }

           else if(myGraphs.name =='EN'){//here you can as the layer name you want switch on the visibility.

                myGraphs.currentVisibility=true;

                }

            }

        }catch(e){}

        app.selection = null;

        }

Do you have debug the above script. Just I add the else condition thats all. If you need help in forum you always post your js code what you have tried. and what you get. so that is easy to help any one don't expect full code. This will not improve your future development growth.

thx,

csm_phil