Skip to main content
Participant
Feb 28, 2024 4:48 PM UTC
Answered

Random letters and numbers mixing position in grid

Hi, I use Illustrator to create worksheets for my students in preschool. I'm searching for tool or scrypt that allow me random mix postition of objects (letters, number). I have grid under those objects, and I wish that after mixing objects they stay in the middle of grid. Am I only dreaming that something like that exsist? Help ❤️

This topic is closed to new replies. Start a new post to keep the conversation going.
femkeblanco
femkeblancoCorrect answer
Legend
Feb 28, 2024 6:11 PM UTC

 

// select text frames
var doc = app.activeDocument;
var contents = [];
for (var i = 0; i < doc.selection.length; i++) {
    contents.push(doc.selection[i].contents);
}
for (var i = 0; i < doc.selection.length; i++) {
    var index = Math.floor(Math.random() * contents.length);
    doc.selection[i].contents = contents[index];
    contents.splice(index, 1);
}

 

6 replies

femkeblanco
femkeblancoCorrect answer
Legend
Feb 28, 2024 6:11 PM UTC

 

// select text frames
var doc = app.activeDocument;
var contents = [];
for (var i = 0; i < doc.selection.length; i++) {
    contents.push(doc.selection[i].contents);
}
for (var i = 0; i < doc.selection.length; i++) {
    var index = Math.floor(Math.random() * contents.length);
    doc.selection[i].contents = contents[index];
    contents.splice(index, 1);
}

 

Translate
Participant
Feb 28, 2024 6:24 PM UTC

Thank you! I'll check them ! It took me so much precious time to prepare something for my kiddos.Tons of 💕

Translate
Kurt Gold
Community Expert
Community Expert
Feb 28, 2024 6:03 PM UTC

There are scripts. One is provided by sky-chaser-high.

 

Shuffle Objects

Translate
RobOctopus
Inspiring
Feb 28, 2024 5:04 PM UTC

While I am certain something could be created via scripting, if I'm understanding your ask correctly a similar effect can be achieved using native tools like area type options and text margins.

  1. Create your underlying grid
  2. Create a large Area Type Frame to cover the grid
  3. Edit the Area type options so that the Rows/Columns match the grid
  4. then get the Margins to push in and left to align

Here is a 50mm x 50mm grid that is ultimately a single text frame with a string of letters/numbers that flow from 1 box to the next. you could simply retype whatever you wish or copy/paste a string into the text frame and each character would flow into the next box in line

Translate
Participant
Feb 28, 2024 5:38 PM UTC

Thank you for replay. Now it's easier to prepare grid with numbers/letters. The thing is I wish I could change/mix it somehow, so they randomly change their places, mix in those 5 rows and 5 columns. Sorry, I don't know how to explain it properly O_O I have 'randomus' script, but it only change properities not places ;( 

Translate
RobOctopus
Inspiring
Feb 28, 2024 6:06 PM UTC

using the above method I've outlined. here's a script to randomise the text thats currently in the frame. 

if(app.activeDocument.selection.length==1 && app.activeDocument.selection[0].typename=="TextFrame"){
    var StartContents = app.activeDocument.selection[0].contents
    var ShuffledContents = shuffleArray(StartContents)
    app.activeDocument.selection[0].contents = ShuffledContents
} else {
    alert("Whoops!\nPlease select a text frame and try again.")
}

function shuffleArray(Arr) {
    if(typeof Arr=="string")Arr = Arr.split("")
    for (var i = Arr.length - 1; i > 0; i--) {
        var j = Math.floor(Math.random() * (i + 1));
        var temp = Arr[i];
        Arr[i] = Arr[j];
        Arr[j] = temp;
    }
    return Arr.join("")
}

it will only work on a single text frame

it will take the contents of the text frame, in this case a string of numbers or letters, and randomise them amongst themselves and then set that text frame's contents to the new randomised string.

Translate