🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: adobe.scripting.indesign
Article #9343

Re: extended toolkit doubt

#9343
From: Dave_Saunders
Date: Tue, 05 Sep 2006 12:37
25 lines
2970 bytes
For what it's worth, I switched to using "aDoc" rather than "myDoc", etc., to get the names of my variables nearer the top of the Data Browser.

And I've recently taken to doing just about everything inside of functions, which also helps to eliminate clutter in the Data Browser because you're not looking at the global variables most of the time.

And there is the issue of name clashes at the global level. There's a long list of names for functions and objects that you can't use at the global level. To do so will either break your script or pollute the global name space. The latter can be a big problem if you have JavaScripts being run as part of the personality of plug-ins -- this is not a common problem, but it can cause an apparently working script to suddenly misbehave, as happened to my TextStylesReporter script where I redefined the global function called resolve() without realizing I'd done that.

So, personalize your names, make them local to your script by doing everything inside an overarching function (except the initial call to the function) and you'll be in good shape.

For example, along these lines:

processScript(); // that's all at the global level (use a name that reflects what your script does) 
function processScript() { 
  var aDoc = app.documents[0]; 
  processDocument(aDoc);

  function processDocument(doc) { 
    // Do something to doc 
  } 
}

Notice that with this structure, the processDocument function is completely inside the processScript function. This makes it local to the processScript function -- try to call it from the global level and it won't be recognized. Because it is contained inside processScript, it see the processScript variables as though they were global, so, in this case, for example, it wasn't actually necessary to pass the parameter aDoc to processDocument because that internal function could see the aDoc variable as a global variable -- however, in spite of this, it is better to pass the variable to make such function re-usable in other scripts.

Hope this helps.

Dave
Technical Details
Message-ID: <3bc187a2.10@webcrossing.la2eafNXanI>
Path: arc1-ca.pugleaf.net!g2news2.google.com!news1.google.com!news3.google.com!border1.nntp.dca.giganews.com!border2.nntp.dca.giganews.com!nntp.giganews.com!transit3.readnews.com!news-out.readnews.com!news-out2.kabelfoon.nl!newsfeed.kabelfoon.nl!bandi.nntp.kabelfoon.nl!213.132.189.2.MISMATCH!multikabel.net!feed20.multikabel.net!news2.euro.net!newsfeed.freenet.de!news.albasani.net!news.motzarella.org!news.isoc.lu!webcrossing
References: <3bc187a2.-1@webcrossing.la2eafNXanI>

Show Full Headers
Complete Article Headers
X-Google-Thread: f939a,d989bab30f600d02
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!news1.google.com!news3.google.com!border1.nntp.dca.giganews.com!border2.nntp.dca.giganews.com!nntp.giganews.com!transit3.readnews.com!news-out.readnews.com!news-out2.kabelfoon.nl!newsfeed.kabelfoon.nl!bandi.nntp.kabelfoon.nl!213.132.189.2.MISMATCH!multikabel.net!feed20.multikabel.net!news2.euro.net!newsfeed.freenet.de!news.albasani.net!news.motzarella.org!news.isoc.lu!webcrossing
Newsgroups: adobe.scripting.indesign
Subject: Re: extended toolkit doubt
Message-ID: <3bc187a2.10@webcrossing.la2eafNXanI>
Date: Tue, 5 Sep 2006 05:37:23 -0700
References: <3bc187a2.-1@webcrossing.la2eafNXanI>
Lines: 42
MIME-Version: 1.0
Content-Type: text/plain; charset="ISO-8859-1"
Content-Transfer-Encoding: 8bit