일러스트 스크립트
일러스트레이터 스크립트에서 파일 읽기, 쓰기
illustscript
2024. 7. 24. 10:10
일러스트레이터 스크립트에서 파일 읽기, 쓰기
// 004_setterGetter.jsx
// https://illustscript.tistory.com
var mm = 2.83464566929134;
var title = "setterGetter";
var noColor = new NoColor();
var myRed = new CMYKColor();
myRed.black = 0;
myRed.cyan = 0;
myRed.magenta = 100;
myRed.yellow = 100;
var docRef = activeDocument;
drawRectFromSavedData();
function drawRectFromSavedData(){
var X = 30*mm;
var Y = -30*mm;
var myWidth = getUserOption();
if(myWidth==false){
myWidth = 10;
}
var myWidth = (prompt ("정사각형을 그립니다.\n한 변의 길이가 얼마인가요?(단위 : mm)", myWidth, title));
if(myWidth){
setUserOption(myWidth);
myWidth = myWidth * mm;
drawRect(X, Y, myWidth, myWidth);
}
}
function drawRect(X, Y, W, H){
var rect = docRef.pathItems.rectangle(Y, X, W, H);
rect.fillColor = noColor;
rect.stroked = true;
rect.strokeWidth = 2*mm;
rect.strokeColor = myRed;
}
function getUserOption(){
var configFilePath = $.getenv("APPDATA")+"\\Adobe\\" //C:\Users\(사용자 이름)\AppData\Roaming\Adobe
var configFileName = "setterGetter.txt"
fd = new Folder(configFilePath);
//폴더가 없는 경우
if(!fd.exists){
return false;
}
//폴더가 있는 경우
else{
file = new File(configFilePath+configFileName);
//파일이 있는 경우
if(file.exists){
// 파일을 읽기모드로 열어서 값을 가져온다.
file.open("r");
var configVal = file.readln();
file.close();
return configVal;
}
//파일이 없는 경우
else{
return false;
}
}
}
function setUserOption(_width){
var configFilePath = $.getenv("APPDATA")+"\\Adobe\\" //C:\Users\(사용자 이름)\AppData\Roaming\Adobe
var configFileName = "setterGetter.txt"
fd = new Folder(configFilePath);
//폴더가 없는 경우, 폴더 생성
if(!fd.exists){
fd.create();
}
file = new File(configFilePath+configFileName);
//파일을 쓰기모드로 열어서 값을 덮어씌운다.
file.open("w+");
file.write(_width);
file.close();
}
결과