13 Replies Latest reply on Apr 18, 2016 10:48 AM by williamadowling

    how can i refresh swatches internally in illustrator through jsx ?

    Upendra_sengar Level 2

      I have a problem with illustrator when I loop through all the swatches like for all spot colors it does not provide me all the swatches present in swatche list. But when I reopen the same document then it works fine . its an illustrator bug so I'm thinking that there should be a way to refresh all the swatches internally. Please help trapped in such situation.

        • 1. Re: how can i refresh swatches internally in illustrator through jsx ?
          Silly-V Adobe Community Professional

          What is the code you use for this to happen?

          • 2. Re: how can i refresh swatches internally in illustrator through jsx ?
            williamadowling Level 4

            Definitely would love to have an answer for this as well. Occasionally (although far too often) illustrator seems to be missing information for one or more swatches. (When you step through a loop that merely gets the information of a given swatch, one or more of the swatches will not have any of the standard property information in the data browser, and thus when you try to call it by name, or compare it's name to something, you get a runtime error...)

             

            My reaction is to redefine the document swatches variable to hopefully repopulate the list of doc.swatches. However i'm inclined to think this will do nothing, since the script defines that variable at the beginning, and re-running the script doesn't solve the issue. The only 2 ways i've been able to solve this problem are to save, close and re-open the file, or quit and re-launch illustrator.

             

            An interesting observation i've made is that this problem seems to become more prominent towards the end of the day after i've been taxing the program hard. Restarting illustrator will usually give me more time before i see the error again. This leads me to believe that there's some sort of memory issue relating to some cache that's purged when quitting illustrator..

             

            Vasily, do you know of any such cache and if so, a way to purge that from the script and hopefully negate said memory issues?

            • 3. Re: how can i refresh swatches internally in illustrator through jsx ?
              Silly-V Adobe Community Professional

              Sorry, wish I did. I hate it when that happens, and a few other times when such awesome things happen, in my case pathItems from outlined text - but that's another story.

               

              According to our other older thread, it appears to be a mac-centered issue, as Carlos was able to test your file without the error appearing.

              • 4. Re: how can i refresh swatches internally in illustrator through jsx ?
                williamadowling Level 4

                Well, the problem, and my ultimate frustration, is that the file itself doesn't seem to be a problem. I could run the script on the same file 100 times (closing and re-opening in between) and get no error. Then I'll get the error on the 101st (numbers are made up and totally random).

                 

                I have my production artists send me their files whenever they have an error. We're all on macs, so platform isn't an issue here. On this particular error, I am never able to replicate the issue when i open their file on my machine. And likewise, when i have the error, I will send it to them and have them test the script, and they do not get the error.

                 

                The problem is that the error is so sporadic and not-repeatable. But as OP says, re-opening the same file without making any changes to it at all, seems to do the trick 99% of the time.

                • 5. Re: how can i refresh swatches internally in illustrator through jsx ?
                  Silly-V Adobe Community Professional

                  Yea the best I could do was just go

                   

                  var flag = false, infiniteBreakout = 0;

                  while(!flag && infiniteBreakout < 100){

                       try {

                            //operate on color...

                            flag = true;

                       } catch (e){

                            infiniteBreakout++;

                            doc.close();

                            doc.open();

                       }

                  }

                  • 6. Re: how can i refresh swatches internally in illustrator through jsx ?
                    Qwertyfly... Level 4

                    I would be interested to see the code.

                     

                    It could just be a section of the script that has some not so robust code.

                    I have found I get less errors now days as my codding skills have improved.

                    making sure everything is wrapped in functions and making sure variables a defined correctly solves most issues.

                    others, I have fixed with some validation of variable contents.

                     

                    not saying these are going to solve this particular issue but it may be worth a look.

                    • 7. Re: how can i refresh swatches internally in illustrator through jsx ?
                      Silly-V Adobe Community Professional

                      You know what, I can't speak to the absolute truth of the matter, but with the MRAP errors, I kind-of think that doing thing the right way actually exacerbates the matter. I yearn for empirical evidence though, but it almost seems that having procedural code awkwardly stuck in loops causes less MRAP errors than properly functionalized code. As I said, it would be great to get some real answers from these seemingly random errors. I am especially feeling the heat as my old CS5 scripts made in 2013 are working horribly now in CC2015. It truly does make one a "sad panda". That makes me a sad panda. - YouTube

                      • 8. Re: how can i refresh swatches internally in illustrator through jsx ?
                        Qwertyfly... Level 4

                        i have never been able to reproduce the MRAP / PARM errors consistently enough to test this out.

                        I have found I get less of them with scripts I have rewritten to "conform".

                         

                        certain things will produce an error every time though.

                        it seems to be when you ask illustrator to do something it can't do.

                        ie.

                        app.executeMenuCommand (item);

                        • 9. Re: how can i refresh swatches internally in illustrator through jsx ?
                          williamadowling Level 4

                          Honestly, I would be happy as a clam if my errors were coming from just incorrect usage of a command or an unknown variable. But I'm getting the errors on various color swatches at random intervals without the ability to recreate the problem. In addition to the swatches error i've spoken about, i also occasionally run into an error where I attempt to create a rectangle, apply a fill and set stroke to false. And i'll get a ru

                           

                          errors that repeat everytime are errors that can be tested, narrowed down and eventually solved.

                           

                          I'm just sick of the errors that truly happen at random, and can sometimes be fixed by selecting all the artwork and moving it a random distance in a random direction.... Why on earth would the position of the artwork on the pasteboard have any bearing at all on whether or not illy can properly read the document swatches!?!!!?!??!??!

                           

                          I'm frustrated. =(

                          • 10. Re: how can i refresh swatches internally in illustrator through jsx ?
                            Silly-V Adobe Community Professional

                            Me frustrated too, and also one more thing, I also have a tiny bit of experience which seems to say that CS6 is more stable regarding those.. Like yesterday when my client and I tested same script side by side on CC2015 and CS6, on CS6 it did not occur once. Course, he was also on Windows and I on Mac.

                            • 11. Re: how can i refresh swatches internally in illustrator through jsx ?
                              Upendra_sengar Level 2

                              I found a solution to overcome params error for color swatches. while you traverse through color swatches. you can stringify object and can check whether illustrator error occurred or not in case of swatch just check for [Swatch], and in case of spot color just check for [Spot].

                               

                              function traverseOverSpotColors(){ 
                                   var allSwatches = app.documents[0].spots;
                                    for (var i = 0; i < allSwatches.length; i++) {
                                  try {
                                       if (allSwatches[i].toString() !== "[Spot]") {
                                             //Your code
                                      }
                                  }
                              }
                              

                               

                              Traverse through your all swatches.

                               

                              function traverseOverSwatches(){ 
                                   var allSwatches = app.documents[0].spots;
                                    for (var i = 0; i < allSwatches.length; i++) {
                                  try {
                                       if (allSwatches[i].toString() !== "[Swatch]") {
                                             //Your code
                                      }
                                  }
                              }
                              
                              • 12. Re: how can i refresh swatches internally in illustrator through jsx ?
                                Silly-V Adobe Community Professional

                                Good technique, but I think the bulk of the problem is having to 'force refresh' the document DOM when such an error is found and work must be done which this error prevents.

                                I have encountered this error when opening and closing many files as part of a script batch, but have found that opening every file in the batch at one time and then iterating back through open documents, this error is usually solved.

                                • 13. Re: how can i refresh swatches internally in illustrator through jsx ?
                                  williamadowling Level 4

                                  I've found the same thing, Vasily. The error seems to be directly correlated with the number of files you open/close in a given timespan. The more files you open and close, whether programmatically or manually, the more likely you are to get a PARM or MRAP error.

                                   

                                  I've taken to the same strategy as you (i.e. opening all the files i need to batch and iterating the open files) when possible, but unfortunately many of the errors we get in our workflow happen while we're going through our normal production processes. These parts of the process can't be batched (at least not yet). So what we get is essentially a punishment to those artists who have higher production rates. The faster they are working through their files, the more likely they are to have frequent MRAP errors because they are opening and closing more files in a shorter period of time.