Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Importing Text From A .txt File

Participant ,
Oct 17, 2013 Oct 17, 2013

Hey guys,

I'm looking for a way to import text from a .txt file but I'm totally lost. If someone could point me in the right direction that would be awesome

TOPICS
Scripting
1.1K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Advocate , Oct 17, 2013 Oct 17, 2013

Hi Prails
This script is basically what you asked:

#target illustrator

#targetengine main

function copyText(){

    var textFile = File.openDialog ("Select the file");

    if (! textFile.exists || app.documents.length==0){

        return;

    };

    textFile.open("r");

    var txtContent = textFile.read();

    textFile.close();

   

    var doc = app.activeDocument;

    var textItem = doc.textFrames.add();

    textItem.contents = txtContent   

};

copyText ();

Basically what you need to do is declare the text fi

...
Translate
Adobe
Advocate ,
Oct 17, 2013 Oct 17, 2013

Hi Prails
This script is basically what you asked:

#target illustrator

#targetengine main

function copyText(){

    var textFile = File.openDialog ("Select the file");

    if (! textFile.exists || app.documents.length==0){

        return;

    };

    textFile.open("r");

    var txtContent = textFile.read();

    textFile.close();

   

    var doc = app.activeDocument;

    var textItem = doc.textFrames.add();

    textItem.contents = txtContent   

};

copyText ();

Basically what you need to do is declare the text file, open it, read the content and close it. Then, you create a new text item in the Illustrator document and write the content once catched into the text item.

You could continue to work with the variable "textItem" in my example script if you want to set properties like the size, color of the text, position and so on. Also, if you want, replace the first line of the function var textFile = new File ("~/Desktop/Test.txt"); by var textFile = File.openDialog ("Select the file"); so the scripts opens a dialog to ask you the file you want the copy the content.

Hope to be helped

Best Regards

Gustavo

Message was edited by: Gustavo Del Vechio

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Oct 17, 2013 Oct 17, 2013
LATEST

Awesome! Yea this was exaclty what I was looking for really simple and straight forward.

Thanks man!

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines