Article View: adobe.scripting.indesign
Article #2110Re: Swatch to Layer InDCS2...
From: 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();
Technical Details
Message-ID:
<59b76a5b.2@webcrossing.la2eafNXanI>Path:
arc1-ca.pugleaf.net!g2news1.google.com!news1.google.com!news.glorb.com!news2!feeder.erje.net!news4us.nl!webcrossingReferences:
<59b76a5b.-1@webcrossing.la2eafNXanI>Show Full Headers
Complete Article Headers
X-Google-Thread: f939a,861aec667a920b14 X-Google-Attributes: gidf939a,domainid0,public,usenet X-Google-Language: ENGLISH,ASCII-7-bit From: "Peter Kahrel" <kahrel@kahrel.plus.com> Newsgroups: adobe.scripting.indesign Subject: Re: Swatch to Layer InDCS2... Message-ID: <59b76a5b.2@webcrossing.la2eafNXanI> Date: Sun, 4 Jan 2009 03:40:47 -0800 References: <59b76a5b.-1@webcrossing.la2eafNXanI> Lines: 54 MIME-Version: 1.0 Content-Type: text/plain; charset="ISO-8859-1" Content-Transfer-Encoding: 8bit Path: arc1-ca.pugleaf.net!g2news1.google.com!news1.google.com!news.glorb.com!news2!feeder.erje.net!news4us.nl!webcrossing