🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: adobe.scripting.indesign
Article #18291

Question regarding ID API and VB - text objects and the applystyle method.

#18291
From: Kathy Kult
Date: Fri, 04 Apr 2003 13:00
41 lines
3224 bytes
I've read all the "posts" here regarding character style application to in-line elements.
I'm trying to create something parallel to the AppleScript I've seen but for windows.
I've written a VB app. which essentially "walks" an XML tree of elements within a document looking for "in-line" elements, applying character styles when they are found.
I've got the code to the point where it's negotiating the tree down to the text object (I think) and invoking the "applystyle" method. This method does not provide a return code so I'm having a hard time telling whether it's successful or not. Running it from within ID I'm not seeing the results I expected (no in-line elements have been "converted".)
Now the code:
The following "snippet" of code walks the Character styles looking for a "known" label (the applystyle method requires a character style "object"):
<snip>
   For myCounter = 1 To myInDesignDoc.CharStyles.Count
        If (myInDesignDoc.CharStyles.Item(myCounter).Name = "Body Bold") Then
            Set CharStyle_Bold = myInDesignDoc.CharStyles.Item(myCounter)
        End If
    Next
</snip>

This next snippet is a routine which gets invoked with the "top" of the XML tree (XMLElements of the ID application object). It will invoke itself recursively, until it finds itself at the "bottom" of the XML "tree", it then compares the element to the "known" style elements and applies the character style to the text object.
<snip>
Private Sub Traverse_XML_Tree(XMLeleGroup As XMLElements)

For myCounter = 1 To XMLeleGroup.Count
        If XMLeleGroup.Item(myCounter).XMLElements.Count > 0 Then
            Call Traverse_XML_Tree(XMLeleGroup.Item(myCounter).XMLElements)
        Else
            If (XMLeleGroup.Item(myCounter).Contents.Item(1).TextContents <> "") Then
                Set myTextItem = XMLeleGroup.Item(myCounter).Contents.Item(1).Texts.Item(1)
                Select Case XMLeleGroup.Item(myCounter).MarkupTag.Name
                    Case "bold"
                        myTextItem.ApplyStyle (CharStyle_Bold)
                        numElementsCnvt = numElementsCnvt + 1
                    End Select
            End If
        End If
    Next

End Sub
</snip>

My intent is once I get this working to :
1) "clean" the code up to reiterate over the content and text collections
2) add a dialog to allow the end user to correlate in-line elements to character styles, perhaps storing this to an INI file.

Thanks for any help you can provide.....
Technical Details
Message-ID: <1de898c4.-1@WebX.la2eafNXanI>
Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-02!sn-xit-03!sn-xit-01!sn-xit-09!supernews.com!news.maxwell.syr.edu!eusc.inter.net!newsfeed01.sul.t-online.de!t-online.de!WebX

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: f939a,a3a4bf457b91c7e5,start
X-Google-Attributes: gidf939a,public
X-Google-ArrivalTime: 2003-04-04 05:31:09 PST
From: "Kathy Kult" <kultk@cch.com>
Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-02!sn-xit-03!sn-xit-01!sn-xit-09!supernews.com!news.maxwell.syr.edu!eusc.inter.net!newsfeed01.sul.t-online.de!t-online.de!WebX
Newsgroups: adobe.scripting.indesign
Subject: Question regarding ID API and VB - text objects and the applystyle method.
Message-ID: <1de898c4.-1@WebX.la2eafNXanI>
Date: Fri, 4 Apr 2003 05:00:11 -0800
Lines: 62
MIME-Version: 1.0
Content-Type: text/plain; charset="ISO-8859-1"
Content-Transfer-Encoding: 8bit