Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var docRef = app.activeDocument;
- var c = 0; // nombre de path
- while(true){
- try{
- docRef.layers[0].pathItems[++c];
- }catch(e){
- break;
- }
- }
- var pathPoints = [];
- var toWrite = [];
- toWrite.lenght = 0;
- for(i = 0; i < c; i++){//go though each path and get it's path points
- pathPoints.push(docRef.pathItems[i].pathPoints);
- fillLenght (pathPoints[i]);
- }
- for(i = 0; i < c; i++){
- var shape = {'r':0.0, 'g':0.0,'b':0.0,'points':[]};
- shape.points.lenght = 0;
- var color = docRef.pathItems[i].fillColor;
- if(color.typename === "CMYKColor"){ //convert CMYK color to RGB
- cyan = color.cyan / 100;
- m = color.magenta / 100;
- y = color.yellow / 100;
- k = color.black / 100;
- //r = 1 - Math.min( 1, cyan * ( 1 - k ) + k );
- //g = 1 - Math.min( 1, m * ( 1 - k ) + k );
- //b = 1 - Math.min( 1, y * ( 1 - k ) + k );
- r = 255 * (1-cyan) * (1-k);
- g = 255 * (1-m) * (1-k);
- b = 255 * (1-y) * (1-k);
- r = Math.round(r);
- g = Math.round(g);
- b = Math.round(b);
- shape.r = r;
- shape.g = g;
- shape.b = b;
- }else{
- shape.r = color.r;
- shape.g = color.g;
- shape.b = color.b;
- }
- for(k = 0; k < pathPoints[i].lenght; k++){
- var n = {
- 'x':0.0, 'y':0.0
- };
- n.x = pathPoints[i][k].anchor[0] / docRef.width
- n.y = pathPoints[i][k].anchor[1] / docRef.height;
- shape.points.push(n);
- shape.points.lenght++;
- }
- toWrite.push(shape);
- toWrite.lenght++;
- }
- str = '';//encoding
- for(i = 0; i < toWrite.lenght; i++){
- str += toWrite[i].r + ':' + toWrite[i].g + ':' + toWrite[i].b + 'a';
- for(k = 0; k < toWrite[i].points.lenght; k++){
- str += toWrite[i].points[k].x + '!' + toWrite[i].points[k].y;
- if(k != toWrite[i].points.lenght -1){
- str += '}';
- }
- }
- if(i != toWrite.lenght -1){
- str += '*';
- }
- }
- str += '$';
- var points = docRef.layers[1].pathItems[0].pathPoints;
- fillLenght(points);
- for(i = 0; i < points.lenght; i++){
- var x = points[i].anchor[0] / docRef.width;
- var y = points[i].anchor[1] / docRef.height;
- str += x + '!' + y;
- if(i != points.lenght -1)
- str += '}';
- }
- var destFolder = null;//save to disk
- destFolder = Folder.selectDialog('Select the directory to save the file.', 'D:\\unity\\testing\\Shaders\\Assets\\Resources');
- if(destFolder != null){
- var reportFile = new File(destFolder + '/Icon.txt');
- reportFile.open('w');
- reportFile.writeln(str);
- reportFile.close();
- alert('done');
- }
- function fillLenght(points){
- var c = 0;
- while(true){
- try{
- points[++c].anchor[0];
- }catch(e){
- points.lenght = c;
- break;
- }
- }
- }
- function getColorRGB(color){
- if(color.typename === "CMYKColor"){
- c = color.cyan / 100;
- m = color.magenta / 100;
- y = color.yellow / 100;
- k = color.black / 100;
- r = 1 - Math.min( 1, c * ( 1 - k ) + k );
- g = 1 - Math.min( 1, m * ( 1 - k ) + k );
- b = 1 - Math.min( 1, y * ( 1 - k ) + k );
- r = Math.round(r * 255 );
- g = Math.round(g * 255 );
- b = Math.round(b * 255 );
- alert('color :' + r + ':' + g + ':' + b);
- return {'r' : r, 'g':g, 'b' : b};
- }else if(color.typename === "RGBColor") {
- return color;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement