Skip to content

Instantly share code, notes, and snippets.

@ff6347
Created March 19, 2012 08:41
Show Gist options
  • Save ff6347/2103355 to your computer and use it in GitHub Desktop.
Save ff6347/2103355 to your computer and use it in GitHub Desktop.
creating obj files from adobe illustrator for TRapcode Form !NOT WORKING RIGHT
main();
function main(){
var list = new Array();
var doc = app.activeDocument;
var str = "";
var coords = new Array();
var ab = doc.artboards[0];
// ab.rulerOrigin = [0 , 0];
for(var j in doc.selection){
var sel = doc.selection[j];
for(var i = 0; i < sel.pathPoints.length;i++){
str = str + "v "+ (sel.pathPoints[i].anchor[0].toFixed(3)) +" " +(sel.pathPoints[i].anchor[1].toFixed(3)) + " 0.0\r\n";
coords.push("v "+ (sel.pathPoints[i].anchor[0].toFixed(3)) +" " +(sel.pathPoints[i].anchor[1].toFixed(3)) + " 0.0");
// list.push(sel.pathPoints[0].anchor);
}
}
str+="v 0 0 0\r\n";
coords.push("v 0 0 0");
var newLocation = Folder.selectDialog("Select a output folder...");
var timestamp = Number(new Date());
var fn = "file "+ timestamp;// prompt("Enter target file name","myObjFile");
var tf = newLocation.fsName;
var txtFile = new File( tf+"/" + fn + ".obj" );
// alert(list);
writeArray(txtFile, coords);
// writeData (txtFile , str );
alert("wrote: " + fn + ".obj\nto folder: " + tf);
}
function writeArray (txtFile , arr )
{
var out;
if( txtFile!='' )
{
//Open the file for writing.
out = txtFile.open( 'e', undefined, undefined );
txtFile.encoding = "UTF-8";
}
if( out != false )
{
txtFile.seek(0);
for(var i in arr){
txtFile.write((arr[i]) + "\r\n");
}
txtFile.close();
// txtFile.execute();
}
}
function writeData (txtFile , aData )
{
var out;
if( txtFile!='' )
{
//Open the file for writing.
out = txtFile.open( 'e', undefined, undefined );
}
if( out != false )
{
txtFile.seek(0);
txtFile.writeln( aData );
txtFile.close();
// txtFile.execute();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment