7 Replies Latest reply on Mar 21, 2013 1:10 AM by restless_mind

    align object using a key object

    restless_mind Level 1

      Hi there,

       

      has anybody successfully been able to script CS6s align using key object? I've tried this in applescript and I'm farely sure my syntax is ok but I just can't make it work.

       

      tell application "Adobe InDesign CS6"

        activate

                set mydoc to document 1

                set f to properties of align distribute preferences

                set keyObject to item 1 of (every page item of mydoc whose label is "key_object")

                set theFrame to item 1 of (every page item of mydoc whose label is "myframe")

        select keyObject

        select theFrame existing selection add to

        select keyObject existing selection set key

        --set selection key object to keyObject

                tell align distribute preferences to set align distribute bounds to key object

        align document 1 align distribute items {keyObject, theFrame} align option vertical centers align distribute bounds key object

      end tell

       

      when I run the above script on a document that consists of 2 frame, one labelled 'key_object' and another labelled 'myframe' the script just returns this error:

       

      error "Adobe InDesign CS6 got an error: Missing required parameter 'reference' for method 'align'." number 30479

       

      Any help would be appreciated.

       

      Thanks,

      Nik

        • 1. Re: align object using a key object
          [Jongware] Most Valuable Participant

          The error message indicates you are missing a parameter 'reference', and checking the DOM Reference indicates that's indeed the case. On http://jongware.mit.edu/idcs6js/pc_Document.html#align you can read

           

          reference [...] The reference or key object to align to distribute relative to. Required when 'align distribute bounds' specifies 'key object'. (Optional)

          (my emph.)

           

          .. although I'm in the dark on how to say that in AppleScript

          • 2. Re: align object using a key object
            restless_mind Level 1

            Hi,

             

            many thanks for the relpy. I just just tried this in ExtendScript

             

            var mydoc = app.activeDocument

            mydoc.align (app.selection , AlignOptions.HORIZONTAL_CENTERS, AlignDistributeBounds.KEY_OBJECT)

             

            and I get this error:

             

            Missing required parameter 'reference' for method 'align'

             

            which is similar to my Applescript error. Also I noticed that when I typed the line AlignDitributeBounds. the auto completion only listed these options:

             

            ITEM_BOUNDS

            MARGIN_BOUNDS

            PAGE_BOUNDS

            SPREAD_BOUNDS

             

            no sign of KEY_OBJECT even though the reference you supplied indicates it as a valid option!!!

             

            Could this be a bug in CS6?

             

            Any further help is greatfully appreciated.

            Nik

            • 3. Re: align object using a key object
              Jump_Over Level 5

              Hi,

               

              Back to your script's goal:

              Seems like it is to distribute vertically by centers every of textFrames:

                   whose label is "myframe"

              on specific page:

                   whose label is "key_object"

               

              So it will works if some of your pages' label will be "key_object" (not a textFrame)

              and some of yours textFrames there will be labeled with "myframe".

               

              Starting with this you could go further..., I hope...

              • 4. Re: align object using a key object
                Marijan Tompa [tomaxxi] Level 4

                You are missing one parameter in your call.

                 

                Here is the right usage:

                 

                var
                    mD = app.activeDocument,
                    mS = app.selection;
                
                // KeyObject assigned in UI 
                mD.align ( mS, AlignOptions.HORIZONTAL_CENTERS, AlignDistributeBounds.KEY_OBJECT, mD.selectionKeyObject );
                
                // or use first selected object
                mD.align ( mS, AlignOptions.HORIZONTAL_CENTERS, AlignDistributeBounds.KEY_OBJECT, mS [ 0 ] );
                

                 

                Hope that helps.

                 

                --

                Marijan (tomaxxi)

                http://tomaxxi.com

                1 person found this helpful
                • 5. Re: align object using a key object
                  restless_mind Level 1

                  Hi There,

                   

                  It's been a couple of weeks since I originally posted this message but I finally got another chance to look at it.

                   

                  Firstly thanks to Marijan for your reply and using JavaScript the command works perfectly, but I'm still unable to get this to work in applescript!!! I stripped it back to basics and just created a document with 2 frames and selected a key object, then I ran the below code:

                   

                  tell application "Adobe InDesign CS6"

                            set f to selection key object of document 1

                    align document 1 align distribute items selection align option horizontal centers align distribute bounds key object

                  end tell

                   

                  When I run this command I still get this error:

                  --> error "Missing required parameter 'reference' for method 'align'." number 30479

                   

                  Now I noticed that in JavaScript the align command is passed the parameter of the selection key object but in applescript there's no way to pass this so that the syntax compiles. I would love to know if anybody can get this to work in applescript.

                   

                  For the time being I have manged to run the JavaScript from within applescript like this:

                   

                  set myJavaScript to "var mD = app.activeDocument;

                  var mS = app.selection;

                  mD.align ( mS, AlignOptions.HORIZONTAL_CENTERS, AlignDistributeBounds.KEY_OBJECT, mD.selectionKeyObject );"

                   

                  tell application "Adobe InDesign CS6"

                    do script myJavaScript language javascript

                  end tell

                   

                  Thanks again,

                  Nik

                  • 6. Re: align object using a key object
                    -hans- Level 4

                    Hi,

                     

                    can't test it at the moment as no cs 6 but as the error message told you guess you've missed the reference _> page item

                     

                    try

                     

                    tell application "Adobe InDesign CS6"

                        set sel to selection

                        align active document align distribute items sel align option vertical centers align distribute bounds key object reference (item 1 of selection)

                        end tell

                    • 7. Re: align object using a key object
                      restless_mind Level 1

                      Hi Hans,

                       

                      Thanks for your reply.

                       

                      I just tried your script and it won't compile! It seems although the align command is expectiong a reference for the 'key object' it doesn't allow you to indicate what that 'key object' is.

                       

                      If I change the parameter for the 'align distribute bounds' to any of the other options in the dictionary i.e. 'item bounds/page bounds/margin bounds/spread bounds/' they all work, it's only when I use the 'key object' that it causes any error. So I'm either missing something in the syntax or the command has a bug.

                       

                      Thanks,

                      Nik