Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Apply 10% Black tint Color Text Frame / Object

Explorer ,
Aug 24, 2010 Aug 24, 2010

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?

TOPICS
Scripting
9.1K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advisor ,
Aug 24, 2010 Aug 24, 2010

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/

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Aug 24, 2010 Aug 24, 2010

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!!!

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advisor ,
Aug 24, 2010 Aug 24, 2010

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/

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Aug 24, 2010 Aug 24, 2010

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.


Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advisor ,
Aug 24, 2010 Aug 24, 2010

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

--

tomaxxi

http://indisnip.wordpress.com/

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Aug 24, 2010 Aug 24, 2010

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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advisor ,
Aug 25, 2010 Aug 25, 2010

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/

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Aug 25, 2010 Aug 25, 2010

This is the script.

Thanks!!! You are the man!

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Aug 26, 2010 Aug 26, 2010

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!

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Oct 11, 2015 Oct 11, 2015

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;

    } else {

        sel = app.selection.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;

    } else {

        sel = app.selection.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]‌.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guide ,
Oct 11, 2015 Oct 11, 2015

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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Oct 12, 2015 Oct 12, 2015

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?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guide ,
Oct 12, 2015 Oct 12, 2015

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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Oct 14, 2015 Oct 14, 2015

Cool! Didn't know that trick.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Aug 16, 2017 Aug 16, 2017

...is there a way to align the stroke to the inside?

Awesome scripts by the way. Cheers.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Aug 17, 2017 Aug 17, 2017

https://forums.adobe.com/people/AdobeOne+Shinobi  wrote

...is there a way to align the stroke to the inside?

Look up property strokeAlignment in the DOM documentation.

There are three values:

StrokeAlignment.CENTER_ALIGNMENT

StrokeAlignment.INSIDE_ALIGNMENT

StrokeAlignment.OUTSIDE_ALIGNMENT

Regards,
Uwe

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Aug 17, 2017 Aug 17, 2017

Thank you, you’re awesome.

Another thing, I attempted to select multiple frames, each having varied strokes and fills etc and this script seemed to fail to uniform them to the stroke attributes indicated by the script. I had to select each item individually and then the script worked again, one by one.

So obviously my request is, how could I select multiple frames and apply the below script to them, to affect/effect all of them at once?

As always thanks in advance. Cheers.

var mySel = app.selection[0]; 

mySel.strokeWeight = .3; 

mySel.strokeColor = app.activeDocument.swatches.item("C=0 M=0 Y=0 K=50"); 

mySel.strokeTint = 100; 

mySel.strokeAlignment = StrokeAlignment.INSIDE_ALIGNMENT 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Aug 17, 2017 Aug 17, 2017

Hi,

with app.selection[0] you addressed the first item of your selection. Counting begins with 0.
Loop through the selection to address all selected items.

var sel = app.selection;

var selLength = sel.length;

for(var n=0;n<selLength;n++)

{

// Your code here…

sel.strokeWeight = .3 ;

// etc.pp.

};

Regards,
Uwe

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Aug 17, 2017 Aug 17, 2017

So what would the whole code look like, that I can simply copy paste.

The below code only works on 1 frame (video attached).

Thanks again.

  1. var sel = app.selection; 
  2. var selLength = sel.length; 
  3. for(var n=0;n<selLength;n++) 
  4. {
  5. var mySel = app.selection[0]; 
  6. mySel.strokeWeight = .3; 
  7. mySel.strokeColor = app.activeDocument.swatches.item("C=0 M=0 Y=0 K=50"); 
  8. mySel.strokeTint = 100; 
  9. mySel.strokeAlignment = StrokeAlignment.INSIDE_ALIGNMENT 
  10. };

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Aug 17, 2017 Aug 17, 2017

Look harder at my code…

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Aug 17, 2017 Aug 17, 2017

So should line 5 var mySel = app.selection [0] BE CHANGED to ....?

Holy cow, it worked!

Thanks again man. Ha. It helps to inch me towards understanding this stuff a little more. Greatly appreciated. Cheers.

  1. var sel = app.selection; 
  2. var selLength = sel.length; 
  3. for(var n=0;n<selLength;n++) 
  4. {
  5. var mySel = app.selection[n]; 
  6. mySel.strokeWeight = .3; 
  7. mySel.strokeColor = app.activeDocument.swatches.item("C=0 M=0 Y=0 K=50"); 
  8. mySel.strokeTint = 100; 
  9. mySel.strokeAlignment = StrokeAlignment.INSIDE_ALIGNMENT 
  10. };
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Aug 17, 2017 Aug 17, 2017

...here’s one for you.

If the color swatch indicated in the script isn’t currently available in the Swatch Panel, can it be scripted to be added to the Swatch Panel.

Right now, the script gives an error, until I manually add C=0 M=0 Y=0 K=50 to the Swatch Panel, naturally.

Again, thanks in advance.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Aug 17, 2017 Aug 17, 2017

Hi,

Try this!!

mySel.strokeColor = myDoc.colors.add("0, 0, 0,50");

Thanks,

Prabu G

Thanks,
Prabu
Design smarter, faster, and bolder with InDesign scripting.
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Aug 17, 2017 Aug 17, 2017

Hi,

Try this,

var myDoc = app.activeDocument;   

    var sel = app.selection;

    var selLength = sel.length;

    var myColor =  myDoc.colors.add({name : "New_Color", colorValue : [0,100,100,0] , model : ColorModel.PROCESS ,space : ColorSpace.CMYK }); 

    for(var n=0;n<selLength;n++)

    {

    var mySel = app.selection;

    mySel.strokeWeight = .3;

    mySel.strokeColor = myColor;

    mySel.strokeTint = 100;

    mySel.strokeAlignment = StrokeAlignment.INSIDE_ALIGNMENT

    };

Thanks,

Prabu G

Thanks,
Prabu
Design smarter, faster, and bolder with InDesign scripting.
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines