6 Replies Latest reply on Apr 29, 2013 8:38 AM by Paulo Jorge Carvalho

    Create charater based on a txt file

    Paulo Jorge Carvalho

      Y have a text file separeted by tabs with the definitions of the charater style that y want to create, but in some font name it gets error (example Lucida Math Std and Frutiger LT Std.

      The file was exported by the same way, so y don't undestand why. can someone help me pleeeeeaaaase!!!


      Here's the file:


      Horizontal ScaleVertical ScaleCor% de CorBaseline ShiftLinguagemBasedo em
      vverbete.lexeger.exeger.tbregHelvetica LT StdLight Condensed100100C=0 M=70 Y=0 K=01000Portuguese: Orthographic Agreement[None]
      efaux3Helvetica LT StdRoman100100C=100 M=0 Y=0 K=601000Portuguese: Orthographic Agreement[None]
      efaux4Lucida Math StdSymbol100100C=20 M=100 Y=50 K=01000Portuguese: Orthographic Agreement[None]
      vverbete.divisao.catgram.aceps.numITC Novarese StdBold100100C=0 M=100 Y=100 K=01000Portuguese: Orthographic Agreement[None]
      vverbete.divisao.catgram.aceps.subacep.traduz.trad_iFrutiger LT Std46 Light Italic100100C=100 M=0 Y=0 K=201000Portuguese: Orthographic Agreement[None]
      vverbete.divisao.catgram.aceps.subacep.traduz.trad_ibFrutiger LT Std66 Bold Italic100100C=100 M=0 Y=0 K=501000Portuguese: Orthographic Agreement[None]



      Here's the script:




      function main(){

                var myObject;

                //Make certain that user interaction (display of dialogs, etc.) is turned on.

                app.scriptPreferences.userInteractionLevel = UserInteractionLevels.interactWithAll;

                if(app.documents.length > 0){




                          alert("Não existem documentos abertos. Abra o documento pretendido e corra o script de novo.");




      function myCreateStyles(myObject){

                var myScriptFileName, myCharFile, myFindChangeFileName, myScriptFile, myResult;

                var myFindChangeArray, myFindPreferences, myChangePreferences, myFindLimit, myStory;

                var myStartCharacter, myEndCharacter;

                var myCharFile = myFindFile("/FindChangeSupport/FindChangeList.txt")

          var i = 0;



                if(myCharFile != null){

              myCharFile = File(myCharFile);

              var myDoc = app.documents[0];

              var myResult = myCharFile.open("r", undefined, undefined);



          if(myResult == true){

                 //determina o número de  estilos a criar a alterar

                 var myCharStyles = new Array();


                      myFindArray = myCharFile.readln();



                  while(myCharFile.eof == false);

                  var charStylesLenght = myCharStyles.length;


        // cria estilo a lingua dos estilos de carater

                for (oneStyle=1;oneStyle<charStylesLenght;oneStyle++){

              var myCharacterStyle = new Array();

              myCharStyleProp = myCharStyles[oneStyle].split("\t");


              var myCharStyleName = myCharStyleProp[0];

              var myCharStyleFont = myCharStyleProp[1];

              var myCharStyleFontStyle = myCharStyleProp[2];

              myCharacterStyle = myDoc.characterStyles.add();

              myCharacterStyle.name = myCharStyleName;

              myCharacterStyle.fontStyle = myCharStyleFontStyle;

              myCharacterStyle.appliedFont = myCharStyleFont;


                                    alert ("Foram criados os estilos de carater.");




      function myFindFile(myFilePath){

                var myScriptFile = myGetScriptPath();

                var myScriptFile = File(myScriptFile);

                var myScriptFolder = myScriptFile.path;

                myFilePath = myScriptFolder + myFilePath;

                if(File(myFilePath).exists == false){

                          myFilePath = File.openDialog("Selecione o documento .txt com as palavras a alterar.");


                return myFilePath;


      function myGetScriptPath(){


                          myFile = app.activeScript;



                          myFile = myError.fileName;


                return myFile;


        • 1. Re: Create charater based on a txt file
          Vamitul Level 4

          Hello Paulo!


          First a qustion: what error do you recive?

          Second, a littel experiment, not very sure it will help, but still try it: switch the lines


          myCharacterStyle.fontStyle = myCharStyleFontStyle;

          myCharacterStyle.appliedFont = myCharStyleFont;


          between them

          so first apply the font, and then the font style, like this:


          myCharacterStyle.appliedFont = myCharStyleFont;

          myCharacterStyle.fontStyle = myCharStyleFontStyle;




          or, even better, replace the two lines with this (but please try the first solution first and tell me if it works.. i'm curious):



          • 2. Re: Create charater based on a txt file
            Paulo Jorge Carvalho Level 1

            I've tried all but none worked.


            The error that i get is that the requested font family is not available, but i got the font name by the following lines.


            var myAppliedFont = myCharStyles[oneStyle].appliedFont;

            var myFontStyle = myCharStyles[oneStyle].fontStyle;


            var name2 = myName + "\t" + myAppliedFont + "\t" + myFontStyle + "\t" + myHScale + "\t" + myVScale + "\t" + myColorName + "\t" + myTint + "\t" + myBaselineShift + "\t" + myAppliedLanguage + "\t" + myBasedOn;

            myData = name2 + "\r";

            f.writeln( myData ); 


            Thats what i don't understand.

            The font is available but, when importing the file that was exported by script i get error in some fonts, and the font name is exactly as used in indesign.

            • 3. Re: Create charater based on a txt file
              Vamitul Level 4

              well i got some good news and some bad ones.


              The good one: The script is ok.

              The bad one: The problem is the OS or Indesign or FontManagent.


              Make sure you have the fonts properly installed on your sistem before running the script (starting indesign AFTER the fonts have been installed might help also). If you are using Extensis Suitcase for font management.. well i'm tempted to say uninstall it, throw away the installation CD etc, but i know it's usefull form time to time, so.. just make sure all the neded fonts are activated, and try again.

              • 4. Re: Create charater based on a txt file
                Paulo Jorge Carvalho Level 1

                Thanks for the quick answer.

                I use Universal Type Client with Universal Type Server (the server version of Extensis Suitcase or Suitcase Fusion).

                I will try to deactivate the UTC Core and place the fonts in a Font's folder in the same level of the Indesign file.


                hope it works. i will give you feed back, later.

                • 5. Re: Create charater based on a txt file
                  Vamitul Level 4

                  If it doesn't work, try putting the fonts in the OS's font folder (Windows\Fonts on MS Win or ~/Library/Fonts)

                  • 6. Re: Create charater based on a txt file
                    Paulo Jorge Carvalho Level 1

                    The good news is that it work's with the the fonts in the system folder.

                    The bad news is that i need UTC.


                    @Vanitul, Thank you so mutch for the tips.