🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: adobe.scripting.indesign
Article #8750

Re: problem with nextStyle.name

#8750
From: Dave_Saunders
Date: Thu, 28 Sep 2006 13:09
31 lines
2425 bytes

      It is no good to get an error message or even worse (as is the case somtimes
      when dealing with xmlElements) when you get an object that doesn't reveal
      itself as not existing until you try to reference one of its properties.




That is not restricted to xmlElements. That's the way that JavaScript works. I can never remember what it's called; something like Late Resolution.

The thing to bear in mind is this:

When you work with objects in the InDesign object model, you are in fact looking at the objects themselves. Now, one of the quirky things about the way that objects work is: the collections always exist even when they're empty. This takes some getting used to, but it surely makes adding new objects easier because you can always add to the collection, even when it is empty (provided the collection in question has the add() method defined for it -- some don't because the objects are created in some special manner).

This "late resolution" also applies to things like this:

myCharStyle = app.activeDocument.characterStyles.item("Italic");

if that style exists in the active document, you get a reference to it you can work with. If it doesn't, you get null, so you can write:

myCharStyle = app.activeDocument.characterStyles.item("Italic"); 
if (myCharStyle == null) { 
$nbsp;$nbsp;myCharStyle = app.activeDocument.characterStyles.add({name:"Italic", fontStyle:"Italic"); 
}

which, by the way, is a much better method for doing this than the one I used in the script I posted an hour or so ago in a different topic.

What you're complaining about is the way that JavaScript is supposed to work (as I understand it).

Dave
Technical Details
Message-ID: <3bc1cef3.9@webcrossing.la2eafNXanI>
Path: arc1-ca.pugleaf.net!g2news2.google.com!news4.google.com!border1.nntp.dca.giganews.com!border2.nntp.dca.giganews.com!nntp.giganews.com!newspeer1.nwr.nac.net!newsfeed.freenet.de!news.buerger.net!news.mb-net.net!open-news-network.org!news.isoc.lu!webcrossing
References: <3bc1cef3.-1@webcrossing.la2eafNXanI>

Show Full Headers
Complete Article Headers
X-Google-Thread: f939a,2f8a9309c8ea275e
X-Google-Attributes: gidf939a,public
X-Google-Language: ENGLISH,ASCII-7-bit
From: Dave_Saunders@adobeforums.com
Path: arc1-ca.pugleaf.net!g2news2.google.com!news4.google.com!border1.nntp.dca.giganews.com!border2.nntp.dca.giganews.com!nntp.giganews.com!newspeer1.nwr.nac.net!newsfeed.freenet.de!news.buerger.net!news.mb-net.net!open-news-network.org!news.isoc.lu!webcrossing
Newsgroups: adobe.scripting.indesign
Subject: Re: problem with nextStyle.name
Message-ID: <3bc1cef3.9@webcrossing.la2eafNXanI>
Date: Thu, 28 Sep 2006 06:09:50 -0700
References: <3bc1cef3.-1@webcrossing.la2eafNXanI>
Lines: 36
MIME-Version: 1.0
Content-Type: text/plain; charset="ISO-8859-1"
Content-Transfer-Encoding: 8bit