Skip to main content
Participant
January 6, 2018
Answered

How can I give text variables names to artboard names?

  • January 6, 2018
  • 2 replies
  • 5872 views

I am currently trying to learn to script, am quite at the beginning. And I am wondering how to access the variables content, at the moment I only managed to access the variable?

Hope that makes sense.

Please advise.

Regards, Eva

This topic has been closed for replies.
Correct answer Silly-V

Or import a single-column text file directly with this:

#target illustrator

function RenameArtboardsFromText() {

    if (app.documents.length) {

        function getTextFile() {

            var fileType = ($.os.match("Windows")) ? "*.txt;*.csv;" : function(f) {

                return f instanceof Folder || (f instanceof File && f.displayName.match(/(\.txt|\.csv)$/i));

            };

            var textFile = File.openDialog("Choose a text file.", fileType);

            if (textFile != null) {

                return textFile;

            } else {

                alert("Canceled");

                return null;

            }

        };

        var textFile = getTextFile();

        if (textFile != null) {

            textFile.open('r');

            var namesArray = textFile.read().split("\n");

            textFile.close();

            var doc = app.activeDocument;

            for (var i = 0; i < namesArray.length; i++) {

                try {

                    var thisName = namesArray;

                    var thisItem = doc.artboards;

                    thisItem.name = thisName;

                } catch (e) {

                    // do nothing

                }

            }

            alert("Done with " + i + " names");

        }

    } else {

        alert("No AI document is open or no selection.");

    }

}

RenameArtboardsFromText();

2 replies

Participant
January 9, 2018

Silly-V, Not sure how I select the dataset. (it gets deselected when I run the script)

CarlosCanto , great question, I'm not sure, they both seam to contain my objects.

To give a bit more context, what I am trying to do is load a csv/txt into illustrator and assign each line to an artbord name. (there is more than one line and more than one artboard, hence the reason I need it automated )

Silly-V
Legend
January 9, 2018

It's: app.activeDocument.dataSets[0].display()

Likewise, you can put the variable data from the art objects, back into the xml data, by somehow changing the content of the art to go against what's in the current dataset and then using the dataSet.update() method.

Participant
January 6, 2018

Forgot to mention that my question is for Extended Java script

pixxxelschubser
Community Expert
Community Expert
January 6, 2018

Hi 0evelynaa0​,

for the beginning:

Re: Script access to dataset variables

Have fun