9 Replies Latest reply on May 14, 2014 10:32 PM by hasvi

    Create 'Object Style' by script

    hasvi Level 1

      Hi,

       

      My 'Library.indl' file has the 'Box1', 'Box2'. I need to create the object style(with dummy properties) based on the Library file names.

      If the library has BOX1, BOX2, I need to check my Indesign file has Object Style with the same name(BOX1, BOX2).

      If object style not presented in that particular name(BOX1, BOX2) in Indesign, I have to create the dummy Object style. (The 'object style name' should match with BOX1, BOX2.)

      Is this possible by Indesign script?

       

      by

      hasvi

        • 1. Re: Create 'Object Style' by script
          Chinnadk Level 4

          Hi Hasi,

           

          Use the below code.

           

          var doc = app.activeDocument;

          var library=new File("C:/Library.indl");//Your library file path.

          app.open(library);

          asset = app.libraries[0].assets;

          for(var i=0;i<asset.length;i++)

          {

              try{

                  doc.objectStyles.add({name:asset[i].name});

                  }

              catch(e){}

              }

           

          Regards,

          Chinna

          • 2. Re: Create 'Object Style' by script
            hasvi Level 1

            Hi Chinna,

             

            Excellent job, thanks a lot.

             

            by

            Hasvi

            • 3. Re: Create 'Object Style' by script
              hasvi Level 1

              Hi Chinna,


              When I click 'hyphenation setting' on, I have the problems on line 54 and 55.

              • If I select line 55(line 54 is deselect). script working fine.
              • If I select line 54(line 55 is deselect) script is not working, but I want to select library file from the folder path, so I need line 54 action.

              Correct my script here:

               

              var w = new Window ("dialog", "Template Checklist", undefined, {closeButton: false});

              w.alignChildren = "left";

              var check1  = w.add ("checkbox", undefined, "Hyphenation Settings");

              var check2  = w.add ("checkbox", undefined, "Object Style creation based on Library");

              var buttons = w.add ("group");

              buttons.add ("button", undefined, "Ok");

              var Exit = 0;

              var cancel = buttons.add ("button", undefined, "Cancel")

                      cancel.onClick = function()

                      {

                              w.close();

                              Exit = 1;

                          }

              w.show ();

              if(Exit ==1)

              {

                      this.exit();

                  }

               

              var myDocument = app.activeDocument;

              if (check1.value == true)

              {

                  var myPara=app.activeDocument.paragraphStyles;

                  for(var i=1;i<myPara.length;i++)

                  {

                          if(myPara[i].hyphenation)

                          {

                          //myPara[i].hyphenation=true;

                          myPara[i].hyphenateWordsLongerThan=6;

                          myPara[i].hyphenateAfterFirst=3;

                          myPara[i].hyphenateBeforeLast=3;

                          myPara[i].hyphenateLadderLimit=2;

                          myPara[i].hyphenationZone="1p";

                          myPara[i].hyphenateCapitalizedWords=true;

                          myPara[i].hyphenateLastWord=false;

                          myPara[i].hyphenateAcrossColumns=false;

                          }

                  }

                  var myStyle=new Array("BK_TTL","BK_HTTL")

                  for(var i=0;i<myStyle.length;i++)

                  {

                          if(myDocument.paragraphStyles.item(myStyle[i]).isValid)

                          {

                           myDocument.paragraphStyles.item(myStyle[i]).hyphenation = false;

                          }

                      }

              }

              if (check2.value == true)

              alert("Library File is must for this process.");

              {

              //~ var library = File.openDialog ("Select the Library File", "*.indl");  ////Your library file path.

              var library=new File("C:\\Users\\Jayanthi\\Desktop\\Library.indl");//Your library file path.

              app.open(library);

              asset = app.libraries[0].assets;

              for(var i=0;i<asset.length;i++)

              {

                  try{

                      myDocument.objectStyles.add({name:asset[i].name});

                      }

                  catch(e){}

                  }

              }

               

               

              var ProgressBar = function(/*str*/title)

              {

                   var w = new Window('palette', ' '+title, {x:0, y:0, width:340, height:60}),

                        pb = w.add('progressbar', {x:20, y:12, width:300, height:12}, 0, 100),

                        st = w.add('statictext', {x:10, y:36, width:320, height:20}, '');

                   st.justify = 'center';

                   w.center();

                   this.reset = function(msg,maxValue)

                        {

                        st.text = msg;

                        pb.value = 0;

                        pb.maxvalue = maxValue||0;

                        pb.visible = !!maxValue;

                        w.show();

                        };

                   this.hit = function() {++pb.value;};

                   this.hide = function() {w.hide();};

                   this.close = function() {w.close();};

              };

              //------------------------------------------------

              //      SAMPLE CODE

              //------------------------------------------------

              function main()

              {

                   var pBar = new ProgressBar("Running");

                   var i;

                  

                   // Routine #1

                   pBar.reset("Please wait Processing ...", 100);

                   for( i=0 ; i < 100; ++i, pBar.hit() )

                        {

                        $.sleep(10);

                        }

                   // Routine #2

                   pBar.close();

                   }

              main();

              exit();

                 

               

               

              by

              hasvi

              • 4. Re: Create 'Object Style' by script
                hasvi Level 1

                Hi chinna,

                 

                For your information:

                Line 54: //~ var library = File.openDialog ("Select the Library File", "*.indl");  ////Your library file path.

                Line 55: var library=new File("C:\\Users\\Jayanthi\\Desktop\\Library.indl");//Your library file path.

                 

                by

                hasvi

                • 5. Re: Create 'Object Style' by script
                  Chinnadk Level 4

                  Hi Hasvi,

                   

                  The script working fine here with line number 54.

                  Did you close the library file before running the script? And could you show me what kind of errors your receiving?

                   

                  Regards,

                  Chinna

                  • 6. Re: Create 'Object Style' by script
                    hasvi Level 1

                    Hi chinna,

                     

                    This is the script:

                     

                    var w = new Window ("dialog", "Template Checklist", undefined, {closeButton: false});

                    w.alignChildren = "left";

                    var check1  = w.add ("checkbox", undefined, "Hyphenation Settings");

                    var check2  = w.add ("checkbox", undefined, "Object Style creation based on Library");

                    var buttons = w.add ("group");

                    buttons.add ("button", undefined, "Ok");

                    var Exit = 0;

                    var cancel = buttons.add ("button", undefined, "Cancel")

                            cancel.onClick = function()

                            {

                                    w.close();

                                    Exit = 1;

                                }

                    w.show ();

                    if(Exit ==1)

                    {

                            this.exit();

                        }

                     

                    var myDocument = app.activeDocument;

                    if (check1.value == true)

                    {

                        var myPara=app.activeDocument.paragraphStyles;

                        for(var i=1;i<myPara.length;i++)

                        {

                                if(myPara[i].hyphenation)

                                {

                                //myPara[i].hyphenation=true;

                                myPara[i].hyphenateWordsLongerThan=6;

                                myPara[i].hyphenateAfterFirst=3;

                                myPara[i].hyphenateBeforeLast=3;

                                myPara[i].hyphenateLadderLimit=2;

                                myPara[i].hyphenationZone="1p";

                                myPara[i].hyphenateCapitalizedWords=true;

                                myPara[i].hyphenateLastWord=false;

                                myPara[i].hyphenateAcrossColumns=false;

                                }

                        }

                        var myStyle=new Array("BK_TTL","BK_HTTL")

                        for(var i=0;i<myStyle.length;i++)

                        {

                                if(myDocument.paragraphStyles.item(myStyle[i]).isValid)

                                {

                                 myDocument.paragraphStyles.item(myStyle[i]).hyphenation = false;

                                }

                            }

                    }

                    if (check2.value == true)

                    alert("Library File is must for this process.");

                    {

                    var library = File.openDialog ("Select the Library File", "*.indl");  ////Your library file path.

                    //~ var library=new File("C:\\Users\\Jayanthi\\Desktop\\Library.indl");//Your library file path.

                    app.open(library);

                    asset = app.libraries[0].assets;

                    for(var i=0;i<asset.length;i++)

                    {

                        try{

                            myDocument.objectStyles.add({name:asset[i].name});

                            }

                        catch(e){}

                        }

                    }

                     

                     

                    var ProgressBar = function(/*str*/title)

                    {

                         var w = new Window('palette', ' '+title, {x:0, y:0, width:340, height:60}),

                              pb = w.add('progressbar', {x:20, y:12, width:300, height:12}, 0, 100),

                              st = w.add('statictext', {x:10, y:36, width:320, height:20}, '');

                         st.justify = 'center';

                         w.center();

                         this.reset = function(msg,maxValue)

                              {

                              st.text = msg;

                              pb.value = 0;

                              pb.maxvalue = maxValue||0;

                              pb.visible = !!maxValue;

                              w.show();

                              };

                         this.hit = function() {++pb.value;};

                         this.hide = function() {w.hide();};

                         this.close = function() {w.close();};

                    };

                    //------------------------------------------------

                    //      SAMPLE CODE

                    //------------------------------------------------

                    function main()

                    {

                         var pBar = new ProgressBar("Running");

                         var i;

                       

                         // Routine #1

                         pBar.reset("Please wait Processing ...", 100);

                         for( i=0 ; i < 100; ++i, pBar.hit() )

                              {

                              $.sleep(10);

                              }

                         // Routine #2

                         pBar.close();

                         }

                    main();

                    exit();

                     

                     

                    When I click the hyphenation setting on its asking 'Select the Library File'.

                    (And tell how to attach the screen shot?)

                    • 7. Re: Create 'Object Style' by script
                      Chinnadk Level 4

                      Hi Hasvi,

                       

                      In your code '{' is placed after the line 'alert("Library File is must for this process.");' but it should be placed immediately after 'if (check2.value == true)'.

                       

                      if (check2.value == true)

                      {

                          alert("Library File is must for this process.");

                          var library = File.openDialog ("Select the Library File", "*.indl");  ////Your library file path.

                          //~ var library=new File("C:\\Users\\Jayanthi\\Desktop\\Library.indl");//Your library file path.

                          app.open(library);

                          asset = app.libraries[0].assets;

                          for(var i=0;i<asset.length;i++)

                          {

                              try{

                                  myDocument.objectStyles.add({name:asset[i].name});

                                  }

                              catch(e){}

                              }

                      }

                       

                      Regards,

                      Chinna

                      • 8. Re: Create 'Object Style' by script
                        hasvi Level 1

                        Hi Chinna,

                         

                        We defined var myDocument = app.activeDocument; in front of all the check1, check2.

                        We are checking check1 is valid, but we used app.open in check2. Is any connection between these?

                         

                        by

                        hasvi

                        • 9. Re: Create 'Object Style' by script
                          hasvi Level 1

                          My adobe community log in suddenly not working. You have any idea.

                           

                          Sent from Yahoo Mail on Android