This is a bug. You can't address guides through their label. app.selection (when a guide is selected) and app.activeDocument.guides work ok, but app.activeDocument.guides.item('xxx') doesn't work.
Thanks Peter. And just to clarify... I need to move a specific guide.
.guides won't work for me since I don't know if the user will add any to the document I create. This script will be adjusting an existing document where I won't know the number reference of a guide.
But then I can't address that guide's script label because of a bug? Why was this bug not fixed? If this is true, then the script I want to create is impossible?
You can't address the guide using it's label, but you can cycle through all guides and look for the one with the label you want.
>.guides won't work for me since . . .
Sorry -- I wasn't very clear on that. All I meant was that there are several ways in which you could get a handle on a guide, but not through its label.
> Why was this bug not fixed?
I don't know when this bug was first reported, but I reported it just a couple of weeks ago. We'll have to wait and see what happens.
>. . . then the script I want to create is impossible?
That's what I thought until a few minutes ago, and in fact I recently ditched an approach because of this bug, but, of course, Dave's remark ("but you can cycle through all guides and look for the one with the label you want.") provides the solution:
g = app.activeDocument.guides;
for (i = 0; i < g.length; i++)
if (g[i].label == 'myGuide')
g[i].location = 2;
Great workaround Dave!
Thanks Peter for the code help on how to loop through all the guides. I may have been able to figure it out, but that will save me some time of trial and error.
I'll be testing this out shortly.
Thanks again! :)
Both Page and Spread objects have guide selections, so it might not be necessary to search the whole document collection.
Just bear in mind, though, that some guides are page guides while others are spread guides, so a search of the spread guides might not find a page guide -- probably won't.
I just tried it and things seem to be working as I expect now.
I was beginning to think I was crazy when nothing I tried was working. It's nice to know about this bug and to have a workaround for it. Many thanks to both of you!
I'm not so sure that it is a bug. Ole has made the point that itemByName only works with labels when the objects are labeled pageItems -- although there are some other objects for which it does work, by and large, if it's not a page item, itemByName (for which item("Name") is an alternative syntax) is not guaranteed to run.
However, the documentation in the OMV doesn't make this very clear. For example, consider tables:
Tables.itemByName (name:string): Table
Returns the Table with the specified name.
name: Data Type: string
but tables don't have names, only labels. I just tried this:
var myStory = app.activeDocument.stories;
and that worked as long as I only had one table with that label. Duplicate the label a couple of times and try again and I got the truncated error in the ESTK info field:
>Invalid value for parameter 'selectableItems' of event 'select'. Expected ...Enum enumerator or SelectAll enumerator but received (Table, Table, Table).
Which is a reminder that when itemByName works with named items, you only ever get one object returned, even if there are many of said objects with the same name, but when it works with labeled items, it returns a reference to all the in-scope objects that have the label in question.
Well, ok, if it's intended behaviour it's not a bug (just a nuisance). I can't see the rationale, though. It would be very useful if you could refer to guides (and stories, tables, and what not) using their label.
There is at least a bug in the object model description:
Guides.itemByName (name:string): Guide
Returns the Guide with the specified name.
name: Data Type: string
I'm with you, it ought to work where the documentation says it should work. If it doesn't, then either fix the documentation or make it work.
Hi Dave, Peter,
It looks to me as if this is an error in the way that InDesign generates the XML file for the ESTK to use. A guide does not have a name property, so it shouldn't have an item by name method.
Tables don't have names either, but they support itemByName corectly.
I've said before that that is probably an error. It's nice that it works, though.
>A guide does not have a name property
But it does have a label, and it's sort of usable. It still doesn't make any sense to me why certain object can be addressed using their label, and others not.
We created a special case for page items because it was useful. At the time, we had to argue that it was so useful that it was worth keeping even though it was inconsistent.
I agree that it would be great to be able to use it with guides--or any other object that has a label. I doubt, however, that we have the resources to add this feature anytime soon.
Fair enough -- thanks.
> I'm not so sure that it is a bug. Ole has made the point that itemByName only works with labels when the objects are labeled pageItems
But, I'm almost positive that guides *are* page items -- on the C++
level. (At least that's what my experience with APID has lead me to
Maybe we should ask for an itemByLabel method which would always work
with the label...
FYI - beating my own drum here, but I think this might be helpful: by installing our free 'APID ToolAssistant' (formerly Active Page Items Runtime) plug-in, you gain some additional script functionality in CS/CS2/CS3.
Amongst a host of other functionality, it's also a bit of a grab-bag of functionality we needed to get in ExtendScript for our own use - each time we needed a new feature, we just plunked it into the plug-in and made it accessible via the ExtendScript DOM.
One of the things is that it adds an event called 'labeledPageItems' to the Document object, which returns an array (not a collection) of all matching items. For example, if I have a document that contains a frame, and two guides that all have the label 'test' assigned, the following script returns an array that contains all of them:
var theDoc = app.activeDocument;
var theItems = theDoc.labeledPageItems("test");
labeledPageItems accepts wildcard expressions (not grep - just simple wildcards; "*" = zero or more chars, "?" = exactly one char) - so you can do things like:
var theDoc = app.activeDocument;
var theItems = theDoc.labeledPageItems("t*");
to grab all page items whose label starts with 't'.
There are some more options (e.g also select by layer or spread).
If you install the plug-in you can inspect some short docs via the ExtendScript Object Model viewer.
Other interesting freely available features are:
- a progress bar window with optional Cancel button for use with long-running scripts in InDesign CS/CS2 (which became obsolete, but is still functional in CS3),
- clearing the InDesign undo stack during long running scripts,
- temporarily locking InDesign into a fake 'modal mode' (so the user cannot interfere with it while you're juggling things with scripts and external programs - I use it to make fake 'modal dialogs' that seem to originate from InDesign, but are really created from a REALbasic app),
The latest APID ToolAssistant 1.0.45 adds a new event Document.multiPropertyAssign, which allows you to assign a whole collection of objects and attributes new values in one event call - which represents a single undo, and seems to speed up some scripts (the jury is still out - in some situations, there is marked improvement, in other situations it's actually slower). Docs can be seen via the ExtendScript toolkit.
What's available in ExtendScript is a bit of a hodgepodge as it is mostly driven by our own needs rather than by design.
This part of the functionality of the plug-in is all free (as in 'at no cost') - APID ToolAssistant has two modes (licensed and unlicensed), and you can use this stuff with an unlicensed version installed; check the docs for more info.
(the downloadable demo of APID contains PDF documentation that is relevant to the free APID ToolAssistant)
Hope it's useful!
That sounds very useful -- thanks.
On 20/5/08 4:26 PM, "Harbs" <firstname.lastname@example.org> wrote:<br /><br />> But, I'm almost positive that guides *are* page items -- on the C++<br />> level.<br /><br />Perhaps, but not on a scripting level. Ask for allPageItems...<br /><br />-- <br />Shane Stanley <email@example.com>
Peter Kahrel wrote:
> That sounds very useful -- thanks.
I'll be happy to beat that drum too... *It is very useful!!!*
What Kris wrote just barely scratches the surface. APID makes possible,
stuff you haven't even dreamed of...
(I've been using it very extensively over the last year or so... and
here are some of the results: www.in-tools.com )
P.S. the site should be totally live in a few days.
>> Perhaps, but not on a scripting level. Ask for allPageItems...
Yes I know. I didn't mean to disagree. It was more of a question as to
why the difference...
On 22/5/08 8:58 PM, "Harbs" <firstname.lastname@example.org> wrote:<br /><br />> It was more of a question as to why the difference...<br />> <br />I always found it strange in the old days when graphics were page items. I<br />mean, if there's one item that can *never* belong to a page...<br /><br />-- <br />Shane Stanley <email@example.com>
you wrote: "clearing the InDesign undo stack during long running scripts"
Is it possible to completly deactivate the undo stack functionality in CS3? Or do I have to clear the array periodically? I already read the post: http://forums.adobe.com/message/1110044#1110044 but i need a solution for CS3? If not with the Scripting API perhaps with a c++ plugin?
APID has a function for clearing the undo stack. I don't think there's
a way to disable it completely -- not even with C++.
thanks for fast answering. I gonna take a look on the APID.