2 Replies Latest reply on Sep 24, 2013 11:29 PM by DavideBenzoni

    how create a mixedcolor in javascritp

    DavideBenzoni

      Below a segment of my scritp but there is an error in the assignment of colors

       

      ------------------

      try{

      myDocument.colors.item("doublecolor").name;

      }

      catch (myError){

         myDocument.mixedInks.add({name:"sbalzooro", model:ColorModel.MIXEDINKMODEL, space:ColorSpace.MIXEDINK,inkList:["Process Cyan","Process Magenta","sbalzo", "PANTONE 871 C"],inkPercentages:[0,0,100,100]});

      }

       

      ------------------

       

      thanks


        • 1. Re: how create a mixedcolor in javascritp
          Marc Autret Level 4

          Hi Davide,

           

          MixedInks.add(…) expects the following arguments, in that order:

          inkList (array of Inks or MixedInkGroup)

          inkPercentages (Array of numbers)

          withProperties (Object w/ additional mixed ink props — optionnal)

           

          Note that inkList, if supplied as an array, must contains actual existing (=valid) Ink specifiers (rather than ink names). So I suggest you implement a ink validator routine.

          Here is a possible approach:

           

          // Your settings
          // -------------------------------------
          var MY_MIX_INKS = {
              // Valid ink names are required -- At least 2 process inks are required
              'Process Cyan'    :   0,      // Process1 : %
              'Process Magenta' :   0,      // Process2 : %
              'sbalzo'          : 100,      // Custom1  : %
              'PANTONE 871 C'   : 100       // Custom2  : %
              },
              MY_MIX_NAME = 'doublecolor';
          
          // Ink Validator
          // -------------------------------------
          var validateInkData = function(/*{name: %}*/o, /*inks*/c, /*&inklist*/ll, /*&inkPerc*/pp)
              {
              var k, t, z=0, r=1;
          
              ll.length = pp.length = 0;
          
              for( k in o )
                  {
                  if( !o.hasOwnProperty(k) ) continue;
                  if( !(t=c.itemByName(k)).isValid ){ r=0; break; }
                  ll[z] = t.getElements()[0];
                  pp[z++] = +o[k];
                  }
          
              return r;
              };
          
          // Main process
          // -------------------------------------
          var doc = app.activeDocument,
              inkList,    // will receive validated ink list (array)
              inkPerc;    // corresponding percentages (array)
          
          if( !doc.mixedInks.itemByName(MY_MIX_NAME).isValid )
              {
              if( validateInkData(MY_MIX_INKS, doc.inks, inkList=[], inkPerc=[]) )
                  {
                  doc.mixedInks.add(inkList, inkPerc,
                      {
                      name: MY_MIX_NAME,
                      model: ColorModel.MIXEDINKMODEL,
                      space: ColorSpace.MIXEDINK
                      });
          
                  alert( "The mixed ink '" + MY_MIX_NAME + "' has been successfully created." );
                  }
              else
                  {
                  alert( "Unable to create mixed ink. Some inner inks are missing." );
                  }
              }
          else
              {
              alert( "The mixed ink '" + MY_MIX_NAME + "' already exists." );
              }
          

           

          @+

          Marc

          • 2. Re: how create a mixedcolor in javascritp
            DavideBenzoni Level 1

            Thanks Marc,

            now everything is OK.

            I need to understand the steps. I am just a beginner.