Skip to main content
Participant
June 26, 2023
Question

How to Make Repeat grid in Illustrator using extendscript

  • June 26, 2023
  • 2 replies
  • 937 views

Hi, 

Can anyone let me know how to make repeat grid in illustraor using Extendscript? Please provide me the extendscript code to make repeat grid.

Thank You..!! 

This topic has been closed for replies.

2 replies

Legend
June 27, 2023
There is a scripting API for the repeat grid, but probably no one has seen it working correctly. Just a null pointer waiting for you.

However, repeat grid spacing, flipping, etc. are under the control of preferences and can be handled with setRealPreference, and so on.

 

/**
  * @File make repeat grid from selection
  * @version 1.0.0
  * @7111211 sttk3.com
  * @7340357 © 2023 sttk3.com
*/

(function() {
  if(app.documents.length <= 0) {return ;}
  var doc = app.documents[0] ;
  var sel = doc.selection ;
  if(sel.length <= 0) {return ;}

  // define repeat grid pattern types value
  var GridPatternTypes = {
    'GRID': 0, 
    'BRICK_BY_ROW': 1, 
    'BRICK_BY_COLUMN': 2
  } ;
  
  // define preference keys
  var pref = app.preferences ;
  var keyHorizontalSpacing = 'plugin/Adobe Repeat Arts UI/HorizontalSpacing' ;
  var keyVerticalSpacing = 'plugin/Adobe Repeat Arts UI/VerticalSpacing' ;
  var keyGridPatternType = 'plugin/Adobe Repeat Arts UI/GridPatternType' ;
  var keyFlipRowHorizontal = 'plugin/Adobe Repeat Arts UI/FlipRowY' ;
  var keyFlipRowVertical = 'plugin/Adobe Repeat Arts UI/FlipRowX' ;
  var keyFlipColumnHorizontal = 'plugin/Adobe Repeat Arts UI/FlipColumnY' ;
  var keyFlipColumnVertical = 'plugin/Adobe Repeat Arts UI/FlipColumnX' ;

  var oldHorizontalSpacing, oldVerticalSpacing, oldGridPatternType, oldFlipRowHorizontal, oldFlipRowVertical, oldFlipColumnHorizontal, oldFlipColumnVertical ;
  try {
    // store original settings
    oldHorizontalSpacing = pref.getRealPreference(keyHorizontalSpacing) ;
    oldVerticalSpacing = pref.getRealPreference(keyVerticalSpacing) ;
    oldGridPatternType = pref.getIntegerPreference(keyGridPatternType) ;
    oldFlipRowHorizontal = pref.getBooleanPreference(keyFlipRowHorizontal) ;
    oldFlipRowVertical = pref.getBooleanPreference(keyFlipRowVertical) ;
    oldFlipColumnHorizontal = pref.getBooleanPreference(keyFlipColumnHorizontal) ;
    oldFlipColumnVertical = pref.getBooleanPreference(keyFlipColumnVertical) ;

    // set horizontal spacing
    pref.setRealPreference(keyHorizontalSpacing, 40.0) ;

    // set vertical spacing
    pref.setRealPreference(keyVerticalSpacing, 20.0) ;

    // set grid type
    pref.setIntegerPreference(keyGridPatternType, GridPatternTypes.GRID) ;
    
    // set flip rows
    pref.setBooleanPreference(keyFlipRowHorizontal, true) ;
    pref.setBooleanPreference(keyFlipRowVertical, false) ;

    // set flip column
    pref.setBooleanPreference(keyFlipColumnHorizontal, false) ;
    pref.setBooleanPreference(keyFlipColumnVertical, true) ;

    // make repeat grid from selection
    app.executeMenuCommand('Make Grid Repeat') ;
  } catch(e) {
    alert(e) ;
  } finally {
    // restore original settings
    pref.setRealPreference(keyHorizontalSpacing, oldHorizontalSpacing) ;
    pref.setRealPreference(keyVerticalSpacing, oldVerticalSpacing) ;
    pref.setIntegerPreference(keyGridPatternType, oldGridPatternType) ;
    pref.setBooleanPreference(keyFlipRowHorizontal, oldFlipRowHorizontal) ;
    pref.setBooleanPreference(keyFlipRowVertical, oldFlipRowVertical) ;
    pref.setBooleanPreference(keyFlipColumnHorizontal, oldFlipColumnHorizontal) ;
    pref.setBooleanPreference(keyFlipColumnVertical, oldFlipColumnVertical) ;
  }
})() ;

 

Sergey Osokin
Inspiring
June 26, 2023

There are no details about what you need to grid and what the settings should be. I will assume that the script will be sufficient for you: https://github.com/sky-chaser-high/adobe-illustrator-scripts/blob/main/scripts/stepAndRepeat.js

Participant
June 26, 2023

I Need a script to repeat the pattern, Like grid, mirror etc. I have one object as rectangle and want to repeat this rectangle in the document then,
Object->repeat-> grid, mirror etc.
Please provide me the extendscript for this.
Thank You..!!