🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: adobe.scripting.indesign
Article #17871

Re: VB question: type mismatch

#17871
From: Olav Kvern
Date: Sat, 10 May 2003 17:27
39 lines
2237 bytes
Ana--

It's easier to think of PageItem as a kind of utility class for working with heterogenous groups of page items. If you need to know the specific type of a PageItem, use TypeName(PageItem) to get the string representation of the name ("Rectangle", "Oval", etc.).

Try something like this:



Rem Randomly move everything on the page. 
Rem The following variable declarations may be omitted 
Rem if you turn Option Explicit off. 
Dim myInDesign As InDesign.Application 
Dim myDocument As InDesign.Document 
Dim myPage As InDesign.Page 
Dim myPageItem As Object 
Dim myX As Double 
Dim myY As Double 
Rem End of optional variable declarations. 
Set myInDesign = CreateObject("InDesign.Application.2.0") 
Set myDocument = myInDesign.ActiveDocument 
Set myPage = myDocument.Pages.Item(1) 
For myCounter = 1 To myPage.PageItems.Count 
    Rem Generate two random numbers (between 0 and 10) 
    myY = 10 * Rnd 
    myX = 10 * Rnd 
    Set myPageItem = myPage.PageItems.Item(myCounter) 
    myPageItem.Move Array(myX, myY) 
Next 




As I've said before, I think scripters should turn off Option Explicit during script development. Many InDesign properties/method return more than one type of data, so declaring a variable as this or that type will almost always lead to type mismatch errors. Once your script is working, you can always go back and declare variable types.

Also--I wouldn't use "pi" as a variable name--it's a commonly-used geometric constant (3.1415926535897932).

Thanks,

Ole
Technical Details
Message-ID: <1de9125c.3@WebX.la2eafNXanI>
Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-03!sn-xit-06!sn-xit-01!sn-xit-09!supernews.com!news.maxwell.syr.edu!eusc.inter.net!newsfeed01.sul.t-online.de!t-online.de!WebX
References: <1de9125c.-1@WebX.la2eafNXanI>

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: f939a,2e58c5c8e33c7ae1
X-Google-Attributes: gidf939a,public
X-Google-ArrivalTime: 2003-05-10 10:40:06 PST
From: "Olav Kvern" <okvern@adobe.com>
Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-03!sn-xit-06!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: Re: VB question: type mismatch
Message-ID: <1de9125c.3@WebX.la2eafNXanI>
Date: Sat, 10 May 2003 10:27:55 -0700
References: <1de9125c.-1@WebX.la2eafNXanI>
Lines: 43
MIME-Version: 1.0
Content-Type: text/plain; charset="ISO-8859-1"
Content-Transfer-Encoding: 8bit