🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: adobe.scripting.indesign
Article #19782

Re: VB6&ID - Replace function like ImportXML

#19782
From: David Ames
Date: Thu, 21 Nov 2002 21:58
51 lines
4272 bytes
I wouldn't think that it's so much an Option Explicit related problem, more an early binding (vTable or DispID binding) problem. Option Explicit means that you have to declare a variable, but you still don't have to declare it of a specific type (you can declare it as Variant or Object). IE, I can have Option Explicit on and do: 

Dim idPageItem 
OR 
Dim idPageItem as Object 

and have no issues. The variable is still declared (and therefore even with Option Explicit on, this will work), but it will be late-bound, so as you said, things like Intellisense will not work with it. There is also a performance hit with LateBinding because vb needs to call GetIDsOfNames (because there is no vTable and the DispID is unknown as run-time), but that's not a huge issue for me. 

I _think_ the problem is caused because the PageItem property of the PageItems object does NOT actually return an Indesign.PageItem as you would expect. 

Try this code: 

Dim idApplication As InDesign.Application 
Dim idDocument As InDesign.Document 

Dim idPage As InDesign.Page 

Set idApplication = CreateObject("InDesign.Application") 
Set idDocument = idApplication.Open("D:\development\indesign\test.indd") 
Set idPage = idDocument.Pages(1) 

MsgBox (TypeOf idDocument.Pages(1) Is InDesign.Page) 
MsgBox (TypeOf idPage.PageItems(1) Is InDesign.PageItem) 
MsgBox (TypeOf idPage.Rectangles(1) Is InDesign.Rectangle) 

It will return True, false, True. Because idPage.PageItems(1) does not return a Indesign.PageItem! True, it looks like an Indesign.PageItem and from your point of view it functions like an Indesign.PageItem, but from VB's point of view, it's not an Indesign.PageItem. - I think the Type Library might be a little screwed.... This is also why 

For Each idPageItem In idPage.PageItems 

does not work. 

Anyway - getting back to the main issue. What I want to do is create something similar to File=>ImportXML, because the build-in ID function does not suit my needs. The way I see it, it's fairly simple: Iterate through every object on the page, check it's idTextFrame.AssociatedXMLElements(1).MarkupTag.Name and if that matches the name of a node on my XML document then replace the text or image as nessasery. (Keeping the original image size, being able to fit text to the textbox, and all sorts of funky stuff that the standard ID File=>ImportXML can not do).... 

Your example code does not work for me, because idDocument.AllPageItems(curPageItem).Item does NOT contain a TextFrames object, even when (TypeName(idDocument.AllPageItems(curPageItem)) = "TextFrame") = true!!! EG, this code fails: 

For curPageItem = 1 To idDocument.AllPageItems.Count 
     If TypeName(idDocument.AllPageItems(curPageItem)) = "TextFrame" Then 
       MsgBox (idDocument.AllPageItems(curPageItem).Item.TextFrames.Count) 
     End If 
    Next 

at the msgBox statment with "Object doesn't support this property or method." Because TextFrames does not appear to be a member of the PageItem object! Even though the TypeLib says it is and idsnscripting.pdf says it is.... 

I also think that the contentType of converted frames bug is actually related to ID cracking it if the PageItem is a group. IE: 

curPageItem = 11 
Msgbox(idPage.PageItems(curPageItem).ContentType)) 

returns an exection "Object doesn't support this property or method" 

BUT msgbox(TypeName(idPage.PageItems(curPageItem))) returns "Group" - so I'm thinking that the ContentType property does not exist when the PageItem refers to a group?
Technical Details
Message-ID: <1de6b092.6@WebX.la2eafNXanI>
Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-02!sn-xit-05!sn-xit-06!sn-xit-04!supernews.com!news.maxwell.syr.edu!eusc.inter.net!newsfeed01.sul.t-online.de!t-online.de!WebX
References: <1de6b092.-1@WebX.la2eafNXanI>

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: f939a,9fb81744ad733cf6
X-Google-Attributes: gidf939a,public
X-Google-ArrivalTime: 2002-11-21 14:07:50 PST
From: "David Ames" <davida@in-site.com.au>
Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-02!sn-xit-05!sn-xit-06!sn-xit-04!supernews.com!news.maxwell.syr.edu!eusc.inter.net!newsfeed01.sul.t-online.de!t-online.de!WebX
Newsgroups: adobe.scripting.indesign
Subject: Re: VB6&ID - Replace function like ImportXML
Message-ID: <1de6b092.6@WebX.la2eafNXanI>
Date: Thu, 21 Nov 2002 13:58:20 -0800
References: <1de6b092.-1@WebX.la2eafNXanI>
Lines: 85
MIME-Version: 1.0
Content-Type: text/plain; charset="ISO-8859-1"
Content-Transfer-Encoding: 8bit