26 Replies Latest reply on Apr 20, 2009 12:36 AM by TinoRuntzler

    [JS] Move a Guide that has a ScriptLabel

    Level 1
      I am trying move a specific guide. The guide is on the master page and is named myGuide

      Here is what I currently trying, but it doesn't work.
      app.activeDocument.guides.item("myGuide").location = 2

      Thanks in advanced for any help.
      Dan

      P.S. I will this to work in CS2 and CS3.
        • 1. Re: [JS] Move a Guide that has a ScriptLabel
          Peter Kahrel Adobe Community Professional & MVP
          This is a bug. You can't address guides through their label. app.selection[0] (when a guide is selected) and app.activeDocument.guides[0] work ok, but app.activeDocument.guides.item('xxx') doesn't work.

          Peter
          • 2. Re: [JS] Move a Guide that has a ScriptLabel
            Level 1
            Thanks Peter. And just to clarify... I need to move a specific guide.
            .guides[0] 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?

            :(
            • 3. Re: [JS] Move a Guide that has a ScriptLabel
              Level 1
              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.

              Dave
              • 4. Re: [JS] Move a Guide that has a ScriptLabel
                Peter Kahrel Adobe Community Professional & MVP
                Daniel,

                >.guides[0] 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;


                Peter
                • 5. Re: [JS] Move a Guide that has a ScriptLabel
                  Level 1
                  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! :)
                  • 6. Re: [JS] Move a Guide that has a ScriptLabel
                    Level 1
                    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.

                    Dave
                    • 7. Re: [JS] Move a Guide that has a ScriptLabel
                      Level 1
                      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!
                      • 8. Re: [JS] Move a Guide that has a ScriptLabel
                        Level 1
                        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
                        The name.

                        but tables don't have names, only labels. I just tried this:

                        var myStory = app.activeDocument.stories[0];
                        app.select(myStory.tables.item("myTable"));

                        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.

                        Dave
                        • 9. Re: [JS] Move a Guide that has a ScriptLabel
                          Peter Kahrel Adobe Community Professional & MVP
                          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.

                          Peter
                          • 10. Re: [JS] Move a Guide that has a ScriptLabel
                            Level 1
                            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
                            The name.

                            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.

                            Dave
                            • 11. Re: [JS] Move a Guide that has a ScriptLabel
                              Level 1
                              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.

                              Thanks,

                              Ole
                              • 12. Re: [JS] Move a Guide that has a ScriptLabel
                                Level 1
                                Tables don't have names either, but they support itemByName corectly.

                                Dave
                                • 13. Re: [JS] Move a Guide that has a ScriptLabel
                                  Level 1
                                  Hi Dave,

                                  I've said before that that is probably an error. It's nice that it works, though.

                                  Thanks,

                                  Ole
                                  • 14. Re: [JS] Move a Guide that has a ScriptLabel
                                    Peter Kahrel Adobe Community Professional & MVP
                                    >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.

                                    Peter
                                    • 15. Re: [JS] Move a Guide that has a ScriptLabel
                                      Level 1
                                      Hi Peter,

                                      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.

                                      Thanks,

                                      Ole
                                      • 16. Re: [JS] Move a Guide that has a ScriptLabel
                                        Peter Kahrel Adobe Community Professional & MVP
                                        Fair enough -- thanks.

                                        Peter
                                        • 17. Re: [JS] Move a Guide that has a ScriptLabel
                                          Harbs. Level 6
                                          Dave_Saunders@adobeforums.com wrote:
                                          > 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
                                          believe.)

                                          Maybe we should ask for an itemByLabel method which would always work
                                          with the label...

                                          Harbs
                                          • 18. Re: [JS] Move a Guide that has a ScriptLabel
                                            RorohikoKris-u5pUJw Level 2
                                            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");
                                            alert(theItems);

                                            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*");
                                            alert(theItems);

                                            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),
                                            - etc...

                                            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.

                                            http://www.rorohiko.com/apidtoolassistant.html
                                            http://www.rorohiko.com/activepageitemsdeveloper.html
                                            (the downloadable demo of APID contains PDF documentation that is relevant to the free APID ToolAssistant)

                                            Hope it's useful!

                                            Cheers,

                                            Kris
                                            • 19. Re: [JS] Move a Guide that has a ScriptLabel
                                              Peter Kahrel Adobe Community Professional & MVP
                                              That sounds very useful -- thanks.

                                              Peter
                                              • 20. Re: [JS] Move a Guide that has a ScriptLabel
                                                sstanleyau Level 4
                                                On 20/5/08 4:26 PM, "Harbs" <member@adobeforums.com> 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 <sstanley@myriad-com.com.au>
                                                • 21. Re: [JS] Move a Guide that has a ScriptLabel
                                                  Harbs. Level 6
                                                  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.

                                                  Harbs
                                                  • 22. Re: [JS] Move a Guide that has a ScriptLabel
                                                    Harbs. Level 6
                                                    Shane_Stanley@adobeforums.com wrote:
                                                    >> 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...

                                                    Harbs
                                                    • 23. Re: [JS] Move a Guide that has a ScriptLabel
                                                      sstanleyau Level 4
                                                      On 22/5/08 8:58 PM, "Harbs" <member@adobeforums.com> 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 <sstanley@myriad-com.com.au>
                                                      • 24. Re: [JS] Move a Guide that has a ScriptLabel
                                                        TinoRuntzler Level 1

                                                        Hi RorohikoKris

                                                         

                                                        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?

                                                         

                                                        Cheers Tino

                                                        • 25. Re: [JS] Move a Guide that has a ScriptLabel
                                                          Harbs. Level 6

                                                          http://www.rorohiko.com/wordpress/indesign-downloads/active-page-item-developer/

                                                          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++.

                                                           

                                                          Harbs

                                                          http://www.in-tools.com

                                                          • 26. Re: [JS] Move a Guide that has a ScriptLabel
                                                            TinoRuntzler Level 1

                                                            Hi Harbs,

                                                             

                                                            thanks for fast answering. I gonna take a look on the APID.

                                                             

                                                            Cheers Tino