Article View: adobe.scripting.indesign
Article #2035[CS4 JavaScript] Adding a CrossReferenceFormat
From: Rick_Quatro
Date: Wed, 14 Jan 2009 14:49
Date: Wed, 14 Jan 2009 14:49
29 lines
1730 bytes
1730 bytes
I am using a function to return a cross-reference format. If it doesn't exist, then I want to create it. Here is the code:
var doc = app.activeDocument;
var xrefFmt = getXRefFmt(doc,'Hoffman Accessory');
alert(xrefFmt.name);
function getXRefFmt(doc,formatName) {
var xrefFmt = null;
try {
xrefFmt = doc.crossReferenceFormats.item(formatName);
$.writeln(xrefFmt.name);
}
catch (e) {
xrefFmt = doc.crossReferenceFormats.add({name:formatName});
xrefFmt.buildingBlocks.add({blockType:BuildingBlockTypes.FULL_PARAGRAPH_BUILDING_BLOCK});
xrefFmt.buildingBlocks.add({blockType:BuildingBlockTypes.CUSTOM_STRING_BUILDING_BLOCK,customText:', page '});
xrefFmt.buildingBlocks.add({blockType:BuildingBlockTypes.PAGE_NUMBER_BUILDING_BLOCK});
}
return xrefFmt;
}
The function works as long as I have the $.writeln statement in the try block; otherwise the format is not created and I get an error on the alert statement on line 3. Why does the function fail without the $.writeln statement? Thanks.
Rick Quatro
585-659-8267
Technical Details
Message-ID:
<59b78308.-1@webcrossing.la2eafNXanI>Path:
arc1-ca.pugleaf.net!g2news2.google.com!news2.google.com!npeer01.iad.highwinds-media.com!news.highwinds-media.com!feed-me.highwinds-media.com!newshub.sdsu.edu!webcrossingShow Full Headers
Complete Article Headers
X-Google-Thread: f939a,49b15a73a3ef986c,start X-Google-Attributes: gidf939a,domainid0,public,usenet X-Google-Language: ENGLISH,ASCII-7-bit From: Rick_Quatro@adobeforums.com Path: arc1-ca.pugleaf.net!g2news2.google.com!news2.google.com!npeer01.iad.highwinds-media.com!news.highwinds-media.com!feed-me.highwinds-media.com!newshub.sdsu.edu!webcrossing Newsgroups: adobe.scripting.indesign Subject: [CS4 JavaScript] Adding a CrossReferenceFormat Message-ID: <59b78308.-1@webcrossing.la2eafNXanI> Date: Wed, 14 Jan 2009 06:49:26 -0800 Lines: 32 MIME-Version: 1.0 Content-Type: text/plain; charset="ISO-8859-1" Content-Transfer-Encoding: 8bit