6 Replies Latest reply on Jan 4, 2009 7:11 PM by dhishok

    Swatch to Layer InDCS2...

    dhishok Level 1
      Hi everyone,<br /><br />We have more than hundreds of InDesign documents. What we have to do is, turned off this "IE-Black" spot color swatch applied paragraphs in the document. So i am finding "IE-Black" spot color applied paragraphs in the documents then apply "ANNO" named layer to the corresponding paragraphs text frames. And finally hiding them all. If i have tested this script in the new document its working fine. But not working in our exiting documents. It showing error like, <br /><br />------<br />Error Number:45<br />Error string:Object is invalid<br />Line:12<br />------<br /><br />Please find my script below;<br /><br />----<br />var myDoc = app.activeDocument;<br />with (myDoc){<br />     myNewLayer = layers.add();<br />     with (myNewLayer) {<br />     name = "ANNO"<br />     }<br />}<br />var mySwatch = myDoc.swatches.item("IE-Black");<br />for (i=0; i<myDoc.textFrames.length; i++){<br />       if (myDoc.textFrames[i].paragraphs[0].fillColor == mySwatch )<br />               {<br />              myDoc.textFrames[i].itemLayer=myNewLayer;<br />               }<br />}<br />myNewLayer.visible=false;<br /><br />alert ("DONE...")<br />----<br /><br />Thanks in advance<br />Thiyagu
        • 1. Re: Swatch to Layer InDCS2...
          Peter Kahrel Adobe Community Professional & MVP
          Your script assumes that each document has a layer called IE-Black and that each text frame has some text in it. If either of these conditions isn't met the script errors out, so you should check if these conditions are met or put the script in a try/catch construction.

          Peter
          • 2. Re: Swatch to Layer InDCS2...
            dhishok Level 1
            Hi peter thanks for your kind reply.

            The IE-Black is the spot color swatch. Each document has this IE-Black swatch. All the text elements which are in the base layer. So i am finding these IE-Black swatch applied paragraphs and applying new layer to it. Then only i can easily hide this IE-Black applied paragraphs by turned off the layer. This is our requirement. I am a learner of the scripts. Could you please help me for this? If you need i can send you the document for testing.

            Thanks
            Thiyagu
            • 3. Re: Swatch to Layer InDCS2...
              Peter Kahrel Adobe Community Professional & MVP
              Thiyagu,

              The error message ("Object is invalid") points to a text frame -- probably the first paragraph in that text frame. You must try and anticipate as many errors as possible in a script. In your script, possible errors are a layer and a swatch that may not be present, or a problem with some text frame that you try to do something with (maybe it's empty, or locked, or anything else that prevents it from being processed).

              Below is a version of your script that tries to get around errors: if a layer doesn't exist, it is created, same for the swatch. The script also creates a layer to which obstinate text frames are moved. When the script finishes it alerts you if it encountered any problems.

              Peter

              #target indesign;
              

              var myDoc = app.activeDocument;

              if (myDoc.layers.item ('ANNO') == null)
                 myDoc.layers.add ({name: 'ANNO'});
              var myNewLayer = myDoc.layers.item ('ANNO');

              if (myDoc.layers.item ('errors') == null)
                 myDoc.layers.add ({name: 'errors'});
              var errorLayer = myDoc.layers.item ('errors');

              if (myDoc.swatches.item ("IE-Black") == null)
                 myDoc.colors.add ({name: "IE-Black", /*more features*/});
              var mySwatch = myDoc.swatches.item ("IE-Black");

              for (i=0; i<myDoc.textFrames.length; i++)
                 try
                    { 
                    if (myDoc.textFrames[i].paragraphs[0].fillColor == mySwatch)
                       myDoc.textFrames[i].itemLayer=myNewLayer
                    }
                 catch(_)
                    {
                    myDoc.textFrames[i].itemLayer = errorLayer
                    }

              //myNewLayer.visible=false;

              if (errorLayer.textFrames.length > 0)
                 alert ('Some text frame(s) could not be processed.\r(See error layer.)');
              else
                 errorLayer.remove();
              • 4. Re: Swatch to Layer InDCS2...
                csm_phil Level 4
                Hi Thiyagu,<br /><br />I wrote the script for your problemm of Layer Movement see below the script, let you check it out and then tell your suggestions....<br /><br />var myDoc = app.activeDocument; <br />try{<br />myDoc.layers.item("ANNO").name;<br />}<br />catch (myError){<br />myDoc.layers.add({name:"ANNO"});<br />}<br />var myAnno = myDoc.layers.item ('ANNO'); <br />var mySwatch = myDoc.swatches.item("IE-Black"); <br />for (i=0; i<myDoc.textFrames.length; i++)<br />{<br />if (myDoc.textFrames[i].paragraphs[0].fillColor == mySwatch ) <br />{<br />myDoc.textFrames[i].itemLayer=myAnno; <br />} <br />}myAnno.visible=false; <br />myDoc.save();<br />myDoc.close();<br />alert ("Completed...")
                • 5. Re: Swatch to Layer InDCS2...
                  dhishok Level 1
                  Hi peter,

                  Thanks for your great & kind support. Its working fine. Now i am trying to do this for, as batch process. Once again i am thanking you.

                  Thanks
                  Thiyagu
                  • 6. Re: Swatch to Layer InDCS2...
                    dhishok Level 1
                    Hi baby,

                    Thanks for your help. While trying your script, it shows the same error as i got before. I think you have tried this in the new document. Ok the script shows error with the existing(i.e. completed) documents. But Peter script is working very fine.

                    Thanks
                    Thiyagu