• Global community
    • Language:
      • Deutsch
      • English
      • EspaƱol
      • FranƧais
      • PortuguĆŖs
  • ę—„ęœ¬čŖžć‚³ćƒŸćƒ„ćƒ‹ćƒ†ć‚£
    Dedicated community for Japanese speakers
  • ķ•œźµ­ ģ»¤ė®¤ė‹ˆķ‹°
    Dedicated community for Korean speakers
Exit
1

P: Ability to "Ruler origin" by script

Enthusiast ,
Aug 24, 2016 Aug 24, 2016

Copy link to clipboard

Copied

I want to make sure a user has its ruler origin reseted to document top/left.
But I can't reset it by script.

Idea Released
TOPICS
macOS , Windows

Views

554

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Adobe Employee , Nov 18, 2016 Nov 18, 2016

// Version 2016.11.18
// Show how to get and set the ruler origin point for the current document
// Values are in pixels shifted 16 bits

// some constants to make it more readable
const classProperty                = app.stringIDToTypeID("property");
const krulerOriginHStr             = app.stringIDToTypeID("rulerOriginH");
const krulerOriginVStr             = app.stringIDToTypeID("rulerOriginV");
const classDocument                = app.stringIDToTypeID("document");
const typeOrdinal                  =

...

Votes

Translate

Translate
18 Comments
Community Expert ,
Aug 24, 2016 Aug 24, 2016

Copy link to clipboard

Copied

Votes

Translate

Translate

Report

Report
Enthusiast ,
Aug 24, 2016 Aug 24, 2016

Copy link to clipboard

Copied

I'll ask on ps-scripts, thanks.

Votes

Translate

Translate

Report

Report
LEGEND ,
Aug 24, 2016 Aug 24, 2016

Copy link to clipboard

Copied

The path you entered, is too long. Enter a shorter pathFile Name could not be found. Check the spelling of the filename, 
and verify that the file location is correct.

Votes

Translate

Translate

Report

Report
Enthusiast ,
Aug 24, 2016 Aug 24, 2016

Copy link to clipboard

Copied

Hi Albina, are you refering the link Christoph wrote?
That path of PS scripts forum path works perfectly.

Can you explain better?

Votes

Translate

Translate

Report

Report
Enthusiast ,
Aug 24, 2016 Aug 24, 2016

Copy link to clipboard

Copied

Sorry Albina, I didn't explain myself write.
I'm not refering a variable name.
I'm refering the x,y position of the origin [0,0] of the rulers.
The user can drag and change de [0,0] position.

What I want is to run a script to allow reset the 0,0 relative position to the document top/left position again.

Votes

Translate

Translate

Report

Report
Explorer ,
Aug 24, 2016 Aug 24, 2016

Copy link to clipboard

Copied

You can close and re-open the file to reset the ruler origin the 0,0. 

Votes

Translate

Translate

Report

Report
Enthusiast ,
Aug 24, 2016 Aug 24, 2016

Copy link to clipboard

Copied

It could be done, but still it makes no sense to provoque such a drastic turn arround for my retouchers team.

Votes

Translate

Translate

Report

Report
Community Expert ,
Aug 24, 2016 Aug 24, 2016

Copy link to clipboard

Copied

In one thread Mike Hale mentioned that he could reset the rulerOrigin but he did not post the code. 
http://www.ps-scripts.com/viewtopic.php?f=66&t=6934&p=34798&hilit=rulerOriginH&sid=8...

Votes

Translate

Translate

Report

Report
Enthusiast ,
Aug 24, 2016 Aug 24, 2016

Copy link to clipboard

Copied

Well, ps-scrips is inaccessible again, 

I will use Michael Hale ruler orign to get the ruler x,y and I'll have to review all my code to compensate this.

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'));  
$.writeln( xOffSet >> 16 );
$.writeln( yOffSet >> 16 );

// >> 16 converts the 16bits Integer to pixels (Michael Hale in https://forums.adobe.com/thread/650622)

Votes

Translate

Translate

Report

Report
Enthusiast ,
Aug 24, 2016 Aug 24, 2016

Copy link to clipboard

Copied

This was the answer from Michael L Hale:
Re: how to change ruler's Origin

by Mike Hale Ā» Mon Oct 25, 2010 8:56 pm

A couple of thoughts. Scriptlistener doesn't record changing the ruler offset because that is done with the mouse and scriptlistener doesn't record most actions done with the mouse. And I don't see any other way to change it in the GUI using menus or keyboard shortcuts.
RulerOriginH and RulerOriginV are two of a document's action descriptor keys. You can use those IDs to get the current offsets. There are some things that you can get but not set and this may be one of those. When I try to construct an executeAction to set the offset the best I can do is set it to 0. That is to say no matter what value I use in the executeAction, the ruler resets to 0.
I have never spent a lot of time trying to get setting the offset to work so it may be possible but I suspect that it needs access to the ruler class and action manager does not have that access.

Votes

Translate

Translate

Report

Report
Explorer ,
Aug 25, 2016 Aug 25, 2016

Copy link to clipboard

Copied

I thought you could do it within the script by setting a variable to the current file path/filename and then close the file with save changes. Open the file using that variable and the origin will be reset to 0,0.

The files I work with are huge and would take too long to save and re-open. If you are dealing with small files, you wouldn't notice much delay.

I had to use offsets like you described above, but it makes my code more complex.

Votes

Translate

Translate

Report

Report
Enthusiast ,
Aug 26, 2016 Aug 26, 2016

Copy link to clipboard

Copied

Each retoucher open/saves 500 images/day on average.
My team has 6500 images/day on average.
Can't do that.
It's easier to assume de ruler origin has a variable on team scripts.

Votes

Translate

Translate

Report

Report
Explorer ,
Aug 26, 2016 Aug 26, 2016

Copy link to clipboard

Copied

The offset solution is the only other suggestion I have, here is the code I use:

var ref = new ActionReference();  // figure out where the ruler origin is - we can't change it, but we can offset it
ref.putEnumerated( charIDToTypeID("Dcmn"), charIDToTypeID("Ordn"), charIDToTypeID("Trgt") );  
var desc = executeActionGet(ref);  
var xRulerRawOffSet = desc.getInteger(stringIDToTypeID('rulerOriginH'));  
var yRulerRawOffSet = desc.getInteger(stringIDToTypeID('rulerOriginV'));  
var xRuler = xRulerRawOffSet/65536 // these are stored as two byte numbers so they need to be divided
var yRuler = yRulerRawOffSet/65536
 I hope it helps!

Votes

Translate

Translate

Report

Report
Enthusiast ,
Aug 26, 2016 Aug 26, 2016

Copy link to clipboard

Copied

Yes, that's the one I'm using. Thanks,

Votes

Translate

Translate

Report

Report
LEGEND ,
Sep 05, 2016 Sep 05, 2016

Copy link to clipboard

Copied

I used to have similar problems too, but after using
"long path tool" You can use to solve this problem.

Votes

Translate

Translate

Report

Report
Adobe Employee ,
Nov 18, 2016 Nov 18, 2016

Copy link to clipboard

Copied

// Version 2016.11.18
// Show how to get and set the ruler origin point for the current document
// Values are in pixels shifted 16 bits

// some constants to make it more readable
const classProperty                = app.stringIDToTypeID("property");
const krulerOriginHStr             = app.stringIDToTypeID("rulerOriginH");
const krulerOriginVStr             = app.stringIDToTypeID("rulerOriginV");
const classDocument                = app.stringIDToTypeID("document");
const typeOrdinal                  = app.stringIDToTypeID("ordinal");
const enumTarget                   = app.stringIDToTypeID("targetEnum");
const typeNULL                     = app.stringIDToTypeID("null");
const keyTo                        = app.stringIDToTypeID("to");
const eventSet                     = app.stringIDToTypeID("set");



// get the current values
GetRulerOrigin().toSource();

// set them to zero, negative numbers work as well
SetRulerOrigin(0, 0);



//////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////


function GetRulerOrigin() {


    var ro = {};

    ro.horizontal = GetInfo(classDocument, krulerOriginHStr) >> 16;
    ro.vertical = GetInfo(classDocument, krulerOriginVStr) >> 16;
    
    return ro;
}

function SetRulerOrigin(horiz, vert) {


    var desc = new ActionDescriptor();
    var ref = new ActionReference();
    ref.putProperty(classProperty, krulerOriginHStr);
    ref.putEnumerated(classDocument, typeOrdinal, enumTarget);
    desc.putReference(typeNULL, ref);
    desc.putInteger(keyTo, horiz << 16);
    executeAction(eventSet, desc, DialogModes.NO);

    var desc = new ActionDescriptor();
    var ref = new ActionReference();
    ref.putProperty(classProperty, krulerOriginVStr);
    ref.putEnumerated(classDocument, typeOrdinal, enumTarget);
    desc.putReference(typeNULL, ref);
    desc.putInteger(keyTo, vert << 16);
    executeAction(eventSet, desc, DialogModes.NO);
}



///////////////////////////////////////////////////////////////////////////////
// Function: GetInfo
// Usage: Get information from Photoshop
// Input: desiredClass, classApplication, classLayer, etc.
//        desiredKey, optional specific key to get instead of everything
//                    this is recommended as all keys is an expensive call
// Return: ActionDescriptor or single value depending on what is asked for
///////////////////////////////////////////////////////////////////////////////
function GetInfo(desiredClass, desiredKey) {


    var reference = new ActionReference();
    if (typeof desiredKey != "undefined") {


        reference.putProperty(stringIDToTypeID("property"), desiredKey);
    }
    reference.putEnumerated(desiredClass, stringIDToTypeID("ordinal"), stringIDToTypeID("targetEnum")); 
    var desc = executeActionGet(reference);
    if (typeof desiredKey != "undefined") {


        return GetItemFromDescriptor(desc, desiredKey);
    }
    return desc;
}

///////////////////////////////////////////////////////////////////////////////
// Function: GetItemFromDescriptor
// Usage: Get a specific key from an ActionDescriptor
// Input: desc (ActionDescriptor), valid ActionDescriptor to pull info from
//        desiredKey (Number), key in question, use charIDToTypeID() or
//                             stringIDToTypeID()
// Return: ActionDescriptor or single value depending on what is asked for
///////////////////////////////////////////////////////////////////////////////
function GetItemFromDescriptor(desc, desiredKey) {


    if (desc.hasKey(desiredKey)) {


        var typeID = desc.getType(desiredKey);
        switch (typeID) {


            case DescValueType.BOOLEANTYPE:
return desc.getBoolean(desiredKey);
break;
case DescValueType.STRINGTYPE:
return desc.getString(desiredKey);
break;
case DescValueType.DOUBLETYPE:
return desc.getDouble(desiredKey);
break;
case DescValueType.INTEGERTYPE:
                return desc.getInteger(desiredKey);
                break;
            case DescValueType.LARGEINTEGERTYPE:
            return desc.getLargeInteger(desiredKey);
            break;
case DescValueType.OBJECTTYPE:
                return desc.getObjectValue(desiredKey);
                break;
case DescValueType.UNITDOUBLE:
                var newT = desc.getUnitDoubleType(desiredKey);
                var newV = desc.getUnitDoubleValue(desiredKey);
                return new UnitValue(newV, newT);
                break;
case DescValueType.ENUMERATEDTYPE:
                return desc.getEnumerationValue(desiredKey);
                break;
case DescValueType.CLASSTYPE:
                return desc.getClass(desiredKey);
                break;
case DescValueType.ALIASTYPE:
                return desc.getPath(desiredKey);
                break;
case DescValueType.RAWTYPE:
                var tempStr = desc.getData(desiredKey);
                var rawData = new Array();
                for (var tempi = 0; tempi < tempStr.length; tempi++) { 
                    rawData[tempi] = tempStr.charCodeAt(tempi); 
                }
                return rawData;
                break;
case DescValueType.REFERENCETYPE:
                return desc.getReference(desiredKey);
                break;
case DescValueType.LISTTYPE:
                return desc.getList(desiredKey);
                break;
default:
return;
        }
    }
return;
}

Votes

Translate

Translate

Report

Report
Enthusiast ,
Nov 18, 2016 Nov 18, 2016

Copy link to clipboard

Copied

Thank you Tom!

Votes

Translate

Translate

Report

Report
Community Expert ,
May 16, 2021 May 16, 2021

Copy link to clipboard

Copied

LATEST

Votes

Translate

Translate

Report

Report