Skip to main content
Known Participant
June 9, 2022
Answered

Import Artboard names from list (csv file)?

  • June 9, 2022
  • 2 replies
  • 1452 views

Are there any scripts or workarounds for importing a list of names to automatically update the Artboard names to match?

This topic has been closed for replies.
Correct answer hammer0909

It is possible via a script but most of the users in this forum are not scripting. Here's a post in the scripting forum that discusses your topic in more detail. I hope it helps. https://community.adobe.com/t5/illustrator-discussions/script-to-import-csv-file-to-create-artboards-with-name-and-size/td-p/10440630

2 replies

Known Participant
April 8, 2023

I have a related question - Is there a way, or a script, to export the list of artboard names?

CarlosCanto
Community Expert
April 8, 2023

here you go, open a document before running the script

text file will be saved to the desktop

 

 

// write Artboard names to text file
// CarlosCanto 4/8/23
// https://community.adobe.com/t5/illustrator-discussions/import-artboard-names-from-list-csv-file/td-p/12994650

function main() {
    var abnames = getArtboardNames ();
    
    var f = File('~/Desktop/artboardNames.txt');
    
    writeToText (abnames.join("\n"), f);
}

main();

function getArtboardNames (names) {
    var idoc = app.activeDocument;
    var abnames = [];
    
    for (a=0; a<idoc.artboards.length; a++) {
        abnames.push(idoc.artboards[a].name);
    }

    return abnames;
}

function writeToText (str, f) {
    f.open('w');
    f.write(str);
    f.close();
}

 

 

Sergey Osokin
Inspiring
April 10, 2023

I made such a script too. But I also added two actions via boolean variable: either save names to txt file or read and rename from it. I also added an artboard index counter to start collecting names. I needed this to collect the names of new artboards in one document and also to rename only part of the artboards in another document.

 

 

 

// write or read Artboard names to text file
// CarlosCanto 4/8/23
// Modification: Sergey Osokin 4/11/23
// https://community.adobe.com/t5/illustrator-discussions/import-artboard-names-from-list-csv-file/td-p/12994650

function main() {
  var isSave = true; // Save or load artboard names to doc
  var startIdx = 0; // Save names starting from the index (first index = 0)
  var f = File(Folder.desktop + '/artboardNames.txt');

  if (!/illustrator/i.test(app.name)) {
    alert('Wrong application\nRun script from Adobe Illustrator', 'Script error');
    return false;
  }

  if (!documents.length) {
    alert('No documents\nOpen a document and try again', 'Script error');
    return false;
  }

  var doc = app.activeDocument;

  var win = new Window('dialog', 'Artboard Names to TXT');
  win.alignChildren = ['fill','top'];

  var actionGrp = win.add('group');
  actionGrp.alignChildren = ['left', 'center'];
  var saveRb = actionGrp.add('radiobutton', undefined, 'Save to file');
  saveRb.value = isSave;
  var applyRb = actionGrp.add('radiobutton', undefined, 'Apply from file');
  applyRb.value = !isSave;
  
  var idxGrp = win.add('group');
  idxGrp.alignChildren = ['left', 'center'];
  idxGrp.add('statictext', undefined, 'Start index (first is 0):');
  var idxInp = idxGrp.add('edittext', undefined, startIdx);
  idxInp.characters = 6;

  win.add('statictext', undefined, decodeURI(f));

  // Buttons
  var btns = win.add('group');
      btns.alignChildren = ['fill', 'center'];

  var cancel = btns.add('button', undefined, 'Cancel', { name: 'cancel' });
      cancel.helpTip = 'Press Esc to Close';

  var ok = btns.add('button', undefined, 'OK', { name: 'ok' });
      ok.helpTip = 'Press Enter to Run';

  cancel.onClick = win.close;

  ok.onClick = function () {
    startIdx = parseInt(idxInp.text);
    if (isNaN(startIdx)) startIdx = 0;

    if (saveRb.value) {
      var abNames = getArtboardNames(doc, startIdx);
      if (abNames.length) writeToText(abNames.join("\n"), f);
    } else {
      var fNames = parseFromText(f);
      if (fNames.length) renameArtboards(doc, fNames, startIdx);
    }
    win.close();
  }

  win.center();
  win.show();
}

main();

function getArtboardNames(doc, idx) {
  if (idx >= doc.artboards.length) return '';
  var abNames = [];
  for (var i = idx; i < doc.artboards.length; i++) {
    abNames.push(doc.artboards[i].name);
  }
  return abNames;
}

function writeToText(str, f) {
  f.open('w');
  f.write(str);
  f.close();
}

function parseFromText(f) {
  f.open('r');
  var contents = f.read();
  var lines = contents.split('\n');
  f.close();
  return lines;
}

function renameArtboards(doc, names, idx) {
  var str = '';
  for (var i = idx; i < doc.artboards.length; i++) {
    str = names[i - idx];
    if (!str) break;
    doc.artboards[i].name = str;
  }
}

 

 

 

hammer0909
hammer0909Correct answer
Community Expert
June 9, 2022

It is possible via a script but most of the users in this forum are not scripting. Here's a post in the scripting forum that discusses your topic in more detail. I hope it helps. https://community.adobe.com/t5/illustrator-discussions/script-to-import-csv-file-to-create-artboards-with-name-and-size/td-p/10440630

Jenny867Author
Known Participant
June 9, 2022

Thanks!