1 Reply Latest reply on Jul 22, 2015 4:08 AM by Jump_Over

    "Object invalid" error for layer visible

    Jackkistens

      Hi All,

       

      I am getting the "Object invalid" error message for below code. please check and suggest me, where is error occurred in my code.

       

      var myDoc =  app.activeDocument;

       

      var myLayer = myDoc.layers;

       

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

        { 

            if(myLayer[i].name == "WEBPDF" && myLayer[i].visible == true)

              {  

                 

                  try

                  {

                          myDoc.revert();

                          myLayer[i].visible = false;

                          myDoc.save();

                      }

                  catch(e){

                          alert(e);

                      }

       

                  }

            }

        • 1. Re: "Object invalid" error for layer visible
          Jump_Over Level 5

          Hi,

           

          myLayer[i] is no longer valid object after myDoc.revert()

           

          Modify it like below and try:

          var
            myDoc = app.activeDocument,
            myLayer = myDoc.layers.item("WEBPDF");
          
          if(myLayer.isValid && myLayer.visible) {
            myDoc.revert();
            myDoc = app.activeDocument;
            myDoc.layers.item("WEBPDF").visible = false;
            myDoc.save();
            }
          
          
          

           

          Jarek