Article View: adobe.scripting.indesign
Article #18296Re: Question regarding ID API and VB - text objects and the applystyle method.
From: Olav Kvern
Date: Fri, 04 Apr 2003 20:09
Date: Fri, 04 Apr 2003 20:09
44 lines
2153 bytes
2153 bytes
Kathy--
Two things come to mind. First, there's no need to iterate through the character styles collection looking for a named style. Instead, you can refer to the character style object by name:
Set CharStyle_Bold = myInDesignDoc.CharStyles.Item("Body Bold")
Obviously, this will generate an error if the character style of that name does not exist, so you might want to surround it with some error-checking code.
Most of the time, the Contents will be an InsertionPoint. The TextContents of an InsertionPoint will always be ""--so your line:
If XMLeleGroup.Item(myCounter).Contents.Item(1).TextContents <> "" Then
Should probably be:
If XMLeleGroup.Item(myCounter).Contents.Item(1).Texts.Item(1).TextContents <> "" Then
Next, you probably want to clear any formatting overrides as you apply the character style--which means you should use the ClearOverrides parameter of the ApplyStyle method:
myTextItem.ApplyStyle myCharStyle, True
Given these changes, and given an XML file placed in a document (style application won't work for unplaced XML elements, as far as I can tell), your example works well for me. If it's not working, put a stop at the line "Select Case..." and watch the type of the variable "myTextItem" (assigned in the preceding line).
Thanks,
Ole
Technical Details
Message-ID:
<1de898c4.0@WebX.la2eafNXanI>Path:
arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-02!sn-xit-04!sn-xit-01!sn-xit-09!supernews.com!newshosting.com!news-xfer2.atl.newshosting.com!news-out.visi.com!petbe.visi.com!eusc.inter.net!newsfeed01.sul.t-online.de!t-online.de!WebXReferences:
<1de898c4.-1@WebX.la2eafNXanI>Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: f939a,a3a4bf457b91c7e5 X-Google-Attributes: gidf939a,public X-Google-ArrivalTime: 2003-04-04 12:40:00 PST From: "Olav Kvern" <okvern@adobe.com> Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-02!sn-xit-04!sn-xit-01!sn-xit-09!supernews.com!newshosting.com!news-xfer2.atl.newshosting.com!news-out.visi.com!petbe.visi.com!eusc.inter.net!newsfeed01.sul.t-online.de!t-online.de!WebX Newsgroups: adobe.scripting.indesign Subject: Re: Question regarding ID API and VB - text objects and the applystyle method. Message-ID: <1de898c4.0@WebX.la2eafNXanI> Date: Fri, 4 Apr 2003 12:09:10 -0800 References: <1de898c4.-1@WebX.la2eafNXanI> Lines: 41 MIME-Version: 1.0 Content-Type: text/plain; charset="ISO-8859-1" Content-Transfer-Encoding: 8bit