14 Replies Latest reply on Oct 14, 2015 1:27 PM by Sashabe

    Apply 10% Black tint Color Text Frame / Object

    Cris Ider Level 1

      How can I create a script to apply color tint in text frame or Object (if it´s this item selected)?

       

      A don´t want to use caractere, paragraph or object style.

       

      Is this possible?

        • 1. Re: Apply 10% Black tint Color Text Frame / Object
          Marijan Tompa [tomaxxi] Level 4

          Hey!

           

          This will apply fill color and tint to selected text frame:

           

          var mySel = app.selection[0];
          mySel.fillColor = app.activeDocument.swatches.item("Black");
          mySel.fillTint = 10;
          

           

          --

          tomaxxi

          http://indisnip.wordpress.com/

          • 2. Re: Apply 10% Black tint Color Text Frame / Object
            Cris Ider Level 1

            Thanks!

             

            This soluction is very good.

             

            If I needed 4 scritpts (aparted):

             

            script 01: Apply 10% Black Fill on Text Frame selected (Secection tool - Not Type tool)

            script 02: Apply 10% Black Stroke on Text Frame selected (Selction tool - Not Type tool)

            script 03: Apply 10% Black Fill on Object selected (rectangle, elipse...)

            script 04: Apply 10% Black Stroke on Object selected (rectangle, elipse...)

             

            Sorry, but I couldn´t edit my thread and my english. (I´m from Brazil - I dont speak english - I do what I can)

             

             

            Thanks anyway!!!

            • 3. Re: Apply 10% Black tint Color Text Frame / Object
              Marijan Tompa [tomaxxi] Level 4

              Script is same for text frame and other object.

               

              Apply 10% Black Fill on Text Frame selected (Secection tool - Not Type tool) and Apply 10% Black Fill on Object selected (rectangle, elipse...):

               

              var mySel = app.selection[0];
              mySel.fillColor = app.activeDocument.swatches.item("Black");
              mySel.fillTint = 10;
              

               

              Apply 10% Black Stroke on Text Frame selected (Selction tool - Not Type tool) and Apply 10% Black Stroke on Object selected (rectangle, elipse...):

               

              var mySel = app.selection[0];
              mySel.strokeColor = app.activeDocument.swatches.item("Black");
              mySel.strokeTint = 10;
              mySel.strokeWeight = 1;
              

               

              --

              tomaxxi

              http://indisnip.wordpress.com/

              • 4. Re: Apply 10% Black tint Color Text Frame / Object
                Cris Ider Level 1

                Yes I know it´s the same. You are fantastic.

                 

                Now I just wanna know if is there a way to Not to change Tool like Selection Tool to Type tool.

                 

                Hmm, I need apply 10% Black tint on Text Frame selected by Seletion Tool (Not by Type tool)

                 

                Your script works very good by Type Tool. But if I select it by Selection Tool, the background of frame is filled and not the text.

                 

                var mySel = app.selection[0];
                mySel.fillColor = app.activeDocument.swatches.item("Black");
                mySel.fillTint = 10;

                 

                My intention is keep the Selection Tool actived. But I thank you your solution anyway.

                 


                • 5. Re: Apply 10% Black tint Color Text Frame / Object
                  Marijan Tompa [tomaxxi] Level 4

                  Can you maybe show me what are you trying to achieve by posting screenshot?

                   

                  --

                  tomaxxi

                  http://indisnip.wordpress.com/

                  • 6. Re: Apply 10% Black tint Color Text Frame / Object
                    Cris Ider Level 1

                    I will try, ok?

                     

                     

                    1st - Create a script to apply 10% Black Fill Tint in Text Frame (add a shortcut to this script)

                    2nd - Create a script to apply 30% Black Fill Tint in Bacground Frame (add a shortcut to this script)

                    3rd - Create a script to apply 60% Black Stroke Tint in Text Frame (add a shortcut to this script)

                    4th - Creat a scritp to apply 80% Black Stroke Tint around Frame (add a shortcut to this script)

                     

                    I need the 4 scripts separated to apply to other applications

                     

                    Remember: I have to use The Selection Tool. (I don´t wanna shift tool to apply)

                     

                    Thanks again! I hope you understand me.

                     

                     

                    TexFrame.JPG

                    • 7. Re: Apply 10% Black tint Color Text Frame / Object
                      Marijan Tompa [tomaxxi] Level 4

                      Oh, ok, now it's all clear

                       

                      Here are the scripts:

                       

                      //Script 1
                      var mySel = app.selection[0];
                      mySel.texts[0].fillColor = app.activeDocument.swatches.item("Black");
                      mySel.texts[0].fillTint = 10;
                      
                      //Script 2
                      var mySel = app.selection[0];
                      mySel.fillColor = app.activeDocument.swatches.item("Black");
                      mySel.fillTint = 30;
                      
                      //Script 3
                      var mySel = app.selection[0];
                      mySel.texts[0].strokeWeight = 1.5;
                      mySel.texts[0].strokeColor = app.activeDocument.swatches.item("Black");
                      mySel.texts[0].strokeTint = 60;
                      
                      //Script 4
                      var mySel = app.selection[0];
                      mySel.strokeWeight = 1.5;
                      mySel.strokeColor = app.activeDocument.swatches.item("Black");
                      mySel.strokeTint = 80;
                      

                       

                      Also if you want, you can apply all this with one script:

                       

                      var mySel = app.selection[0];
                      var myColor = app.activeDocument.swatches.item("Black");
                      if(mySel instanceof TextFrame){
                          with(mySel){
                              texts[0].fillColor = myColor;
                              texts[0].fillTint = 10;
                              texts[0].strokeWeight = 1.5;
                              texts[0].strokeColor = myColor;
                              texts[0].strokeTint = 60;
                              fillColor = myColor;
                              fillTint = 30;
                              strokeWeight = 1.5;
                              strokeColor = myColor;
                              strokeTint = 80;
                          }
                      }
                      

                       

                      --

                      tomaxxi

                      http://indisnip.wordpress.com/

                      • 8. Re: Apply 10% Black tint Color Text Frame / Object
                        Cris Ider Level 1

                         

                         

                        This is the script.

                         

                         

                        Thanks!!! You are the man!

                        • 9. Re: Apply 10% Black tint Color Text Frame / Object
                          Foxy Ford Level 1

                          I also like this script!

                           

                          Maybe it´s possible to create a script as for example:

                           

                          1 - Script increase 10% tint Black fill for Frame Text (to apply in text) selected by Selection Tool (I hate Type tool)

                          2 - Script increase 10% tint Black stroke for Frame Text (to apply in text) selected by Selection Tool (I hate Type tool)

                          3 - Script increase 10% tint fill Black for Object

                          4 - Script increase 10% tint Black stroke for Object

                           

                           

                          Application:

                           

                          The Script (Alt+>) on selected object with 10% Tint Black go to 20% Black, So apply the same script (Alt+>) and the object go to 30% Tint Black, on the on till 100% Black.

                           

                          Other Script (Alt+<) to decrease till 0% Black (no fill)

                           

                          4 Scripts (1,2,3,4) to increase and 4 Scripts (1,2,3,4) to decrease.

                           

                          I hope you understand me. Thank you very much!

                          • 10. Re: Apply 10% Black tint Color Text Frame / Object
                            Sashabe Level 1

                            Here you go, after all of these years of waiting. It changes the tint of currently selected swatch (depending on whether we edit text, or stroke/fill is selected in the Tools palette):

                            (decrease tint.jsx)

                            var step = 5;
                            for (s=0; s<app.selection.length; s++) {
                                var sel, tint;
                                if (app.strokeFillProxySettings.target == StrokeFillTargetOptions.FORMATTING_AFFECTS_CONTAINER) {
                                    sel = app.selection[s];
                                } else {
                                    sel = app.selection[s].texts[0];
                                }
                                if (app.strokeFillProxySettings.active == StrokeFillProxyOptions.FILL) {
                                    if (sel.fillTint > (step - 1)) {
                                        sel.fillTint -= step;
                                    } else if (sel.fillTint > 0) {
                                        sel.fillTint = 0;
                                    } else if (sel.fillTint === -1) {
                                        sel.fillTint = 100 - step;
                                    }
                                } else {
                                    if (sel.strokeTint > (step - 1)) {
                                        sel.strokeTint -= step;
                                    } else if (sel.strokeTint > 0) {
                                        sel.strokeTint = 0;
                                    } else if (sel.strokeTint === -1) {
                                        sel.strokeTint = 100 - step;
                                    }
                                }
                            
                            }
                            
                            
                            

                             

                            (increase tint.jsx)

                            var step = 5;
                            for (s=0; s<app.selection.length; s++) {
                                var sel, tint;
                                if (app.strokeFillProxySettings.target == StrokeFillTargetOptions.FORMATTING_AFFECTS_CONTAINER) {
                                    sel = app.selection[s];
                                } else {
                                    sel = app.selection[s].texts[0];
                                }
                                if (app.strokeFillProxySettings.active == StrokeFillProxyOptions.FILL) {
                                    if (sel.fillTint < (100 - (step - 1)) && sel.fillTint > -1) {
                                        sel.fillTint += step;
                                    } else if (sel.fillTint < 100 || sel.fillTint === -1) {
                                        sel.fillTint = -1;
                                    }
                                } else {
                                    if (sel.strokeTint < (100 - (step - 1)) && sel.strokeTint > -1) {
                                        sel.strokeTint += step;
                                    } else if (sel.strokeTint < 100 || sel.strokeTint === -1) {
                                        sel.strokeTint = -1;
                                    }
                                }
                            
                            }
                            
                            
                            

                             

                            However, I checked it only under the latest version of Indesign CC (2015). But it looks like it should be compatible with everything else. Many thanks to my all-time idols Marijan Tompa [tomaxxi] and [Jongware].

                            • 11. Re: Apply 10% Black tint Color Text Frame / Object
                              Marc Autret Level 4

                              Hi Sashabe,

                               

                              Now let's try to make it more modular:

                               

                              // UTILITY
                              // ---
                              function stepTint(/*int*/dt,  a,TXT,PROP,LIM,ALT,MM,o,t,v)
                              {
                                  if( !dt || !(a=app.properties.selection) ) return;
                              
                                  TXT = +(app.strokeFillProxySettings.target==StrokeFillTargetOptions.FORMATTING_AFFECTS_TEXT);
                                  PROP = app.strokeFillProxySettings.active.toString().toLowerCase() + 'Tint';
                                  LIM = 100 * (0 < dt);
                                  ALT = TXT ? (100-LIM) : 100;
                                  MM = Math[ LIM ? 'min' : 'max' ];
                              
                                  while( o=a.pop() )
                                      {
                                      TXT && (o=o.texts[0].textStyleRanges.everyItem());
                                      o = o.getElements();
                                      while( t=o.pop() )
                                          {
                                          ~(v=t[PROP]) || (v=ALT);
                                          t[PROP] = MM(LIM,v+=dt);
                                          }
                                      }
                              }
                              
                              // API
                              // ---
                              const STEP = 5; // positive integer
                              function incTint(){ stepTint(+STEP); }
                              function decTint(){ stepTint(-STEP); }
                              
                              // TEST
                              // ---
                              incTint();
                              

                               

                              Note that stepTint() supports multiple text tints in the current selection (if some text is selected) and then manage them separately

                               

                              @+

                              Marc

                              • 12. Re: Apply 10% Black tint Color Text Frame / Object
                                Sashabe Level 1

                                Hi Marc! Thank you! That's cool. How could your script be used to assign keyboard shortcuts for incrementing/decrementing tint? Should we put the stepTint function into a separate file and then link somehow to it?

                                • 13. Re: Apply 10% Black tint Color Text Frame / Object
                                  Marc Autret Level 4

                                  Here is an easy approach:

                                   

                                  1. Put the stepTint function in a "stepTint.jsxinc" file.

                                   

                                  2. Use:

                                   

                                  #include 'stepTint.jsxinc'

                                  /* etc */

                                   

                                  in both your incTint.jsx and decTint.jsx scripts

                                   

                                  @+

                                  Marc

                                  • 14. Re: Apply 10% Black tint Color Text Frame / Object
                                    Sashabe Level 1

                                    Cool! Didn't know that trick.