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

Set unit preferences (Javascript)

Community Beginner ,
Aug 12, 2014 Aug 12, 2014

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
14.0K
Translate
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

Translate
Adobe
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

Translate
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

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

Translate
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

Oops! Apologies for my mistake.

I'll update my documentation, Thanks.

Ten

Translate
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

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

Translate
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

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

Translate
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

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?

Translate
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

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

unitPreferences.PNG

Translate
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

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.

Translate
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

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

But its READ ONLY...

Translate
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

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?

Translate
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

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;

        }

    }

}

Translate
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

Unit properties follow ExtendScipt Tool

/*Unit list -

Unknown: - 1

Points - 4 :

Picas - 5 :

Inches -  2 :

Millimeters - 6 :

Centimeters - 3

Pixel - 8

Qs - 7

/*

Translate
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
Advisor ,
Dec 12, 2017 Dec 12, 2017
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?    

Translate
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