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

Set unit preferences (Javascript)

Community Beginner ,
Aug 12, 2014 Aug 12, 2014

Copy link to clipboard

Copied

I can't find a way to set the unit preferences for Illustrator CS6/CC using JavaScript.

I found that this works (setting units for stroke):

var units = 2; // 0-inches, 1-milllimeters, 2-points

app.preferences.setIntegerPreference("strokeUnits", units)

But I want to set the ruler units ("General" in the interface), and this does not work:

app.preferences.setIntegerPreference("rulerUnits", units)

Any help?

Peter

TOPICS
Scripting

Views

12.5K

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

Community Expert , Aug 25, 2014 Aug 25, 2014

Hi,

We can set ruler unit using "rulerType" key not "rulerUnit".

Check below script:

var units = 0; //(0 to 6)

app.preferences.setIntegerPreference("rulerType", units);

/*Unit list

0 : point

1 : pica

2 : inch

3 : mm

4 : cm

5 : H/Q

6 : px

*/

Ten

Votes

Translate

Translate
Adobe
Community Expert ,
Aug 25, 2014 Aug 25, 2014

Copy link to clipboard

Copied

Hi,

We can set ruler unit using "rulerType" key not "rulerUnit".

Check below script:

var units = 0; //(0 to 6)

app.preferences.setIntegerPreference("rulerType", units);

/*Unit list

0 : point

1 : pica

2 : inch

3 : mm

4 : cm

5 : H/Q

6 : px

*/

Ten

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 Beginner ,
Sep 01, 2014 Sep 01, 2014

Copy link to clipboard

Copied

Ten,

Yes, this works, finally! Thank you very much with this simple but poorly documented feature.

I noticed that the unit mapping is:  0: inches, 1: mm, 2: points, 3: pica, 4: cm, 5: custom, 6: pixels

Regards,

Peter

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 ,
Sep 01, 2014 Sep 01, 2014

Copy link to clipboard

Copied

Oops! Apologies for my mistake.

I'll update my documentation, Thanks.

Ten

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
New Here ,
Oct 22, 2014 Oct 22, 2014

Copy link to clipboard

Copied

Where can I find the documentation for all preference set via the setIntegerPreference and similar methods on app.preferences ?

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 ,
Oct 22, 2014 Oct 22, 2014

Copy link to clipboard

Copied

There are no documentation by Adobe.

But, You can reference below script:

https://github.com/ten-A/Extend_Script_experimentals/blob/master/preferencesKeeper.jsx

Ten

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
Valorous Hero ,
May 07, 2017 May 07, 2017

Copy link to clipboard

Copied

Unfortunately I just can't get this one to work, I'm on Ai 21.1.0

To confirm- the expected result is to see the active ai's documents to be changed right after the script command is executed?

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 ,
May 07, 2017 May 07, 2017

Copy link to clipboard

Copied

yes, the expected result is to see units changed in the general preference window. Still works in Win CC2017

unitPreferences.PNG

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
Valorous Hero ,
May 07, 2017 May 07, 2017

Copy link to clipboard

Copied

That's funny, it does affect the dropdown selection in the preferences dialog, but does not change the active document's ruler units. Changing the selection on the preferences dialog does set the active document, but only when the unit is different than the one you just set via script, I think because it thinks it's already applies so it says no change needed.

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 ,
May 07, 2017 May 07, 2017

Copy link to clipboard

Copied

Additionally, We can access document level unit preference from Javascript.

But its READ ONLY...

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
Valorous Hero ,
May 12, 2017 May 12, 2017

Copy link to clipboard

Copied

Unfortunately.. so the only current way of changing a document's current ruler units is GUI scripting with send-keys, or creating a completely new document and pasting all art inside?

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
Enthusiast ,
May 13, 2017 May 13, 2017

Copy link to clipboard

Copied

Again, possible way can be: save document uncompressed then modify the file directly.

%AI5_RulerUnits: 2

Change 2 to 0-6.

app.preferences.setBooleanPreference ('aiFileFormat/enableContentRecovery', true);

app.preferences.setBooleanPreference ('aiFileFormat/dumpPGFwithoutShortcut', true);

var d = app.activeDocument,

    fn = d.fullName,

    f = File(d.path + '/_' + d.name),

    unit = 3;

   

d.close();

app.open(fn);

app.activeDocument.close();

parseData(f, unit);

app.open(f);

// then save as origin name with compression if you like.

app.preferences.setBooleanPreference ('aiFileFormat/dumpPGFwithoutShortcut', false);

function parseData(f, unit) {

    f.encoding  = 'BINARY';

    f.open('e');

    var re = /%AI5_RulerUnits: \d/;

    while (!f.eof) {

        if (re.test(f.readln())) {

            f.seek(-1 - (f.lineFeed == 'windows' ? 2 : 1), 1);

            f.write(unit);

            f.close();

            break;

        }

    }

}

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
New Here ,
Sep 19, 2017 Sep 19, 2017

Copy link to clipboard

Copied

Unit properties follow ExtendScipt Tool

/*Unit list -

Unknown: - 1

Points - 4 :

Picas - 5 :

Inches -  2 :

Millimeters - 6 :

Centimeters - 3

Pixel - 8

Qs - 7

/*

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
Advocate ,
Dec 12, 2017 Dec 12, 2017

Copy link to clipboard

Copied

LATEST

Sorry for bugging here, but im loosing my mind here with scripting. I want to change the default AdjustLayout.jsx script to metric using millimeters, so change all points references in the file. But when the popup comes it keeps calculating my input to points. How is this even possible?

I know this is illustrator but the scripting is same language right?    

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