• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

How to set rulerUnits by ActionManager code?

Guide ,
Jul 01, 2020 Jul 01, 2020

Copy link to clipboard

Copied

How to set rulerUnits by ActionManager code? I tried several options, but I can not achieve the result.

 

 

s2t = stringIDToTypeID;
(r = new ActionReference()).putProperty(s2t("property"), s2t("rulerUnits"));
r.putEnumerated(s2t('application'), s2t('ordinal'), s2t('targetEnum'));
(d = new ActionDescriptor).putReference(s2t('target'), r);
(d1 = new ActionDescriptor).putEnumerated(s2t('rulerUnits'), s2t('rulerUnits'), s2t('rulerPixels'));
d.putObject(s2t('to'), s2t('rulerUnits'), d1);
executeAction(s2t('set'), d, DialogModes.NO);

 

 

 

s2t = stringIDToTypeID;
(r = new ActionReference()).putClass(s2t("rulerUnits"));
(d = new ActionDescriptor).putReference(s2t('target'), r);
(d1 = new ActionDescriptor).putEnumerated(s2t('rulerUnits'), s2t('rulerUnits'), s2t('rulerPixels'));
d.putObject(s2t('to'), s2t('target'), d1);

 

 

TOPICS
Actions and scripting

Views

583

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

LEGEND , Jul 01, 2020 Jul 01, 2020
sTT =  stringIDToTypeID; (ref = new ActionReference()).putProperty(sTT('property'), uP = sTT('unitsPrefs'))
ref.putClass(sTT('application')); (dsc1 = new ActionDescriptor()).putReference(sTT('null'), ref);
(dsc2 = new ActionDescriptor()).putEnumerated(rU = sTT('rulerUnits'), rU, sTT('rulerPixels'))
dsc1.putObject(sTT('to'), uP, dsc2), executeAction(sTT('set'), dsc1)

Votes

Translate

Translate
Adobe
LEGEND ,
Jul 01, 2020 Jul 01, 2020

Copy link to clipboard

Copied

You can check their visibility and then for example hide them (so using the trick):

 

sTT = stringIDToTypeID; (ref = new ActionReference())
.putProperty(sTT('property'), rV = sTT('rulersVisibility'))
ref.putEnumerated(sTT('document'), sTT('ordinal'), sTT('targetEnum'))
executeActionGet(ref).getBoolean(rV) && runMenuItem(sTT('toggleRulers'))

 

Otherwise in your first code change target to null, while in second and the one before last rulerUnits to unitsPrefs.

 

Votes

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
Guide ,
Jul 01, 2020 Jul 01, 2020

Copy link to clipboard

Copied

I am trying to set the units of measure, and not control the visibility of the rulers.

Votes

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
LEGEND ,
Jul 01, 2020 Jul 01, 2020

Copy link to clipboard

Copied

sTT =  stringIDToTypeID; (ref = new ActionReference()).putProperty(sTT('property'), uP = sTT('unitsPrefs'))
ref.putClass(sTT('application')); (dsc1 = new ActionDescriptor()).putReference(sTT('null'), ref);
(dsc2 = new ActionDescriptor()).putEnumerated(rU = sTT('rulerUnits'), rU, sTT('rulerPixels'))
dsc1.putObject(sTT('to'), uP, dsc2), executeAction(sTT('set'), dsc1)

Votes

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
Community Expert ,
Jul 01, 2020 Jul 01, 2020

Copy link to clipboard

Copied

Try this raw SL recording using pixels as the unit:

 

 

// =======================================================
var idsetd = charIDToTypeID( "setd" );
    var desc589 = new ActionDescriptor();
    var idnull = charIDToTypeID( "null" );
        var ref113 = new ActionReference();
        var idPrpr = charIDToTypeID( "Prpr" );
        var idUntP = charIDToTypeID( "UntP" );
        ref113.putProperty( idPrpr, idUntP );
        var idcapp = charIDToTypeID( "capp" );
        var idOrdn = charIDToTypeID( "Ordn" );
        var idTrgt = charIDToTypeID( "Trgt" );
        ref113.putEnumerated( idcapp, idOrdn, idTrgt );
    desc589.putReference( idnull, ref113 );
    var idT = charIDToTypeID( "T   " );
        var desc590 = new ActionDescriptor();
        var idRlrU = charIDToTypeID( "RlrU" );
        var idRlrU = charIDToTypeID( "RlrU" );
        var idRrPx = charIDToTypeID( "RrPx" );
        desc590.putEnumerated( idRlrU, idRlrU, idRrPx );
    var idUntP = charIDToTypeID( "UntP" );
    desc589.putObject( idT, idUntP, desc590 );
executeAction( idsetd, desc589, DialogModes.NO );

 

 

Or this cleaned version:

 

 

set();
function set() {
	var c2t = function (s) {
		return app.charIDToTypeID(s);
	};

	var s2t = function (s) {
		return app.stringIDToTypeID(s);
	};

	var descriptor = new ActionDescriptor();
	var descriptor2 = new ActionDescriptor();
	var reference = new ActionReference();

	reference.putProperty( s2t( "property" ), s2t( "unitsPrefs" ));
	reference.putEnumerated( s2t( "application" ), s2t( "ordinal" ), s2t( "targetEnum" ));
	descriptor.putReference( c2t( "null" ), reference );
	descriptor2.putEnumerated( s2t( "rulerUnits" ), s2t( "rulerUnits" ), s2t( "rulerPixels" ));
	descriptor.putObject( s2t( "to" ), s2t( "unitsPrefs" ), descriptor2 );
	executeAction( s2t( "set" ), descriptor, DialogModes.NO );
}

 

Hopefully you can cut that back to a more concise version, or perhaps transplant the working bits into your more concise code.

 

Votes

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
Guide ,
Jul 01, 2020 Jul 01, 2020

Copy link to clipboard

Copied

 sTT('unitsPrefs'))

I tried to put them in another object 🙂
By the way, I couldn’t write this action through ScriptListener. What did you do to record it?

Thanks!

Votes

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
LEGEND ,
Jul 01, 2020 Jul 01, 2020

Copy link to clipboard

Copied

As you see in my 1st updated post also target instead of null, however with target it works as well.

 

btw for the future similar changes do by preferences, not document to get Script Listener record.

Votes

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
Guide ,
Jul 01, 2020 Jul 01, 2020

Copy link to clipboard

Copied

s2t('target') == s2t('null') 

Votes

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
Community Expert ,
Jul 01, 2020 Jul 01, 2020

Copy link to clipboard

Copied

jazz-y, I'm curious, was this just an exercise to learn AM code? I doubt that this was performance-related...

 

When the DOM code is so simple compared to AM code:

 

app.preferences.rulerUnits = Units.PIXELS;

 

 

Votes

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
Guide ,
Jul 01, 2020 Jul 01, 2020

Copy link to clipboard

Copied

LATEST

It's not about simplicity, but speed.

 

I have a script that changes the content and position of a text layer in a certain way. With a single launch, the difference in the execution time does not play a role, but it can be launched by the user using a different script for each text layer of the document (sometimes it is 100+ layers). With this option, the time difference may already be noticeable.

 

In the working code, I use wrappers for AM functions (such as what CleanSL outputs), which allows me to write them much shorter

Votes

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