Article View: adobe.scripting.indesign
Article #15232JS: Made me an object. But :-(
From: Dave_Saunders
Date: Sat, 13 Dec 2003 02:15
Date: Sat, 13 Dec 2003 02:15
36 lines
3252 bytes
3252 bytes
I'm working on a script to provide a Hyphenation and Justification styling facility. I'm still in the research stage, working out the details of what an H&J dialog might look like and trying to understand the best way to update a number of paragraph style properties in one fell swoop.
So far, my dialog only lets me adjust the alignment, balance ragged lines, composer and single-word justification properties (note that the "alignment" property in the dialog box is called "justification" in the object model).
So far, I've tried three different ways to update the paragraph style after getting the values from my dialog box:
1. Update each property individually:
myPstyle = app.documents[0].paragraphStyles.item(mySettings.name);
myPstyle.justification = decypher(Ualign,theAlignNums,theAlignments);
myPstyle.balanceRaggedLines = Ubalance;
myPstyle.composer = theParaComposers[Ucomposer];
myPstyle.singleWordJustification = decypher(Uswj,theSWJNums,theSingleWordJusts)
This was my first try, and it works. But you can literally see each property being applied. InDesign seems to flinch four times. I mistakenly put this down to the fact that I had issued four separate commands. So, I tried:
2. Update my record of the original properties and then update the style in one fell swoop:
myPstyle = app.documents[0].paragraphStyles.item(mySettings.name);
mySettings.justification = decypher(Ualign,theAlignNums,theAlignments);
mySettings.balanceRaggedLines = Ubalance;
mySettings.composer = theParaComposers[Ucomposer];
mySettings.singleWordJustification = decypher(Uswj,theSWJNums,theSingleWordJusts);
myPstyle.properties = mySettings;
What a disappointment. Instead of flinchiing just four times, it flinched, and flinched, and flinched, then the beachball started spinning, then a dialog came up suggesting I go get a coffee (not really). And it took an age. (By the way I was dong this on a document that had only one paragraph in the style in question and no other text.) So, it occurred to me to make an object -- something I'd never done before -- to see how that would work (I'm inserting newlines in the following to avoid a hugely long line):
3. Make a new object (I can't help thinking of them as records) so only the affected items get updated:
myPstyle = app.documents[0].paragraphStyles.item(mySettings.name);
myNewSettings = {justification:decypher(Ualign,theAlignNums,theAlignments),
balanceRaggedLines:Ubalance,composer:theParaComposers[Ucomposer],
singleWordJustification:decypher(Uswj,theSWJNums,theSingleWordJusts)};
myPstyle.properties = myNewSettings;
And there I was, back with the four flinches.
Technical Details
Message-ID:
<2ccee79b.-1@webx.la2eafNXanI>Path:
arc1-ca.pugleaf.net!archiver1.google.com!news2.google.com!fu-berlin.de!newsfeed01.sul.t-online.de!t-online.de!webxShow Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: f939a,1c2af4f369458bdb,start X-Google-Attributes: gidf939a,public X-Google-ArrivalTime: 2003-12-12 18:37:47 PST From: Dave_Saunders@adobeforums.com Path: arc1-ca.pugleaf.net!archiver1.google.com!news2.google.com!fu-berlin.de!newsfeed01.sul.t-online.de!t-online.de!webx Newsgroups: adobe.scripting.indesign Subject: JS: Made me an object. But :-( Message-ID: <2ccee79b.-1@webx.la2eafNXanI> Date: Fri, 12 Dec 2003 18:15:40 -0800 Lines: 58 MIME-Version: 1.0 Content-Type: text/plain; charset="ISO-8859-1" Content-Transfer-Encoding: 8bit