Copy link to clipboard
Copied
I wonder how to pass information from one script to another
(or save somewhere information).
I have one script where I enter information such as height, width etc.
and later I want to run a second script that would read the same information I have already entered.
For now, the only idea I have is to create a text frame and read information from it
The most basic way is to simply write a text file and have your 2nd script always check for this text file.
Writing a text file is easy!
Check this out:
function writeFile(dest, contents){
var f = File(dest);
f.open('w');
f.write(contents);
f.close();
};
Copy link to clipboard
Copied
The most basic way is to simply write a text file and have your 2nd script always check for this text file.
Writing a text file is easy!
Check this out:
function writeFile(dest, contents){
var f = File(dest);
f.open('w');
f.write(contents);
f.close();
};
Copy link to clipboard
Copied
Thanks!
Now I have a problem with reading all lines. And how can I choose which lines I want to load?
#target illustrator
var f = new File('~/Desktop/file.txt');
alert(readFile(f));
function readFile(f) {
f.open('r');
var line = f.readln();
f.close();
return line;
}
My txt file looks like this:
line1
line2
;ine3
line4
... etc.
Copy link to clipboard
Copied
You can read all the text and do what I do which is create an array by doing var myArray = myTextContent.split(/[\r\n]/g) via that regular expression.
Now you can reference each line like this : var myLine_4 = myArray[3];
Copy link to clipboard
Copied
Please Help me, i gets the answer: "undefined".
#target illustrator
var f =File.openDialog ("open file ");
alert(readFile(f));
function readFile(f) {
f.open('r');
var line = f.readln();
var myArray = line.split(/[\r\n]/g);
var myLine = myArray[3];
f.close();
return myLine ;
}
Copy link to clipboard
Copied
try this:
function readArrayFromFile(src){
var f = File(dest);
f.open('r');
var contents = f.read();
f.close();
var allRowsArray = contents.split(/[\r\n]/g);
return allRowsArray;
};
Copy link to clipboard
Copied
Thank you,
now it works