Thread View: adobe.scripting.indesign
7 messages
7 total messages
Started by thiyagus5
Sat, 03 Jan 2009 13:02
Swatch to Layer InDCS2...
Author: thiyagus5
Date: Sat, 03 Jan 2009 13:02
Date: Sat, 03 Jan 2009 13:02
28 lines
1534 bytes
1534 bytes
Hi everyone,
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,
------
Error Number:45
Error string:Object is invalid
Line:12
------
Please find my script below;
----
var myDoc = app.activeDocument;
with (myDoc){
myNewLayer = layers.add();
with (myNewLayer) {
name = "ANNO"
}
}
var mySwatch = myDoc.swatches.item("IE-Black");
for (i=0; i<myDoc.textFrames.length; i++){ if (myDoc.textFrames[i].paragraphs[0].fillColor == mySwatch ) { myDoc.textFrames[i].itemLayer=myNewLayer; } } myNewLayer.visible=false;
alert ("DONE...")
----
Thanks in advance
Thiyagu
Re: Swatch to Layer InDCS2...
Author: Peter Kahrel
Date: Sat, 03 Jan 2009 14:32
Date: Sat, 03 Jan 2009 14:32
3 lines
865 bytes
865 bytes
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
Re: Swatch to Layer InDCS2...
Author: thiyagus5
Date: Sun, 04 Jan 2009 10:19
Date: Sun, 04 Jan 2009 10:19
6 lines
1191 bytes
1191 bytes
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
Re: Swatch to Layer InDCS2...
Author: Peter Kahrel
Date: Sun, 04 Jan 2009 11:40
Date: Sun, 04 Jan 2009 11:40
43 lines
2291 bytes
2291 bytes
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();
Re: Swatch to Layer InDCS2...
Author: baby1915
Date: Sun, 04 Jan 2009 21:58
Date: Sun, 04 Jan 2009 21:58
14 lines
1181 bytes
1181 bytes
Hi Thiyagu,
I wrote the script for your problemm of Layer Movement see below the script, let you check it out and then tell your suggestions....
var myDoc = app.activeDocument;
try{
myDoc.layers.item("ANNO").name;
}
catch (myError){
myDoc.layers.add({name:"ANNO"});
}
var myAnno = myDoc.layers.item ('ANNO');
var mySwatch = myDoc.swatches.item("IE-Black");
for (i=0; i<myDoc.textFrames.length; i++) { if (myDoc.textFrames[i].paragraphs[0].fillColor == mySwatch ) { myDoc.textFrames[i].itemLayer=myAnno; } }myAnno.visible=false; myDoc.save(); myDoc.close(); alert ("Completed...")
Re: Swatch to Layer InDCS2...
Author: thiyagus5
Date: Mon, 05 Jan 2009 02:51
Date: Mon, 05 Jan 2009 02:51
6 lines
739 bytes
739 bytes
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
Re: Swatch to Layer InDCS2...
Author: thiyagus5
Date: Mon, 05 Jan 2009 03:11
Date: Mon, 05 Jan 2009 03:11
6 lines
871 bytes
871 bytes
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
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads