Skip navigation
Pierre-RAFFA
Currently Being Moderated

Apply [None] Color in TextFrame contents

May 25, 2012 6:20 AM

Hi all,

Is it possible to apply [None] Swatch/Color to a TextFrame contents ?

 

I currently use this:

 

var vNoneColor = app.swatches.itemByName("None");

for (var iText=0; iText < vTextFrame.texts.length ; iText++)

{

        var vText = vTextFrame.texts.item(iText);

        alert(vText.contents);

        vText.fillColor = vNoneColor

 

}

 

 

or maybe create my own Color but it's not possible to change transparency.

 

Thanks.

Regards,

Pierre RAFFA.

 
Replies
  • Currently Being Moderated
    May 25, 2012 6:32 AM   in reply to Pierre-RAFFA

    Pierre,

     

    Try this:

     

    vText.fillColor = null;

     

    or

     

    vText.fillColor = NothingEnum.NOTHING;

     

    Hope that helps.

     

    --

    Marijan (tomaxxi)

    http://tomaxxi.com

     
    |
    Mark as:
  • Currently Being Moderated
    May 25, 2012 6:43 AM   in reply to Pierre-RAFFA

    Yes, you are right. I didn't tested it.

     

    This works:

    vText.fillColor = app.activeDocument.swatches.item("None");

     

    --

    Marijan (tomaxxi)

     
    |
    Mark as:
  • Currently Being Moderated
    May 25, 2012 8:53 AM   in reply to Pierre-RAFFA

    You should really use the locale independent name:

     

    var noColor = doc.swatches.itemByName("$ID/kNoneName");

     
    |
    Mark as:
  • Currently Being Moderated
    May 31, 2012 2:59 PM   in reply to Harbs.

    Hi Harbs and Marijan,

     

    Just curious, any reason not to use vText.fillColor = "$ID/kNoneName"; without the "preamble" doc.swatches.itemByName ?

     
    |
    Mark as:
  • Currently Being Moderated
    May 31, 2012 11:36 PM   in reply to Trevorׅ

    No. Probably not.

     

    I tend to use object references rather than strings, but it should work fine here.

     
    |
    Mark as:
  • Currently Being Moderated
    Jun 1, 2012 1:01 AM   in reply to Harbs.

    You should really use the locale independent name

     

    @Harbs – in my German InDesign " fillColor = "None" " does work as expected. Are there other localized versions of InDesign where this does not work?

     

    So this does the job:

     

    myTextFrame.texts[0].fillColor = "None";
    

     

    Uwe

     
    |
    Mark as:
  • Currently Being Moderated
    Jun 1, 2012 1:10 AM   in reply to Laubender

    I don't know about other languages, but locale independent strings are always safer...

     
    |
    Mark as:
  • Currently Being Moderated
    Jun 1, 2012 2:31 AM   in reply to Harbs.

    Harbs,

     

    Surprisingly, "$ID/kNoneName" doesn't work for Object Styles.

     

    Usually, I do it like this:

     

    var _noneObjStyle = app.activeDocument.objectStyles.item(0);

     

    --

    Marijan (tomaxxi)

     
    |
    Mark as:
  • Currently Being Moderated
    Jun 1, 2012 5:42 AM   in reply to Marijan Tompa

    Yes. For styles I do it that way. Swatches can be moved around, so the first is not always "[None]"...

     
    |
    Mark as:
  • Currently Being Moderated
    Jun 1, 2012 9:03 AM   in reply to Harbs.

    Harbs. wrote:

     

    You should really use the locale independent name:

     

    var noColor = doc.swatches.itemByName("$ID/kNoneName");

     

    I'm afraid this is no correct in the specific case of swatches—and the code above should not work in non-EN languages.

     

    Whatever the locale the None swatch has always the internal name "None"—even if it is localized in the Swatch panel as [None], [Sans], [Ohne], etc. (depending on the locale). This fact is very specific to the Swatches collection, which basically uses None, Black, Paper and Registration as unique reserved names in a locale-independent way. (By contrast, the reserved names of the styles collection, including None, are locale-dependent!)

     

    As a consequence, the regular way to point out to the None swatch in any language, is:

     

    var noneSwatch = myDoc.swatches.itemByName('None');
    alert( noneSwatch.isValid ); // should always be true
    alert( noneSwatch.name ); // should always be"None"
    

     

    Likewise, the shortcut to apply this swatch, in any language, is:

     

    myObj.fillColor = "None";
    

     

    whereas myObj.fillColor = "$ID/kNoneName" will fail in non-EN locales because this actually means:

     

    myObj.fillColor = app.translateKeyString("$ID/kNoneName");

     

    i. e.:

     

    myObj.fillColor = "Ohne"; // in German => error

    myObj.fillColor = "Sans"; // in French => error

     

    By contrast, name-based access to special object styles can be done locale-dependently, and should be done locale-independently:

     

    var noneStyle = myDoc.objectStyles.itemByName('$ID/[None]'); // OK
    

     

    @+

    Marc

     
    |
    Mark as:

More Like This

  • Retrieving data ...

Bookmarked By (0)

Answers + Points = Status

  • 10 points awarded for Correct Answers
  • 5 points awarded for Helpful Answers
  • 10,000+ points
  • 1,001-10,000 points
  • 501-1,000 points
  • 5-500 points