Grid Spacing

Explorer ,
Dec 16, 2021 Dec 16, 2021

Copy link to clipboard

Copied

I am trying to change the grid spacing, the script is working fine, I am returning the correct value, but unfortunately, the result is the same does not change inside preferences and on the artboard, the grid space does not change, can anyone please help me with this.
 

 

var pref = app.preferences;
var grid = pref.getRealPreference('Grid/Horizontal/Spacing');
$.write(grid);

switch (grid) {
  case 12.5: Spacing = 25; break;
  case 25: Spacing = 50; break;
  case 50: Spacing = 12.5; break;
  default: Spacing = 12.5; break;
}

pref.setRealPreference('Grid/Horizontal/Spacing', Spacing);
redraw();

 

Illustrator_2021-12-16_22-04-03.png

 
TOPICS
Scripting

Views

82

Likes

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
Adobe Community Professional ,
Dec 19, 2021 Dec 19, 2021

Copy link to clipboard

Copied

Try to set the preference, and then open a new document to see if the new grid spacing is set like you want. If not, try to restart Illustrator to check whether it is properly set on the next time you open Ai.
If so, then we know it's something that just affects preference items either on new document or app restart. It probably just works on restart. And, unfortunately this may be the end of the road for Ai scripting because it may be one of those things that is quite limited in our world. You may still be able to automate this portion somehow by using various macro apps on the market, AppleScript & VBS with their ability to send keys and tab to various UI controls, or AutoHotKey for Windows which can send keys as well as find image areas on screen and click in any particular spot you wish.

Likes

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
Explorer ,
Dec 20, 2021 Dec 20, 2021

Copy link to clipboard

Copied

Thank you, I already using Autohotkey to change grid spacing.

 

 

#NoEnv
#NoTrayIcon
#Persistent
SendMode Input
#SingleInstance Force
Process Priority,,High
SetControlDelay 1
SetWinDelay 0
SetKeyDelay -1
SetMouseDelay -1
SetBatchLines -1

OnMessage(0x204, "WM_RBUTTONDOWN")
OnMessage(0x201, "WM_LBUTTONDOWN")
OnMessage(0x200, "MOUSEOVER")
OnMessage(0x2A2, "MOUSELEAVE")

#IfWinActive ahk_class illustrator

  Screen_X := % (A_ScreenWidth / 2)-100
  Gui, +AlwaysOnTop -Caption +ToolWindow
  Fsize = w200 h10 ; Gui Frame size

  Gosub, GRID_GUI_ON
  Return

  ~F1 & D:: ; Grid Change <<------------------| Hotkey

  GRID_GUI_ON:
    WinActivate, ahk_class illustrator
    Send, {Control Down}{Alt Down}{g}{Alt Up}{Control Up} ;<<------------------| Hotkey for "Guides & Grid"
    WinWait, Preferences ahk_exe Illustrator.exe, , 1

    WinActivate, Preferences ahk_exe Illustrator.exe
    Sleep, 25
    IfWinActive, Preferences ahk_exe Illustrator.exe
    {
      WinSet, Transparent, 125, Preferences ahk_exe Illustrator.exe
      blockinput, on ; Disable Mouse And Keyboard
      ControlGetText, gridSpace, Edit2, Preferences ahk_exe Illustrator.exe
      gridSpace := StrSplit(gridSpace, A_Space, "") ; Omits periods.

      if (gridSpace[1] == 12.5)
      {
        spacing := 25
        Gui, Color, FFE000 ;BG Color
        Var1:=spacing
        Gosub, Send_Tooltip
      }
      else if (gridSpace[1] == 25)
      {
        spacing := 50
        Gui, Color, 00FF97 ;BG Color
        Var1:=spacing
        Gosub, Send_Tooltip
      }
      else if (gridSpace[1] == 50)
      {
        spacing := 12.5
        Gui, Color, ff2400 ;BG Color
        Var1:=spacing
        Gosub, Send_Tooltip
      }
      else
      {
        spacing := 12.5
      }
      ControlSetText, Edit2, %spacing%, Preferences ahk_exe Illustrator.exe
      Send, {Enter}
      blockinput,off ; Enable Mouse And Keyboard
    }

    Gui, Show, x%Screen_X% y0 %Fsize%, GRID_GUI
    WinActivate, ahk_class illustrator
  Return

  Send_Tooltip:
    SetTimer, Read_Tooltip, 1
    SetTimer, off_tooltips, 1400 ;Tooltip - ის ჩვენების დრო
    blockinput,off ; Enable Mouse And Keyboard
  Return

  Read_Tooltip:
    Tooltip,% Var1
  return

  off_tooltips:
    SetTimer, Read_Tooltip, Off
    SetTimer, off_tooltips, Off
    ToolTip
  return

  WM_RBUTTONDOWN()
  {
  Exitapp
}
Return

WM_LBUTTONDOWN()
{
  reload
}
Return

MOUSEOVER(){
  ToolTip, F1 & 😧 Change grid spacing.
  SetTimer, RemoveToolTip, -200
  return

}

MOUSELEAVE(){
  Gosub, off_tooltips
}

RemoveToolTip:
  ToolTip
return

 

 

Likes

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
Adobe Community Professional ,
Dec 20, 2021 Dec 20, 2021

Copy link to clipboard

Copied

LATEST

Thank you for sharing your AHK solution!

Likes

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