10 Replies Latest reply on Oct 6, 2010 6:40 PM by Michael L Hale

    Ruler offsets/origin

    Ghoulfool Level 1

      I've noticed that the listener (in CS2) does not record the offset coordinates when you move the ruler's origin from the top left hand corner. Surely it's kept as a variable somewhere that you can hook into? Basically as part of a script I need to know how much it gets moved by if it's not in the top left hand corner. Is this possible? Thanks

        • 1. Re: Ruler offsets/origin
          Ghoulfool Level 1

          Does nobody know or (more likely) nobody has needed to know as any offsets have been taken from the (default) top left rether than an arbitary position where the ruler's origin may get moved to?


          Or is it because I didn't use an amusing title?

          • 2. Re: Ruler offsets/origin
            Muppet Mark-QAl63s Level 4

            If it makes you sleep any better I don't know how you would do this either… This is a one off I can't spear the time posting responses to questions I have NO answer for… I would be here all day… I did look…

            • 3. Re: Ruler offsets/origin
              Muppet Mark-QAl63s Level 4

              Actually I lie it may be of partial use to know but new guides are made relative to the ruler offset position…


              #target photoshop
              var docRef = app.activeDocument;
              with (docRef) {
                   addGuide(0, 'Vrtc');
                   addGuide(0, 'Hrzn');
              function addGuide(a, b) {
                   // 'Vrtc' or 'Hrzn')
                   function cTID(s) { return app.charIDToTypeID(s); };
                   function sTID(s) { return app.stringIDToTypeID(s); };
                        var desc207 = new ActionDescriptor();
                        var desc208 = new ActionDescriptor();
                        desc208.putUnitDouble( cTID('Pstn'), cTID('#Pxl'), a );
                        desc208.putEnumerated( cTID('Ornt'), cTID('Ornt'), cTID( b ) );
                        desc207.putObject( cTID('Nw  '), cTID('Gd  '), desc208 );
                   executeAction( cTID('Mk  '), desc207, DialogModes.NO );


              Close with saving, reopen resets to 0,0 there may be a method of reading positions in either the newer versions or with action manager? Can't help with either of those…

              • 4. Re: Ruler offsets/origin
                Ghoulfool Level 1

                Thanks for that. And yes, I only sleep at night when all the rulers are put away straight and ordered in the ruler drawer!

                • 5. Re: Ruler offsets/origin
                  Michael L Hale Level 5

                  Like Mark I didn't want to make a post without an answer.


                  There are things with script that you can get and set, some are get only and some there is no access to all. I am sure that Photoshop stores that info somewhere, I just don't know where and the fact the scriptlistener doesn't record changing the offset is not a good sign. That normally means there is no scripting access.

                  • 6. Re: Ruler offsets/origin
                    Muppet Mark-QAl63s Level 4

                    Guides are part of the DOM in CS5. So Im supposing you could create name place in that version. But closing and re opening the doc may be the only way to reset the origin back. Ugly.


                    Selection is also based upon this…


                    #target photoshop
                    var docRef = app.activeDocument;
                    with(docRef) {
                         var selRegion = [ [0,0],[0,10],[10,10],[10,0] ]


                    So may be you could fill and calculate bounds (as they are broken in CS2)

                    • 7. Re: Ruler offsets/origin
                      Muppet Mark-QAl63s Level 4

                      Michel, what I am able to do in the GUI but NOT sure how to script? Selection will take negative values. A single pixel can be selected at [0,0] origin. I can translateBoundary both upwards and left what Im unsure on is can I count until a while loop errors. The idea being if selection.copy() does not error then its captured doc pixels. Does that make any sense?

                      • 8. Re: Ruler offsets/origin
                        Michael L Hale Level 5

                        Here is how to get the offset.


                        var ref = new ActionReference();
                        ref.putEnumerated( charIDToTypeID("Dcmn"), charIDToTypeID("Ordn"), charIDToTypeID("Trgt") ); 
                        var desc = executeActionGet(ref);
                        var xOffSet = desc.getInteger(stringIDToTypeID('rulerOriginH'));
                        var yOffSet = desc.getInteger(stringIDToTypeID('rulerOriginV'));
                        alert( xOffSet/65536 );
                        alert( yOffSet/65536 );


                        Working on a way to set( or at least reset ).

                        • 9. Re: Ruler offsets/origin

                          This was exactly what I was looking for to solve a different issue. Thank you. Out of curiosity, why do you have to divide by 65536? What is that value all about? Thank again!

                          • 10. Re: Ruler offsets/origin
                            Michael L Hale Level 5

                            One of the problems with using Action Manager is there is no documention. The offsets are stored in the document descriptor as integers. That stored integer needs to be adjusted to pixels. I chose to divide by 65536 because most people understand division. I could have converted by bit shifting ( xOffSet >> 16 ) but I thought it would not be as clear.


                            I don't know why Adobe stored the value in that way. It is ruler and doc resolution indenpent. I seem to recall running into values stored that way before but don't recall where.