4 Replies Latest reply on Aug 8, 2017 10:30 AM by cbishop01

    Script to make selection 100% Black?

    cbishop01 Level 2

      This script question is basic.  How would i go about making a script that makes the selection Solid Black?  I think i could do this in Indesign but I'm finding that illustrator is not the same in scritping

        • 1. Re: Script to make selection 100% Black?
          williamadowling Level 4

          Depends upon what kind of object the selection is. For a simple pathItem, you can do this:

           

          var docRef = app.activeDocument;
          var blackColor = new CMYKColor();
          blackColor.black = 100;
          
          var sel = docRef.selection;
          
          //assuming there's only one item selected
          //if multiple items are selected, you just do this part in a loop
          sel[0].fillColor = blackColor;
          

           

          if you have groupItems you'll likely need some recursive functionality (unless you can rely on a consistent structure of the group, in which case you could target the underlying pathItems specifically, but this isn't very scalable and thus, a bad idea).

           

          If you give more information about the file you're working with and the exact structure of the objects and what not, i can give a more specific answer.

          1 person found this helpful
          • 2. Re: Script to make selection 100% Black?
            Silly-V Adobe Community Professional

            It depends on what you have selected. For example you can have raster images, but they won't change color, or what if you had something with a fill and stroke , would you want both to be black?

            Assuming you are just dealing with paths which have fills, you can apply the following snippet to give them the "Black" color of your document's swatches. The good thing is, your paths can be grouped or be compound paths, etc.

             

            #target illustrator

            function test(){

              var doc = app.activeDocument;

              doc.defaultFillColor = doc.swatches.getByName("Black").color;

            };

            test();

            1 person found this helpful
            • 3. Re: Script to make selection 100% Black?
              cbishop01 Level 2

              Sorry i should have specified.  This is only for certain Guide marks such as "eyemarks/CropMarks" etc.. i have selected.  Both stroke and Fill. I really only need it for all the RICH BLACK marks i have on the documents.

               

              Thanks to you both for replying.

              • 4. Re: Script to make selection 100% Black?
                cbishop01 Level 2

                Thanks both of you.  I used Silly-V's script (Slightly Modified) just because it was simpler to add the stroke as well.

                #target illustrator
                
                function test(){
                
                    var doc = app.activeDocument;
                        doc.defaultFillColor = doc.swatches.getByName("Black").color;
                        doc.defaultStrokeColor = doc.swatches.getByName("Black").color;
                };
                
                test();