Forked from dfred23/creating obj files from adobe illustrator for Trapcode Form (FIXED)
Created
May 8, 2012 06:37
-
-
Save ff6347/2633068 to your computer and use it in GitHub Desktop.
creating obj files from adobe illustrator for Trapcode Form (FIXED)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 = "" + (sel.pathPoints[i].anchor[0].toFixed(3)) +" " +(sel.pathPoints[i].anchor[1].toFixed(3)) + " 0.0\r\n"; | |
coords.push("" + (sel.pathPoints[i].anchor[0].toFixed(3)) +" " +(sel.pathPoints[i].anchor[1].toFixed(3)) + " 0.0"); | |
// list.push(sel.pathPoints[0].anchor); | |
} | |
} | |
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"; | |
txtFile.lineFeed = "Unix"; //convert to UNIX linefeed | |
var openString = "# WaveFront *.obj file (generated by Adobe Illustrator)\n\n"; | |
var groupName = "g " + app.activeDocument.name; | |
txtFile.writeln(openString + groupName); | |
arr.sort(sortfunc); //must sort vertices to get rid of errant vertex at the end | |
} | |
if( out != false ) | |
{ | |
for(var i in arr){ | |
txtFile.writeln("v " + arr[i] ); | |
} | |
txtFile.writeln("v 0 0 0"); | |
txtFile.close(); | |
// txtFile.execute(); | |
} | |
} | |
function sortfunc(a,b) | |
{ | |
return a - b; | |
} | |
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