Copy link to clipboard
Copied
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
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
...Copy link to clipboard
Copied
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
Copy link to clipboard
Copied
Awesome! Yea this was exaclty what I was looking for really simple and straight forward.
Thanks man!
Find more inspiration, events, and resources on the new Adobe Community
Explore Now