31 Replies Latest reply: Mar 20, 2014 2:57 AM by Laubender RSS

    Coloring a Font with a RGB etc. without adding the color to the document swatches.

    Trevorׅ Community Member

      Is there a way of coloring a font with a RGB, Lab or CMYK color without adding the color to the document swatches.

      The only way I know is to add a color to the swatches or use one that already exists.

       

      like

         app.selection[0].characters[0].fillColor=document.colors.add({colorValue: [255, 53, 160], space: ColorSpace.RGB});}

       

      This has the undesired effect of cluttering up the swatches when using a lot of colors.

       

      any ideas?

        • 1. Re: Coloring a Font with a RGB etc. without adding the color to the document swatches.
          John Hawkinson Community Member

          InDesign Tagged Text?

          In short: no, not really, seems like a limitation.

          • 2. Re: Coloring a Font with a RGB etc. without adding the color to the document swatches.
            Harbs. CommunityMVP

            Using standard methods, the only way to add colors is by adding a swatch.

             

            If you have an unnamed color in your document, you can apply it to another object using obj1.fillColor = obj2.fillColor.

             

            So, if you can get the unnamed color in your document somehow, you can apply it via scripting.

             

            One way to do that would be to write a snippet programmatically with the desired color, import that, apply the color and remove the placed snippet.

             

            You can check if the color exists already in the doc before doing that...

             

            Harbs

            • 3. Re: Coloring a Font with a RGB etc. without adding the color to the document swatches.
              John Hawkinson Community Member

              Definitely easier with InDesign Tagged Text:

               

              <ASCII-MAC>
              color test
              <cColor:COLOR\:CMYK\:Process\:0.75\,0.5\,0.53\,0.10>seventy<cColor:>
              nocolor test
              
              • 5. Re: Coloring a Font with a RGB etc. without adding the color to the document swatches.
                Trevorׅ Community Member

                Sounds to me like a good idea as well but unlike Harbs I don't have a clue how to apply XML attributes to text in the document.

                 

                Please can you show me how to do this.

                 

                Take for example I want to make the second character or word in my current selection the color CMYK\:Process\:0.75\,0.5\,0.53\,0.10

                how would I script that?

                 

                 

                 

                 


                • 6. Re: Coloring a Font with a RGB etc. without adding the color to the document swatches.
                  Harbs. CommunityMVP

                  Okay...

                   

                  Here's a multi-purpose function which takes an array of three or four values and returns an unnamed color (either RGB or CMYK) using the methods we discussed here:

                   

                   

                  function GetUnnamedColor(values){
                      if( !(values instanceof Array) ){
                          throw("Values must be an array of three or four values");
                      }
                      var fileString = "<ASCII-MAC>\r" +
                          "<pstyle:><cc:COLOR\:";
                      if(values.length == 3){
                          fileString = fileString + "RGB\:Process\:";
                          for(var i=0;i<values.length;i++){
                              values[i] = values[i]/255 * 100;
                          }
                      }
                      else if(values.length == 4){
                          fileString = fileString + "CMYK\:Process\:";
                      }
                      else {
                          throw("Values must be an array of three or four values");
                      }
                      for(var i=0;i<values.length;i++){
                          if(values[i] >= 100){
                              fileString = fileString + "1";
                          } else {
                  
                              values[i] = values[i].toString();
                              var tempSplit = values[i].split(".");
                              while(tempSplit[0].length<2){
                                  tempSplit[0] = "0" + tempSplit[0];
                              }
                              values[i] = tempSplit.join("");
                              fileString = fileString + "0."+values[i];
                          }
                          if(i<values.length-1){
                              fileString = fileString + "\,";
                          }
                      }
                  
                      fileString = fileString + ">Just Some Text<cc:>";
                      var file = File(Folder.temp+"color_import.txt");
                      file.open('w');
                      file.write(fileString);
                      file.close();
                      var story = app.documents[0].pages[0].place(file)[0];
                      var color = story.fillColor;
                      story.textContainers[0].remove();
                      return color;
                  }
                  alert(GetUnnamedColor([75,0.5,53,10]).colorValue);
                  

                   

                  Harbs

                   

                  [Edit] It assumes a document to be open. I have real work to do, so I can't make it more robust right now...

                  • 7. Re: Coloring a Font with a RGB etc. without adding the color to the document swatches.
                    Trevorׅ Community Member

                    Wow, thanks a lot as I wrote  "unlike Harbs I don't have a clue how to apply XML attributes to text in the document" !


                    I was expecting between 1 and 2 lines of script! (what an Am HaAretz!)


                    I shall go over the the script to analyse the methods.

                     

                    Much appreciated, please get on with some real work and have a Kesiva VeHaSima Tova.

                    • 8. Re: Coloring a Font with a RGB etc. without adding the color to the document swatches.
                      [Jongware] CommunityMVP

                      Gosh I have no idea what prompted me to visit this thread again

                       

                      ... Here is a one-liner to set the color of a text selection to any RGB, Lab, or CMYK color without adding it to the Swatches list:

                       

                      app.selection[0].fillColor.properties = {space:ColorSpace.RGB,colorValue:[255,255,0]};
                      

                       

                      Impressed? Well, if you try it you'll notice it won't work straight away. There Is A Catch! (Two of 'em, actually.)

                       

                      .

                      .

                      .

                      .

                      .

                      (spoiler space)

                      .

                      .

                      .

                      .

                      .

                       

                      Catch #1: You can only change the color of text if it already has an 'undefined' color!

                       

                      Now usually, you'll find your text already comes with a swatch applied to it, even though it's simply "Black", and so you cannot use this trick. If you do want to use it, you have to change it first to the fillColor of a text that already has an undefined color applied to it; then you can change it to anything you want. But you cannot create a piece of text to act as model to begin with, using a script (well, other than Harbs' workaround with a temporary snippet file) -- a real Catch-22.

                       

                      To get it to work, draw a new text frame somewhere on the pasteboard in your document and enter this text into it: "A Jongware Solution". (Use exactly this text.) Change the color to something random, using the Color panel. Use the Script Label panel to add a label to the text frame -- use "color placeholder". Then, just before the line that sets other text to any color, insert this:

                       

                      app.selection[0].fillColor = app.activeDocument.textFrames.item("color placeholder").characters[0].fillColor;
                      

                       

                      At first glance, this appears to work, but I noticed The Weirdest Thing. If you apply this color to your newly selected text, you'll find it initially is set to the placeholder color. That's to be expected. The second line (the one at the top of this post) also works, as you will see the color change to the new settings.

                       

                      However. Catch #2

                      Check what happens to the placeholder text ... It also changes its color! Curioser & curioser, if you used this trick a couple of times in the same document, you'll find that every item with the same color also changes! It's kinda like ... you have a swatch ... but not really ...

                      • 9. Re: Coloring a Font with a RGB etc. without adding the color to the document swatches.
                        Trevorׅ Community Member

                        Thanks Jongware

                         

                        I'm afraid I agree with the spoiler lines you put it

                        I think the catches are quite big,

                        Oh well, but as it happens I was also thinking of this post lately and thought of you because I had seen on another post that you wrote that one can use menu actions

                        So I know this is a cheat because my question was how to add color with no swatch but I think (based on Harbs and your replys) that its better to add and then remove the swatches and replace the removed swatches with unnamed ones.

                         

                        But It's easier said than done

                         

                        Please see the script below and see if you can correct the problem line

                        to run the script a letter ... which is colored with a swatch must be selected.

                         

                        var myMenu = app.menuActions.item('$ID/Swatches_WinMenu');

                        myMenu.invoke();

                        var mySwatchRemoveMenuItem = app.menuActions.item('$ID/Delete Swatch...');

                        mySwatchRemoveMenuItem.invoke();

                        var makeUnnamedSwatch = app.menuActions.item('$ID/Unnamed Swatch');

                        // The above line is the problem line I don't know what to put instead of '$ID/Unnamed Swatch'

                        // to get it to choose replace with unnamed swatch as there dosn't seem to be a valid $ID for it.

                        makeUnnamedSwatch.invoke();

                         

                        Once again

                        Thanks

                        • 10. Re: Coloring a Font with a RGB etc. without adding the color to the document swatches.
                          [Jongware] CommunityMVP

                          I'm afraid it's not that straightforward. "Delete Swatch" is a menu option but "Replace with Unnamed Color" is not, so there is nothing to invoke.

                          • 11. Re: Coloring a Font with a RGB etc. without adding the color to the document swatches.
                            Trevorׅ Community Member

                            Oh well again, I guess that sums it up.

                            Thanks

                            • 12. Re: Coloring a Font with a RGB etc. without adding the color to the document swatches.
                              bduffy323 Community Member

                              Hi all, I am trying to accomplish the same goal (except color a textFrame not text) and I am using Harbs method but am only getting black boxes.

                               

                              var r=0;

                              var g=102;

                              var b=255;

                               

                              var elemBox = currentPage.textFrames.add(); //Add box

                              var addedColor = GetUnnamedColor([r,g,b]);

                              elemBox.fillColor = addedColor;

                               

                               

                              The filestring that gets written to the temp. file is:

                               

                              <ASCII-MAC>

                              <pstyle:><cc:COLOR:RGB:Process:0.00,0.40,1>Just Some Text<cc:>

                               

                              the addedColor.colorValue is 0,0,0,100

                               

                               

                              Is anyone else experiencing the same results?

                              • 13. Re: Coloring a Font with a RGB etc. without adding the color to the document swatches.
                                absqua Community Member

                                I get the expected results—addedColor.colorValue is [0,102,255]—in CS5 and CS4 on the Mac. I don't have any good theories about why you're seeing what you're seeing. Have you tried with a fresh document or after trashing or temporarily moving your prefs and defaults?

                                 

                                Jeff

                                • 14. Re: Coloring a Font with a RGB etc. without adding the color to the document swatches.
                                  [Jongware] CommunityMVP

                                  You input RGB and you get *four* values in return...?

                                  • 15. Re: Coloring a Font with a RGB etc. without adding the color to the document swatches.
                                    bduffy323 Community Member

                                    @Jongware - Yes that is correct. I copied the function verbatum and that is what I get in return. I Have also tried putting in dummy values for a CMYK [50,50,20,0] and I get the same result.

                                     

                                     

                                     

                                    @absqua - I am running CS5.5 on a PC. Does that effect the <ASCII-MAC> maybe?

                                    • 16. Re: Coloring a Font with a RGB etc. without adding the color to the document swatches.
                                      absqua Community Member

                                      You saw this same problem before, without using Harbs's function, right? (Your other thread?) So I don't think it has anything to do with the tagged text. I know it seems like grasping at straws, but, in the absence of any other ideas, can you try clearing your defaults and starting with a new document?

                                      • 17. Re: Coloring a Font with a RGB etc. without adding the color to the document swatches.
                                        bduffy323 Community Member

                                        Well, my other thread is a similiar problem and I'm hoping that this solution is a work-around for that (since I was grasping at straws over there as well). I'm actually using an entirely new document (created by script) and am adding rectangles that each have a color assigned to them. So it works using:

                                         

                                        var addedColor = myDoc.colors.add({space:ColorSpace.RGB,colorValue:[r,g,b]});

                                        elemBox.fillColor = addedColor;

                                         

                                        It just adds them all to the swatches fly-out which I need to avoid as well. So I'm hoping by finding a solution to this problem, it will also solve my other threads problem which is slightly different. Fingers crossed.

                                        • 18. Re: Coloring a Font with a RGB etc. without adding the color to the document swatches.
                                          bduffy323 Community Member

                                          Ah the solution! After researching tagged text, I found that on a windows platform you must have <ASCII-WIN>. The colors come through as expected. I will post on my other thread if this solution works to solve that as well.  Except I wont be able to test that until tomorrow.

                                           

                                          Just on more question. Harbs says above that "You can check if the color exists already in the doc before doing that..." and by that he means executing that method. But how do you check for the unnamed color?

                                           

                                          Message was edited by: bduffy323

                                          • 19. Re: Coloring a Font with a RGB etc. without adding the color to the document swatches.
                                            Trevorׅ Community Member

                                            Ok some years late coming from this thread base on Uwe's discovery that a doc always has a color in it we can just use.

                                             

                                            var myUnnamedColor = app.activeDocument.colors[-1].duplicate();
                                            myUnnamedColor.properties = {colorValue:[10,50,70,0]}; // space, model etc.
                                            
                                            // var newRectangleWithUnnamedColor = app.activeDocument.rectangles.add({geometricBounds:[0,0,100,100],fillColor: myUnnamedColor});
                                            

                                             

                                            Regards to all

                                             

                                            Trevor

                                            • 20. Re: Coloring a Font with a RGB etc. without adding the color to the document swatches.
                                              Laubender CommunityMVP

                                              @Trevor – sorry to say, but that would not  always work.

                                               

                                              After testing a lot, I found, that there are cases where this cannot work. Mostly incidents where a user was working with spot colors and removed that spot color to a unnamed one.

                                               

                                              You can try your snippet on the following file (CS5.5):

                                               

                                              AddingUnnamedColorDoesNotWork.zip

                                                  AddingUnnamedColorDoesNotWork_TREVOR-SNIPPET.idml

                                                  AddingUnnamedColorDoesNotWork_TREVOR-SNIPPET.indd

                                               

                                              Download the zip from my dropbox account here:

                                               

                                              https://www.dropbox.com/s/pl1za6fw9v3bc04/AddingUnnamedColorDoesNotWork.zip

                                               

                                              (EDIT: Link did not work as expected)

                                               

                                              I think, we cannot assume, that  colors[-1] is always the right one for duplication.

                                               

                                              However, what is working with the file you can download is the following snippet (if our goal is a unnamed process color in CMYK):

                                               

                                              //AddingUnnamedCMYKcolorToDocument.jsx
                                              //Uwe Laubender
                                              /**
                                              * @@@BUILDINFO@@@ AddingUnnamedCMYKcolorToDocument.jsx !Version! Tue Mar 18 2014 18:43:44 GMT+0100
                                              */
                                              
                                              //Is working, if document is of type PRINT or WEB.
                                              
                                              var myColors = app.activeDocument.colors;
                                              var myID;
                                              
                                              //Catch the standard unnamed color with colorValue [0,0,0,0]
                                              for(var n=0;n<myColors.length;n++){
                                              
                                                  if(
                                              
                                              
                                                      myColors[n].colorValue.length == 4 &&
                                              
                                                      myColors[n].colorValue[0] == 0 &&
                                                      myColors[n].colorValue[1] == 0 &&
                                                      myColors[n].colorValue[2] == 0 &&
                                                      myColors[n].colorValue[3] == 0 &&
                                              
                                                      myColors[n].name == ""
                                              
                                                      ){
                                                          myID = myColors[n].id;
                                                          break;
                                                          };
                                                  };
                                              
                                              if(myID == null){alert("No color found.");exit()};
                                              
                                              var myUnnamedColor = app.documents[0].colors.itemByID(myID).duplicate();
                                              
                                              myUnnamedColor.colorValue = [100,0,0,20];
                                              
                                              var newRectangleWithUnnamedColor = app.activeDocument.rectangles.add
                                                  ({
                                                  geometricBounds:[0,0,100,100],
                                                  fillColor: myUnnamedColor
                                                  });
                                              

                                               

                                               

                                              Adding an unnamed RGB color will work with the following snippet.

                                              However I cannot tell, if in all circumstances:

                                               

                                              //AddingUnnamedRGBcolorToDocument.jsx
                                              //Uwe Laubender
                                              /**
                                              * @@@BUILDINFO@@@ AddingUnnamedRGBcolorToDocument.jsx !Version! Tue Mar 18 2014 19:10:38 GMT+0100
                                              */
                                              
                                              //Is working, if document is of type PRINT or WEB.
                                              
                                              var myColors = app.activeDocument.colors;
                                              var myID;
                                              
                                              //Catch the standard unnamed color with colorValue [0,0,0,0]
                                              for(var n=0;n<myColors.length;n++){
                                              
                                                  if(
                                              
                                              
                                                      myColors[n].colorValue.length == 4 &&
                                              
                                                      myColors[n].colorValue[0] == 0 &&
                                                      myColors[n].colorValue[1] == 0 &&
                                                      myColors[n].colorValue[2] == 0 &&
                                                      myColors[n].colorValue[3] == 0 &&
                                              
                                                      myColors[n].name == ""
                                              
                                                      ){
                                                          myID = myColors[n].id;
                                                          break;
                                                          };
                                                  };
                                              
                                              if(myID == null){alert("No color found.");exit()};
                                              
                                              var myUnnamedColor = app.documents[0].colors.itemByID(myID).duplicate();
                                              
                                              myUnnamedColor.properties = {
                                                  model:ColorModel.PROCESS,
                                                  space:ColorSpace.RGB,
                                                  colorValue:[255,255,10]
                                                  };
                                              
                                              var newRectangleWithUnnamedColor = app.activeDocument.rectangles.add
                                                  ({
                                                  geometricBounds:[0,0,100,100],
                                                  fillColor: myUnnamedColor
                                                  });
                                              

                                               

                                              Again: sorry…

                                               

                                              Uwe

                                               

                                              Message was edited by: Laubender | Link to dropbox did not work as expected.

                                               

                                              Message was edited by: Laubender | Link did not work as expected

                                              • 21. Re: Coloring a Font with a RGB etc. without adding the color to the document swatches.
                                                Trevorׅ Community Member

                                                Hi Again

                                                 

                                                Uwe,

                                                 

                                                I think (pretty sure) your color value test it not needed and also the length is not and as such you are failing to produce unamed colors in cases where you could.

                                                 

                                                I think as long as you check that the swatch name is "" then it should be enough it seems that all unnamed colors are process and can't be mixed ink, gradient or spot.

                                                 

                                                Can you find a case where this won't work? I.e. were there is no such available unnamed color around that we can duplicate?

                                                 

                                                I am pretty tired here but I still don't understand in which case colors[-1] won't be a duplicatable unnamed swatch from which we can create other unnamed colors.

                                                As the link didn't work as expected can you make the case clearer?

                                                 

                                                I think you might have been misled from our other post (link in 19) to think that the unnamed color was not being created because is wasn't appearing the correct color but  it was it just with the wrong color value to it because of the attempt to make it a spot color.

                                                 

                                                You can see this by running this snippet before and after running your remove function there

                                                 

                                                 

                                                var doc = app.activeDocument,
                                                      cols = doc.colors.everyItem().getElements().slice(0),
                                                      l = cols.length;
                                                while (l--) $.writeln(l+")\t"+cols[l].properties.toSource());
                                                

                                                 

                                                Interested in hearing your findings

                                                 

                                                Trevor

                                                • 22. Re: Coloring a Font with a RGB etc. without adding the color to the document swatches.
                                                  Laubender CommunityMVP

                                                  Good Morning, Trevor!

                                                  (At least in my part of the world it's around 9 am)

                                                   

                                                  Did you try the link using the forum?

                                                  I edited and tested it; seems alright now.

                                                  At least from my side using Firefox 27.0.1 on Mac OSX.

                                                   

                                                  I used your snippet above and it always produced the same color over and over again.

                                                  Without throwing an error.

                                                   

                                                  Now, after some testing I do know why.

                                                   

                                                  You always have to set the properties for space and corresponding colorValue. No more, no less. Not the model.

                                                   

                                                  You are right. An unnamed color  would  always be ColorModel.PROCESS.

                                                  Despite my attempts that cannot be changed…

                                                   

                                                  If one is using the UI to generate an unnamed color, a SPOT color will be transfered into a PROCESS color. Always. In case of a spot color with LAB color values (my downloadable example) the above code snippet has to fail, because LAB has 3 color values.

                                                   

                                                  I was using 4 values without setting the corresponding space to ColorSpace.CMYK.

                                                   

                                                  My problem was: it failed silently.

                                                  The new colorValue was not assigned, the duplicated color was using the old ones.

                                                   

                                                  So I come to the conclusion:

                                                   

                                                  Your snippet will work as is, if both, space and colorValue are declared!

                                                   

                                                  var myUnnamedColor = app.activeDocument.colors[-1].duplicate();
                                                  
                                                  //NEEDED: space AND colorValue
                                                  //WILL THROW ERROR: model OTHER than ColorModel.PROCESS
                                                  myUnnamedColor.properties = {
                                                      space:ColorSpace.CMYK,
                                                      colorValue:[10,50,70,0]
                                                      };
                                                  
                                                  var newRectangleWithUnnamedColor = app.activeDocument.rectangles.add({
                                                      geometricBounds:[0,0,100,100],
                                                      fillColor: myUnnamedColor
                                                      });
                                                  

                                                   

                                                  I'm glad this is sorted out now… :-)

                                                   

                                                  PS. it seems that a mixedInk color will fall back to PROCESS CMYK when set to unnamed in the UI.

                                                  Even in a dedicated WEB document. But this is not proven. Just an observation after experimenting a bit.

                                                   

                                                  Uwe

                                                  • 23. Re: Coloring a Font with a RGB etc. without adding the color to the document swatches.
                                                    Trevorׅ Community Member

                                                    Good Morning Uwe!

                                                     

                                                    After 3am by me 2am by you

                                                     

                                                    I had tried the link and it did download but I have cs5 cs6 and cc but not cs5.5 and all the scripts worked on them may because of the file conversion.

                                                     

                                                    So it looks like the following summary is all correct

                                                     

                                                    All documents new contain

                                                    Swatches (Black, Registration, Paper and None) the index order will be the order that the swatches appear in the swatches panel

                                                    And colors in an alphabetical index order

                                                    named color "A" first "Z" last and then the unnamed colors.

                                                     

                                                    A such all new documents colors[-1] will be an unnamed color which we can duplicated to produce other unnamed colors taking note that the duplication must be process and not spot colors.

                                                     

                                                    So far so good, (not for long )

                                                     

                                                    Unnamed colors are not read only so if we make a positive effort to remove them we can do that.

                                                    while (app.activeDocument.colors[-1].name == "") app.activeDocument.colors[-1].remove()
                                                    

                                                    We now won't have any unnamed swatches to duplicate and will have to resort to John's tagged text file method in 3 above.

                                                    If there were no unnamed swatches and we try to duplicate colors[-1] and it was a color like "Yellow" then it seem's to crash indesign.

                                                     

                                                    Anyway the below method should always work (for regular non tint etc. type colors).

                                                     

                                                     

                                                    // optimized for easy of use but not efficiency !!!
                                                    var doc = app.documents.add();
                                                    var p = doc.pages[0];
                                                    
                                                    p.textFrames.add({contents: "RGB", geometricBounds: ["0mm", "0mm", "30mm", "30mm"], fillColor: addUnnamedColor([0, 0,255])}); // will be a RGB
                                                    p.textFrames.add({contents: "RGB", geometricBounds: ["0mm", "30mm", "30mm", "60mm"], fillColor: addUnnamedColor([0, 255,0], 1666336578)}); // will be a RGB because of value
                                                    p.textFrames.add({contents: "RGB", geometricBounds: ["0mm", "60mm", "30mm", "90mm"], fillColor: addUnnamedColor([65, 50, 102], ColorSpace.RGB)}); // will be a RGB
                                                    p.textFrames.add({contents: "RGB", geometricBounds: ["0mm", "90mm", "30mm", "120mm"], fillColor: addUnnamedColor([84, 90,40],"r")}); // will be a RGB
                                                    p.textFrames.add({contents: "RGB", geometricBounds: ["0mm", "120mm", "30mm", "150mm"], fillColor: addUnnamedColor([232, 0, 128],1)}); // will be a RGB
                                                    
                                                    p.textFrames.add({contents: "Lab", geometricBounds: ["30mm", "0mm", "60mm", "30mm"], fillColor: addUnnamedColor([29.5, 67.5, -112])}); // will be a Lab because of -
                                                    p.textFrames.add({contents: "Lab", geometricBounds: ["30mm", "30mm", "60mm", "60mm"], fillColor: addUnnamedColor([100, -128, 127], 1665941826)}); // will be a Lab because of value
                                                    p.textFrames.add({contents: "Lab", geometricBounds: ["30mm", "60mm", "60mm", "90mm"], fillColor: addUnnamedColor([24.5, 16, -29], ColorSpace.LAB)}); // will be a Lab
                                                    p.textFrames.add({contents: "Lab", geometricBounds: ["30mm", "90mm", "60mm", "120mm"], fillColor: addUnnamedColor([36.8, -9, 27],"l")}); // will be a Lab
                                                    p.textFrames.add({contents: "Lab", geometricBounds: ["30mm", "120mm", "60mm", "150mm"], fillColor: addUnnamedColor([51, 78, 0], -1)}); // will be a Lab because of the 1
                                                    
                                                    p.textFrames.add({contents: "CMYK", geometricBounds: ["60mm", "0mm", "90mm", "30mm"], fillColor: addUnnamedColor([82, 72, 0, 0])}); // will be a CMYK because there are 4 color values
                                                    p.textFrames.add({contents: "CMYK", geometricBounds: ["60mm", "30mm", "90mm", "60mm"], fillColor: addUnnamedColor([60, 0, 100, 0], 1129142603)}); // will be a CMYK because of value
                                                    p.textFrames.add({contents: "CMYK", geometricBounds: ["60mm", "60mm", "90mm", "90mm"], fillColor: addUnnamedColor([84, 90,40, 0], ColorSpace.CMYK)}); // will be a CMYK
                                                    p.textFrames.add({contents: "CMYK", geometricBounds: ["60mm", "90mm", "90mm", "120mm"], fillColor: addUnnamedColor([67, 53, 97.6, 21.7], "c")}); // will be a CMYK
                                                    p.textFrames.add({contents: "CMYK", geometricBounds: ["60mm", "120mm", "90mm", "150mm"], fillColor: addUnnamedColor([0, 100, 0, 0], 0)}); // will be a CMYK
                                                    
                                                    function addUnnamedColor (cValue, space, docToAddColor) {
                                                        docToAddColor = app.documents.length && (docToAddColor || (app.properties.activeDocument && app.activeDocument) || app.documents[0]);
                                                        if (!docToAddColor) return;
                                                        var lastColor = docToAddColor.colors[-1];
                                                        if (!cValue) cValue = [0,0,0,0];
                                                        if (space == 1129142603 || cValue && cValue.length == 4) space = ColorSpace.CMYK;
                                                        else if ((space && space < 0) ||  space && space == 1665941826 || (space && /L|-/i.test(space.toString())) || (cValue && /-/.test(cValue ))) space = ColorSpace.LAB;
                                                        else if ((space && space > 0) || space && space == 1666336578 || (space && /R/i.test(space.toString())) || (cValue && cValue.length == 3)) space = ColorSpace.RGB;
                                                        else space = ColorSpace.CMYK;
                                                        app.doScript (
                                                            """
                                                            var newUnnamedColor = (lastColor.name == "") ? lastColor.duplicate() : taggedColor();
                                                            newUnnamedColor.properties = {space: space, colorValue: cValue};
                                                            """,
                                                            ScriptLanguage.javascript,
                                                            undefined,
                                                            UndoModes.FAST_ENTIRE_SCRIPT
                                                        );
                                                    
                                                         function taggedColor() { // need to use this if no unnamed exists
                                                                 var tagString = "<ASCII-" + ($.os[0] == "M" ? "MAC>\r " : "WIN>\r ") + "<cColor:COLOR\:CMYK\:Process\:0.1\,0.95\,0.3\,0.0><cColor:>"; // would make more sense to apply the correct value in the tagged text file but I can't be bothered !
                                                                 var tempFile = new File (Folder (Folder.temp) + "/ " + (new Date).getTime() + ".txt");
                                                                 tempFile.open('w');
                                                                 tempFile.write(tagString);
                                                                 tempFile.close();
                                                                 var tempFrame = docToAddColor.pages[-1].textFrames.add();
                                                                 $.sleep(250);
                                                                 tempFrame.place(tempFile);
                                                                 tempFrame.remove();
                                                                 tempFile.remove();
                                                    
                                                             return docToAddColor.colors[-1];
                                                    
                                                         }
                                                    
                                                        return newUnnamedColor;
                                                    }
                                                    

                                                     

                                                     

                                                    Shall apply the function to delete and replace swatch on the other thread at a more sane time

                                                     

                                                    Regards

                                                     

                                                    Trevor

                                                    • 24. Re: Coloring a Font with a RGB etc. without adding the color to the document swatches.
                                                      Laubender CommunityMVP

                                                      @Trevor – great. Had no time yet testing your code, but it's looking very promising!

                                                       

                                                      You wrote:

                                                      Unnamed colors are not read only so if we make a positive effort to remove them we can do that.

                                                       

                                                      True. So going the IDMS route or the TAGGED TEXT route would be a safe thing to do.

                                                       

                                                      On the other hand, we could have added a new document and procede with duplicating the last unnamed color. Provided someone did not remove all unnamed colors in InDesign when no document was open.

                                                       

                                                      A slim chance, that this would happen ( a scripter playing around maybe ) ;-)

                                                      For obvious reasons I will not test this scenario.

                                                       

                                                      You'll hear from me after having my first pot of morning coffee ;-)

                                                       

                                                      Uwe

                                                      • 25. Re: Coloring a Font with a RGB etc. without adding the color to the document swatches.
                                                        Jump_Over Community Member

                                                        @Uwe; @Trevor

                                                         

                                                        It is fascinating to watch what two "possitive obsessed with their hobbies" people can achieve

                                                         

                                                        I tested another way to reach unnamed color regardless of user/scripter is playing around.

                                                        It works on my side (Windows, CS5). Assuming searching for unnamed color in doc fails:

                                                        if (app.colors[-1].name !="") {
                                                                  app.documents.everyItem().close(SaveOptions.NO); // watch this; is dangerous
                                                                  for (var id = 29188; id < 29191;id++)
                                                                            if (!app.menuActions.itemByID(id).checked)
                                                                                      {app.menuActions.itemByID(id).invoke(); break;}
                                                                  var myUnnamed = app.colors[-1];
                                                                  }
                                                        else var myUnnamed = app.colors[-1];
                                                        

                                                         

                                                        Did you consider this way?

                                                         

                                                        Jarek

                                                        • 26. Re: Coloring a Font with a RGB etc. without adding the color to the document swatches.
                                                          Trevorׅ Community Member

                                                          Jump_Over wrote:

                                                           

                                                          It is fascinating to watch what two "possitive obsessed with their hobbies" people can achieve

                                                           

                                                           

                                                          Yep!

                                                           

                                                          Your script look very dangerous

                                                           

                                                          What are the menu items?

                                                           

                                                          Trevor

                                                          • 27. Re: Coloring a Font with a RGB etc. without adding the color to the document swatches.
                                                            Jump_Over Community Member

                                                            Hi,

                                                             

                                                            3 menuActions associated to Panel Color menuItems ==> "Lab", "CMYK", "RGB".

                                                            Checking them looks like creating a new unnamed color... (with no doc opened)

                                                            Can you see another danger than closing doc and not saving them?

                                                             

                                                            Jarek

                                                            • 28. Re: Coloring a Font with a RGB etc. without adding the color to the document swatches.
                                                              Trevorׅ Community Member

                                                              No but I think that closing the documents without saving them is very dangerous!

                                                              Also it's not going to help add a swatch to the open document, is it!

                                                              • 29. Re: Coloring a Font with a RGB etc. without adding the color to the document swatches.
                                                                Jump_Over Community Member

                                                                Hi,

                                                                 

                                                                No need to capitalize, I did not provide it for public use - just to show the way (very rare)

                                                                 

                                                                Jarek

                                                                • 30. Re: Coloring a Font with a RGB etc. without adding the color to the document swatches.
                                                                  Laubender CommunityMVP

                                                                  @Jarek – to test your code, did you do the unthinkable?

                                                                  ( Removing all unnamed colors from app while no InDesign file was open )

                                                                   

                                                                  I think, I can see what is happening here.

                                                                   

                                                                  While no document is open, in the UI we can add a new unnamed color to app.colors, if we go to the Color Panel (not the Swatches Panel), define a color there.

                                                                   

                                                                  Nothing more, nothing less. Phew…

                                                                   

                                                                  That unnamed color will stick to the app.colors collection even after restarting InDesign app.

                                                                  So even if a scripter was playing around and removed all unnamed colors, we have a way to fix this.

                                                                   

                                                                  Of course, I did playing around and tested this ;-)

                                                                  Unless I do a reinstall of InDesign this new unnamed color will stick.

                                                                   

                                                                  To make your script working, I think we should open the "Color" Panel beforehand:

                                                                   

                                                                  app.panels.itemByName("$ID/kColor").visible = true;
                                                                  

                                                                   

                                                                  ColorPanelOpen_NoDocumentOpen.png

                                                                   

                                                                  Ok. So we can add an unnamed color through the Color Panel.

                                                                  Could we do it while a document is open?

                                                                   

                                                                  Yes. We can. No need to close all documents:

                                                                   

                                                                  //Adding a fresh document:
                                                                  app.documents.add();
                                                                  
                                                                  //The following is also working on an already open document:
                                                                  
                                                                  /*
                                                                  IDs for the three different sub-menus of the "Color Panel":  
                                                                  29188    Lab
                                                                  29189    CMYK
                                                                  29190    RGB
                                                                  */
                                                                  
                                                                  //Make the Color Panel visible:
                                                                  var myColorPanel = app.panels.itemByName("$ID/kColor").visible = true;
                                                                  
                                                                  //Add a unnamed LAB color to the document.colors collection:
                                                                  try{app.scriptMenuActions.itemByID(29188).invoke()}catch(e){$.writeln(e.message)};
                                                                  
                                                                  for(x in app.documents[0].colors[-1]){
                                                                      $.writeln(x+"\t"+app.documents[0].colors[-1][x]);
                                                                      };
                                                                  $.writeln("********************");
                                                                  
                                                                  //Add a unnamed CMYK color to the document.colors collection:
                                                                  try{app.scriptMenuActions.itemByID(29189).invoke()}catch(e){$.writeln(e.message)};
                                                                  
                                                                  for(x in app.documents[0].colors[-1]){
                                                                      $.writeln(x+"\t"+app.documents[0].colors[-1][x]);
                                                                      };
                                                                  $.writeln("********************");
                                                                  
                                                                  //Add a unnamed RGB color to the document.colors collection:
                                                                  try{app.scriptMenuActions.itemByID(29190).invoke()}catch(e){$.writeln(e.message)};
                                                                  
                                                                  for(x in app.documents[0].colors[-1]){
                                                                      $.writeln(x+"\t"+app.documents[0].colors[-1][x]);
                                                                      };
                                                                  $.writeln("********************");
                                                                  
                                                                  
                                                                  /*
                                                                  //RESULTS WITH A FRESH OPENED DOCUMENT:
                                                                  
                                                                  model    1886548851
                                                                  space    1665941826
                                                                  colorValue    0,-0.49809998273849,-4.84829998016357
                                                                  name    
                                                                  id    207
                                                                  label    
                                                                  isValid    true
                                                                  parent    [object Document]
                                                                  index    15
                                                                  properties    [object Object]
                                                                  events    [object Events]
                                                                  eventListeners    [object EventListeners]
                                                                  isValid    true
                                                                  ********************
                                                                  model    1886548851
                                                                  space    1129142603
                                                                  colorValue    100,100,0,100
                                                                  name    
                                                                  id    208
                                                                  label    
                                                                  isValid    true
                                                                  parent    [object Document]
                                                                  index    16
                                                                  properties    [object Object]
                                                                  events    [object Events]
                                                                  eventListeners    [object EventListeners]
                                                                  isValid    true
                                                                  ********************
                                                                  model    1886548851
                                                                  space    1666336578
                                                                  colorValue    0,0,10.3275000303984
                                                                  name    
                                                                  id    209
                                                                  label    
                                                                  isValid    true
                                                                  parent    [object Document]
                                                                  index    17
                                                                  properties    [object Object]
                                                                  events    [object Events]
                                                                  eventListeners    [object EventListeners]
                                                                  isValid    true
                                                                  ********************
                                                                  
                                                                  */
                                                                  

                                                                   

                                                                  Uwe

                                                                  • 31. Re: Coloring a Font with a RGB etc. without adding the color to the document swatches.
                                                                    Laubender CommunityMVP

                                                                    Of course, the next step would be to access document.colors[-1] and change the colorValue to the desired one :-)

                                                                     

                                                                    Uwe