0 Replies Latest reply on Jul 28, 2014 8:47 PM by Johnwhite

    How to add combine two scripts functions?

    Johnwhite Level 1

      Hi, everyone

       

      I got this script, function: modify cells

       

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

       

      var cancel = 0;

      if ( app.selection.length > 0 && ( app.selection[0].constructor.name == "Cell" || app.selection[0].constructor.name == "Table" ) ) { 

          if ( app.scriptPreferences.version >= 6 ) {

              app.doScript( main, ScriptLanguage.JAVASCRIPT , [], UndoModes.ENTIRE_SCRIPT, "style every second column in selection" );         

          } 

          else {

              main();

          }

      } else {

          alert ( "Nothing or wrong selection!" );

      }

      function main() {

      var

        w = new Window("dialog","What is your choice", undefined, {closeButton: false}),

        mPanel1 = w.add ("panel",undefined, "Fill Color"),

        mPanel2 = w.add ("panel",undefined, "Fill Tint"),

        mPanel3 = w.add ("panel",undefined, "Stroke Color"),

        mPanel4 = w.add ("panel",undefined, "Stroke Weight"),

        mPanel5 = w.add ("panel",undefined, "Character Style"),

        mPanel6 = w.add ("panel",undefined, "Dollar Signs' Character Style"),

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

        mCoList = mPanel1.add("dropdownlist",undefined,app.activeDocument.swatches.everyItem().name),

        mFillTint = mPanel2.add("dropdownlist", undefined, ["15%","20%","25%","30%                                 "]),

        mStCoList = mPanel3.add("dropdownlist",undefined,app.activeDocument.swatches.everyItem().name),

        mStWeightList = mPanel4.add("dropdownlist", undefined, ["0.5pt","1pt","1.5pt","2pt                                   "]),

        mStyList = mPanel5.add("dropdownlist",undefined,app.activeDocument.characterStyles.everyItem().name) ,

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

        b = w.add("group");

       

        mCoList.items[0].selected = mStyList.items[0].selected = true;

        w.alignChildren= "left";

        buttton1 = b.add ('button', undefined, "OK", {name: "ok"});

        button2 = b.add ('button', undefined, "取り消す", {name: "cancel"});

        button2.onClick = function()

        {

            w.close();

            cancel = 1;

            }

             

        if (w.show()) {

       

       

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

        var myColor = mCoList.selection.text;

        var mFillTint =    parseInt(mFillTint.selection.text);

        var myStrokeColor = mStCoList.selection.text;

        var myStrokeWeight = mStWeightList.selection.text;

        var myCharStyleName = mStyList.selection.text;

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

        }

        else

        {

            exit();

            }

       

          var curSel = app.selection[0];

          var allCells = curSel.cells;

          var startCol = curSel.cells[0].name.split(":")[0]*1;   

          var endCol = curSel.cells[-1].name.split(":")[0]*1;

          var startRow = curSel.cells[0].name.split(":")[1]*1;   

          var endRow = curSel.cells[-1].name.split(":")[1]*1; 

          var counter = startCol + 1;

       

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

              var curCell = allCells[i];

              var curCol = curCell.name.split(":")[0]*1;

              var curRow = curCell.name.split(":")[1]*1;

       

              if ( curCol == counter ) {

                  with ( curCell ) {

                      fillColor = myColor;

                      fillTint = mFillTint;

                      texts[0].appliedCharacterStyle = myCharStyleName;

                      rightEdgeStrokeWeight = myStrokeWeight;

                      rightEdgeStrokeColor= myStrokeColor; 

                      leftEdgeStrokeWeight = myStrokeWeight;

                      leftEdgeStrokeColor= myStrokeColor;                 

                  }

                  if ( curRow == startRow ) {

                      curCell.topEdgeStrokeWeight = myStrokeWeight;

                      curCell.topEdgeStrokeColor= myStrokeColor;

                  }

                  else if (curRow == endRow ) {

                      curCell.bottomEdgeStrokeWeight = myStrokeWeight;

                      curCell.bottomEdgeStrokeColor= myStrokeColor;

                  }

                 

                  counter = counter + 2;

              }

             

              if ( counter > endCol ) {

                  counter = startCol + 1;

              } // end if

          } // end for

      } // end main

       

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

       

      It can do this, the come out:

       

      UI03 before.jpg

       

       

      the original UI:

       

      set dropdown list weigh_1.jpg

       

      and I got another script:

       

      function for change current year dollar sign's character, by selected in dropdown list

       

      and I want to add another function: change last year dollar sign's character, by selected in dropdown list

       

       

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

       

      var doc = app.activeDocument,  

          _selection = app.selection[0];  

      for(var i =1;i<_selection.columns.length;i+=2)  

      {  

              var _cells = _selection.columns[i].cells;  

              for(var j =0;j<_cells.length;j++)  

              {  

                      var reg = new RegExp("\\$") 

                      if(reg.test(_cells[j].contents)) 

                      { 

                              _cells[j].texts[0].appliedCharacterStyle = "Bold+Italic";  

                          } 

                  }  

          }

       

       

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

       

      I expected the UI:

       

      drow a script UI_2.jpg

       

       

      I expected the come out:

       

      UI03 after.jpg

       

      I will so complicate

       

      so I need your help me?

       

      thanks

       

      John