Skip to main content
Inspiring
September 23, 2023
Answered

[Q] Is the Grid and Gridline Every setting in Illustrator scriptable?

  • September 23, 2023
  • 1 reply
  • 702 views

I can't find anything on how to script the Illustrator's grid in JavaScript. In particular I am looking for the GridLine Every setting, as in the Preferences dialogue box:

 

Any help greatly appreciated,

 

Tom

This topic has been closed for replies.
Correct answer tomd75724979

Hi Kurt,

 

I'm so happy - and I hope you are too - to tell you that you're wrong 🙂

 

I found this and it works. cm2pts is just my conversion constant for converting centimeters to points.

 

app.preferences.setRealPreference('Grid/Horizontal/Spacing', 0.9*cm2pts)
$.writeln("Spacing: " + app.preferences.getRealPreference('Grid/Horizontal/Spacing'));

app.preferences.setRealPreference('Grid/Vertical/Spacing', 0.9*cm2pts)
$.writeln("Spacing: " + app.preferences.getRealPreference('Grid/Horizontal/Spacing'));

app.preferences.setIntegerPreference('Grid/Horizontal/Ticks', 1);
app.preferences.setIntegerPreference('Grid/Vertical/Ticks', 1);

$.writeln("Hor ticks: " + app.preferences.getIntegerPreference('Grid/Horizontal/Ticks'));
$.writeln("Vert ticks: " + app.preferences.getIntegerPreference('Grid/Vertical/Ticks'));

1 reply

Kurt Gold
Community Expert
Community Expert
September 23, 2023

As far as I know this setting is currently not accessible to JavaScript.

 

Hopefully I'm wrong here.

 

tomd75724979AuthorCorrect answer
Inspiring
September 23, 2023

Hi Kurt,

 

I'm so happy - and I hope you are too - to tell you that you're wrong 🙂

 

I found this and it works. cm2pts is just my conversion constant for converting centimeters to points.

 

app.preferences.setRealPreference('Grid/Horizontal/Spacing', 0.9*cm2pts)
$.writeln("Spacing: " + app.preferences.getRealPreference('Grid/Horizontal/Spacing'));

app.preferences.setRealPreference('Grid/Vertical/Spacing', 0.9*cm2pts)
$.writeln("Spacing: " + app.preferences.getRealPreference('Grid/Horizontal/Spacing'));

app.preferences.setIntegerPreference('Grid/Horizontal/Ticks', 1);
app.preferences.setIntegerPreference('Grid/Vertical/Ticks', 1);

$.writeln("Hor ticks: " + app.preferences.getIntegerPreference('Grid/Horizontal/Ticks'));
$.writeln("Vert ticks: " + app.preferences.getIntegerPreference('Grid/Vertical/Ticks'));
Kurt Gold
Community Expert
Community Expert
September 23, 2023

I haven't tried your approach yet, but if it works I'm certainly happy that I was wrong.