4 Replies Latest reply on Jan 30, 2014 7:45 AM by Trevorׅ

    Creating a color in InDesign Javascript (CC)

    JADarnell Level 1

      Hello everyone:

       

      I am using this code to try to create a color that can be used to fill a button:

      function MakeButtonColor()

      {

         var TheColor;

         var TheDocument = app.activeDocument;

         var myError;

        

         try

         {

            TheColor = TheDocument.colors.item("DPSButtonColor");

            var ColorName = TheColor.name;

         }

         catch(myError)

         {

             TheColor = TheDocument.colors.add({name: "DPSButtonColor", colorSpace:ColorSpace.RGB, model:ColorModel.process,colorValue:[0,137,208]});

         }

       

         var ButtonColor1 = TheColor;

         alert("ButtonColor is " + ButtonColor1.name);

           

      }

       

      I am taking this directly from the Scripting Guide with only a very few modifications.

       

      But I never ever see the last two statements executed.   I've tried all sorts of things to make this work and it just doesn't want to work.

       

      Anyone have any ideas why it won't work and what I can do to fix it?

        • 1. Re: Creating a color in InDesign Javascript (CC)
          Trevorׅ Adobe Community Professional

          Hi JADarnell,

           

          change colorSpace to space and make sure to call the function by adding MakeButtonColor() to the beggining or end of the script

          1 person found this helpful
          • 2. Re: Creating a color in InDesign Javascript (CC)
            csm_phil Level 4

            Hi JADarnell,

             

            I just modified your code as per the Trevor mentioned lines. Try this!

             

             

            MakeButtonColor()
            function MakeButtonColor(){
               var TheColor;
               var TheDocument = app.activeDocument;
               var myError;
               try{
                   TheColor = TheDocument.colors.itemByName("DPSButtonColor");
                   var ColorName = TheColor.name;
                   }
               catch(myError){
                   TheColor = TheDocument.colors.add({name: "DPSButtonColor", space:ColorSpace.RGB, model:ColorModel.process,colorValue:[0,137,208]});
                   }
               var ButtonColor1 = TheColor;
               alert("ButtonColor is " + ButtonColor1.name);
               }
            

             

            thx,

            csm_phil

            • 3. Re: Creating a color in InDesign Javascript (CC)
              JADarnell Level 1

              Thanks Trevor, thanks Phil.  After wrestling with what can only be described as a self-inflicted wound, I used your code and it worked as advertised.

               

              I considered starting a flame war WRT the proper positioning of brackets in code, but decided I was too grateful for such unpleasant behavior (grin).

               

              My only other, closing remark is that I was following a number of examples which used "colorSpace" instead of "space."  They, however, were obviously wrong...success proved that.

               

              Take care,

              John

              • 4. Re: Creating a color in InDesign Javascript (CC)
                Trevorׅ Adobe Community Professional

                ColorSpace is then name of the enum i.e. Colorspace.RGB.