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
Silly-VCorrect answer
Legend
January 10, 2018

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();

Participant
January 13, 2018

Thank you,

Indeed it does everything all in one so I chose this answer being the most comprehensive as the best because it does what I am trying to accomplish, though I realize my first question was not worded like that.

By the way for importing the variables I was also using one of your scripts

Quite a life saver.

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