Quantcast
Channel: Adobe Community : Popular Discussions - Illustrator Scripting
Viewing all articles
Browse latest Browse all 12845

Help! I need somebody! Help!

$
0
0

I'm new to scripting for adobe programs and I'm less new to javascript. I've got this bit of code from user moluapple - he was incredibly helpful in getting me started. But I'm having trouble understanding the code. I don't know which parts do what and I'm having trouble finding definitions of terms online - is there a disconnect between scripting for adobe and regular javascripting?

 

The code works to collect fonts in an open Illustrator document. The issue I am having is that it only collects one font. Or sometimes it will collect a whole font family. But I haven't been able to get it to collect all of the fonts in the document.

 

I was hoping someone could put their finger on what I'm doing wrong. And help me understand how the code works.

 

Any help is much apreciated. I do know that I'm asking a huge favor.

 

 

-----------------------------------------

 

 

function getUsedFonts (doc){

     var xmlString = new XML(doc.XMPString),

     fontFamily = xmlString.descendants("stFnt:fontFamily"),

     fontFace = xmlString.descendants("stFnt:fontFace"),

     ln = fontFace.length(), i = 0, arr = [];

     for (; i<ln; i++){arr.push(fontFamily[i] + '\t' + fontFace[i])};

     return arr;

}

alert(getUsedFonts(activeDocument));

 

function main() {

          var

                    doc = app.activeDocument,

                    docPath = doc.path,

                    arr = getUsedFonts (doc),

                    oFolder = new Folder(docPath + '/DocumentFonts'),

                    btMsg,

                    PackageFonts = function (string, oFolder) {

                              var arr = string.split(','), oPath, oFile, oName, i;

                              for (i=0; i<arr.length; i++){

                                        oPath = app.fonts.itemByName(arr[i]).location;

                                        oFile = File(oPath);

                                        oName = oFolder + '/' + arr[i].replace ('          ', ' ').replace(' Regular', '') +

                                                  oPath.substring(oPath.lastIndexOf('.'), oPath.length);

                                        oFile.copy(File(oName), true);

                              }

                    };

          oFolder.create();

          btMsg = new BridgeTalk();

          btMsg.target = "indesign";

          btMsg.body = PackageFonts.toSource() + '("' + arr +'", "' + oFolder + '")';

          btMsg.onResult = function (resultMsg) {

                    $.writeln("Result = " + resultMsg.body);

          }

          btMsg.onError = function (errorMsg) {

                    $.writeln("Error = " + errorMsg.body);

          }

          btMsg.send();

}

 

 

main();


Viewing all articles
Browse latest Browse all 12845

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>