8 Replies Latest reply on Jan 28, 2013 7:25 AM by Trevorׅ

    Scripting Help! Batch color swap between libraries

    AcmeGV Level 1

      I have multiple files that are setup using pantone solid colors and I need to change them to our custom swatch that we have created for our customers they are also requesting to see the values of the swatch builds.

       

      Is it possible to swap object fill colors from pantone solid coated color to custom swatch library that I have created that is CMYK builds?

      Also once the object fill color is change to the custom CMYK swatch can I setup it up so the values that are being used will display?

       

      Any help or suggestion are greatly appreicated.  I thought of doing this within illustrator but not sure if it is possible within illustrator.

      Screen Shot 2012-11-29 at 9.58.01 PM.png

        • 1. Re: Scripting Help! Batch color swap between libraries
          Trevorׅ Adobe Community Professional

          Check out http://in-tools.com/article/scripts-blog/hexadecimal-swatches-in-indesign/

          Adds "New Hex Swatch" to the Swatches pannel.

          See also cms_phils scripts here for a point in the right direction

          http://forums.adobe.com/message/4863661#4863661

          http://forums.adobe.com/message/4812800#4812800

           

          Trevor

          • 2. Re: Scripting Help! Batch color swap between libraries
            Trevorׅ Adobe Community Professional

            If you wanted to be original in your case you could easily do it with Greps

            Maybe, I'll try post a small script on Sunday.

            What version CS of indesign do you have?

            • 3. Re: Scripting Help! Batch color swap between libraries
              AcmeGV Level 1

              CS5 for both indesign and illustrator

              • 4. Re: Scripting Help! Batch color swap between libraries
                Trevorׅ Adobe Community Professional

                PRESUMING YOU HAVE MADE YOUR DOCUMENT AS FOLLOWS!!!

                 

                1) You have inserted a RECTANGLE as an inline text object.

                2) The next line has the color name

                3) The next line has the CMYK value in the format you did above (Capitol C, - minus sign, space).

                4) The are no other occurrences of the CMYK in the format described in 3 above in the rest of the story.

                 

                 

                INSTRUCTIONS

                 

                1) Make sure the cursor in the story that has the color swabs in it.

                2) Run the script.

                 

                SCREENSHOTS

                 

                Before                                                                                                                                   After

                _Untitled-1 @ 100%_2012-12-01_20-09-09.png_Untitled-1 @ 100%_2012-12-01_20-11-08.png

                I don't know why our 103 Yellows are so different, your's look quite gold.

                Note the script runs on ENTIRE_SCRIPT and not on the FAST_ENTIRE_SCRIPT undo mode, a fix for that would be nice DOES ANY BODY KNOW HOW TO FIX THAT?.

                 

                Enjoy

                Trevor

                 

                app.doScript("main()", ScriptLanguage.javascript, undefined, UndoModes.ENTIRE_SCRIPT, "Make CMYK Swatches");
                function main()
                    {
                        var doc, myParentStory, mySwatches, l, lineOfSwatch, newSwatchName, newSwatch;
                        doc = app.activeDocument
                        myParentStory = app.selection[0].parentStory;
                        app.changeGrepPreferences = app.findGrepPreferences = null;
                        app.findGrepPreferences.findWhat = "C-\\d+\\.?\\d* M-\\d+\\.?\\d* Y-\\d+\\.?\\d* K-\\d+\\.?\\d*";
                        mySwatches = myParentStory.findGrep();
                        l = mySwatches.length;
                        while (l--)
                            {
                                lineOfSwatch =myParentStory.texts.itemByRange (myParentStory.lines[0], mySwatches[l].lines[0]).lines.length-1;
                                CMYK = mySwatches[l].contents.match(/\d+\.?\d*/g);
                                newSwatchName = "C="+CMYK[0]+" M="+CMYK[1]+" Y="+CMYK[2]+" K="+CMYK[3];
                                newSwatch = (doc.swatches.itemByName(newSwatchName).isValid) ? doc.swatches.itemByName(newSwatchName) 
                                : doc.colors.add ({colorValue: [CMYK[0]*1,CMYK[1]*1,CMYK[2]*1,CMYK[3]*1], space: ColorSpace.CMYK,  name:newSwatchName});
                                myParentStory.texts[0].lines[lineOfSwatch-2].rectangles[0].fillColor = newSwatch;
                            }
                }
                
                • 5. Re: Scripting Help! Batch color swap between libraries
                  Trevorׅ Adobe Community Professional

                  Ok Acme

                   

                  This is a much better workflow.

                   

                  1) Setup a document add the Swatches you want converted and made into CMYK values.

                  _Untitled-53 @ 119%_2012-12-02_13-48-53.png

                  If you want the whole Pantone range you can get it here http://www.adobe.com/cfusion/exchange/index.cfm?event=extensionDetail&extid=1046678

                   

                  2) Run the script

                  _Untitled-84 @ 119%_2012-12-02_13-46-59.png

                   

                  Fantastic if I say so myself

                   

                  The script is NOT optimized!!! so it will bit a bit on the slow side for a donation to my charity I shall do my best to optimize it.

                  Either way donation to my charity would be greatly appreciated.

                   

                  // Script by Trevor to make CMYK color Swabs http://forums.adobe.com/message/4890389#4890389
                  var il = app.scriptPreferences.userInteractionLevel;
                  app.scriptPreferences.userInteractionLevel = UserInteractionLevels.NEVER_INTERACT;
                  app.doScript("main()", ScriptLanguage.javascript, undefined, UndoModes.ENTIRE_SCRIPT, "Make CMYK Swabs");
                  app.scriptPreferences.userInteractionLevel = il;
                  function main()
                  {
                      var swatchDoc, doc, swatchColors, l, newSwatch, newSwatchName, cv, ps, m, mtb, tb, ms, tf, ptf;
                      swatchDoc = app.activeDocument;
                      setupDoc();
                      app.activeDocument = doc;
                      swatchColors = swatchDoc.swatches.everyItem().getElements();
                      l = swatchColors.length;
                      while (l--)
                          {
                          if (swatchColors[l].name != "None" && swatchColors[l].name != "Registration" && swatchColors[l].name != "Paper")
                              {
                              newSwatch = doc.colors.add ({model: swatchColors[l].model, space: swatchColors[l].space, colorValue: swatchColors[l].colorValue});
                              newSwatch.space = ColorSpace.CMYK;
                              cv = newSwatch.colorValue;
                              newSwatchName = "C="+cv[0]+ " M="+cv[1]+ " Y="+cv[2]+ " K="+cv[3];
                              newSwatch.name = (doc.swatches.itemByName(newSwatchName).isValid) ? newSwatch.name : newSwatchName;
                              ps.insertionPoints[0].contents = "\r"+swatchColors[l].name+"\r"+newSwatch.name+"\r"
                              ps.insertionPoints[0].rectangles.add({geometricBounds:[0, 0, "15mm", "45mm"], fillColor: newSwatch.name /*  appliedObjectStyle: myStyle */});
                              };
                          }
                      ps.overflows ? addPages(tf): 0;
                      function setupDoc()
                          {
                              doc = app.documents.add({documentPreferences:{facingPages:0, pageOrientation: PageOrientation.PORTRAIT}});
                              m = doc.pages[0].marginPreferences;
                              mtb = doc.pages[0].bounds;
                              tb = doc.pages[0].bounds;
                              mtb[0]=mtb[2]-m.bottom;
                              ms = doc.masterSpreads[0].textFrames.add ({geometricBounds:mtb, textFramePreferences:{verticalJustification:VerticalJustification.CENTER_ALIGN}});
                              ms.parentStory.properties = ({digitsType: DigitsTypeOptions.ARABIC_DIGITS, hyphenation: 0, justification: Justification.CENTER_ALIGN, paragraphDirection: ParagraphDirectionOptions.LEFT_TO_RIGHT_DIRECTION, contents: SpecialCharacters.AUTO_PAGE_NUMBER});
                              tb[0] += m.top; tb[1]+=m.left; tb[2]-=m.bottom; tb[3]-=m.right;
                              tf = doc.pages[0].textFrames.add({geometricBounds:tb})
                              ps= tf.parentStory;
                              ps.properties = {digitsType: DigitsTypeOptions.ARABIC_DIGITS, hyphenation: 0, justification: Justification.LEFT_ALIGN, paragraphDirection: ParagraphDirectionOptions.LEFT_TO_RIGHT_DIRECTION, rightIndent: 2};
                          }
                          function addPages(ptf)
                          {
                              np = doc.pages.add();
                              ptf = np.textFrames.add({geometricBounds:tb, previousTextFrame: ptf});
                              if (ps.overflows) addPages(ptf);
                          }
                  }
                  
                  • 6. Re: Scripting Help! Batch color swap between libraries
                    Trevorׅ Adobe Community Professional

                    Hi Acme,

                     

                    Long time no speak

                     

                    After getting the pro version working, I thought you could mark the above script as correct.

                     

                    In the pro version I works quite a bit differently to the above script.

                     

                    Just one question, what do you do with the swatch sheets?

                     

                    If any one is interested in the in the pro version they should send me a private message or mail to the address shown in the picture.

                     

                    _Untitled-5 @ 25%_2013-01-28_16-07-12.png

                    • 7. Re: Scripting Help! Batch color swap between libraries
                      AcmeGV Level 1

                      Trevor

                       

                      We build custom pantone books for our press profiles.

                       

                      Greg

                      • 8. Re: Scripting Help! Batch color swap between libraries
                        Trevorׅ Adobe Community Professional

                        Hi Greg

                         

                        Can you mark the answer as correct.

                         

                        Thanks

                         

                        Trevor