10 Replies Latest reply on Nov 4, 2015 2:09 AM by Vinicius Baptista

    Selecting objects by fill color

    Puthoskey Level 1

      Hi guys

      Is possible to select objects by color in CMYK using JavaScript?

      All I want to group several objects with the same fill color.

       

      Many thanks for your time...

       

      Please see the picture bellow...

       

      2.jpg

        • 1. Re: Selecting objects by fill color
          Vinicius Baptista Level 2

          Hello P., Are you tried use the native option of Illustrator? Select a item and go to top menu Select>Same>Fill Color or Select>Same>Stroke Color? If you want loop through all the Page Items to select them, look this post: Preflight Pre-Press, there's one way to do this loop, if you prefer I can write it and post here for you.

           

          Best Regards,

          -Vinícius Baptista

          • 2. Re: Selecting objects by fill color
            Puthoskey Level 1

            Hi Vinicius

            Many thanks for your help!

             

            I have tried the code on the post "Prelight" but it doesn't work.

            I would appreciate if you write a simple code that does this:

            - Find objects with the same color and group them (Not using the menu: Select>Same>Fill Color)

             

            A handshake bro!

            • 3. Re: Selecting objects by fill color
              Silly-V Adobe Community Professional

              Are you cool with using menu commands in the script?

              • 4. Re: Selecting objects by fill color
                LeoMari Level 2

                Magic Wand tool

                Take 2 clicks on Magic Wand tool (Screen Shot 2015-11-03 at 2.41.57 PM.png).

                Will open a window where you can select fill color with tolerance 0.

                Screen Shot 2015-11-03 at 2.37.50 PM.png

                hug.

                • 5. Re: Selecting objects by fill color
                  Vinicius Baptista Level 2

                  OfCourse LeoMari great, maybe this will be a best way! Take a look Puthoskey, I think this help you.

                  • 6. Re: Selecting objects by fill color
                    Silly-V Adobe Community Professional

                    I think he wants to be able to use a code inside of other scripts, because he implied not using the UI.

                    • 7. Re: Selecting objects by fill color
                      LeoMari Level 2

                      If script believe it would have to have a prompt to indicate color you want to group.I would have to keep typing combinations. With Magic Wand configure once and select with a single click.

                       

                      But as Silly said, we need to know what our friend want to do ..

                      ThankVinicius..

                      • 8. Re: Selecting objects by fill color
                        Vinicius Baptista Level 2

                        Hello Puthoskey all good?

                         

                        Well, I wrote something as what I had said, notes:

                         

                        This code just work to PathItems;

                        Just CMYKColor;

                        You need select one pathItem before perform the script;

                        It should read the fillColor of selected item and looping through all pageItems of the document, if the pageItem is a pathItem and have the same fillColor or strokeColor, it will be grouped with others;

                        If you want do this in other objects like textItems, you should follow the same logic;

                         

                        Try, test and enjoy, contact us to more adjusts.

                         

                        function selSameColor (){
                           
                            if(app.activeDocument.selection.length == 0){alert('Select a pathItem.'); return};
                            if(app.activeDocument.selection.length > 1){alert('Select just one pathItem.'); return};
                        
                        
                            var selFillColor = function(){
                           
                                var groupColor =  app.activeDocument.groupItems.add();
                        
                        
                                if(app.activeDocument.selection[0].typename == 'PathItem'){ 
                                var colorSel = new CMYKColor;
                                colorSel.cyan = app.activeDocument.selection[0].fillColor.cyan;
                                colorSel.magenta = app.activeDocument.selection[0].fillColor.magenta;
                                colorSel.yellow = app.activeDocument.selection[0].fillColor.yellow;
                                colorSel.black = app.activeDocument.selection[0].fillColor.black;
                                }else{alert('This is not a pathitem.'); return};
                               
                                var itemsLength = app.activeDocument.pageItems.length;
                                var items = app.activeDocument.pageItems;
                        
                        
                                for (i = 0; i < itemsLength; i++){ 
                        
                                    if(items[i].typename == 'PathItem'){ 
                        
                                        if(items[i].fillColor.cyan == colorSel.cyan && items[i].fillColor.magenta == colorSel.magenta && items[i].fillColor.yellow == colorSel.yellow && items[i].fillColor.black == colorSel.black){
                                            items[i].moveToBeginning(groupColor);
                                        }else if(items[i].strokeColor.cyan == colorSel.cyan && items[i].strokeColor.magenta == colorSel.magenta && items[i].strokeColor.yellow == colorSel.yellow && items[i].strokeColor.black == colorSel.black){
                                            items[i].moveToBeginning(groupColor);
                                        };
                                    };
                           
                                };
                            if(groupColor.pageItems.length > 0){groupColor.selected = true};
                            };
                        
                        
                            selFillColor ();
                           
                        };
                        
                        
                        selSameColor ();
                        
                        

                         

                        I hope it be useful, see ya soon man,

                         

                        Best Regards,

                        -Vinícius Baptista

                        • 9. Re: Selecting objects by fill color
                          Puthoskey Level 1

                          Many thanks guys for all your suggestions and time!

                          And to you too Vinícius... your code works like a charm XP

                          Just like I asked

                           

                          A big handshake for all of you!

                          Regards

                          • 10. Re: Selecting objects by fill color
                            Vinicius Baptista Level 2

                            You are welcome Puthoskey, it's always great to be helping i'm glad for that

                             

                            For questions regarding the operation of the code or want to add some more procedure, just call us here.

                             

                            A handshake bro...

                            -Vinícius