9 Replies Latest reply on Mar 31, 2016 7:13 AM by Vladimir Miroshnikov

    Intermittent Javascript MRAP error

    baktunatier

      I have a for loop which moves all elements of an "Artwork" layer to a "working" layer so that I can edit the elemets without a chance of affecting the original layer:

       

      for (var i=app.documents[0].layers['Artwork'].pageItems.length-1; i>=0; i--)

      {

                try

                {

                          app.documents[0].layers['Artwork'].pageItems[r].duplicate(app.documents[0].layers['workin g'], ElementPlacement.PLACEATEND);

                }

                catch(e)

                {

                          alert(e);

                }

      }

       

      This seems to work fine for three or four documents, and then begins to return the following error:

       

      Error: an Illustrator error occurred: 1346458189 ('MRAP')

       

      Action on every document then returns this error, even ones on which it has previously worked. The only solution is to quit Illustrator and relaunch.

       

      Am I missing something obvious?

       

      Thanks in advance.

        • 1. Re: Intermittent Javascript MRAP error
          Gustavo Del Vechio Level 3

          Are you running this script via the Extended Script Toolkit application?

           

          Or the error occurs even if you execute directlly from Illustrator (like a

          normal user)?

           

          Gustavo.

          • 2. Re: Intermittent Javascript MRAP error
            baktunatier Level 1

            This is executed directly from Illustrator (like a normal user).

            • 3. Re: Intermittent Javascript MRAP error
              Gustavo Del Vechio Level 3

              If you try:

               

              #target illustrator

              #targetengine main

               

               

              var artwork = app.activeDocument.layers.getByName ("Artwork");

              var items = artwork.pageItems;

              var working = app.activeDocument.layers.getByName ("working");

               

               

              for (var g=0 ; g<items.length ;  g++){

                  try {

                      items[g].duplicate(working, ElementPlacement.PLACEATEND);

                  } catch(e){

                      alert(e);

                  };

              };

               

              Does it get the same error?

              Which Illustrator version are you using? Which OS?

              • 4. Re: Intermittent Javascript MRAP error
                Muppet Mark Level 5

                The AI guide suggests wrapping your snytax inside of functions and calling them… to avoid these types of errors…

                • 5. Re: Intermittent Javascript MRAP error
                  pixxxel schubser Level 5

                  At first:

                  The code that Gustavo Del Vechio has sent is the better one.

                   

                  Your code could also functionate, but there are many syntax errors:

                   

                  for (var i=app.documents[0].layers['Artwork'].pageItems.length-1; i>=0; i--) // here you have defined the counter "i"

                  {

                  try

                  {

                  // here you use a undefined counter "r"

                  // here is a space inside

                  // if you loop backwards, you should use "PLACEATBEGINNING"

                  app.documents[0].layers['Artwork'].pageItems[r].duplicate(app.documen ts[0].layers['working'], ElementPlacement.PLACEATEND);

                  }

                  catch(e)

                  {

                  alert(e);

                  }

                  }

                   

                  In this case your code functionate, too:

                  (But it is really better to use some variables for that)

                   

                  for (var i=app.documents[0].layers['Artwork'].pageItems.length-1; i>=0; i--) {
                      try {
                          app.documents[0].layers['Artwork'].pageItems[i].duplicate(app.documents[0].layers['working'], ElementPlacement.PLACEATBEGINNING );
                          }
                      catch(e)
                      {
                          alert(e);
                          }
                      }
                  

                   

                  Have fun

                   

                   

                   

                   

                   

                  ---

                   

                  Once again:

                  Why you used app.documents[0] ?

                  Do you work with more than one document at the same time?

                   

                   

                  --

                   

                  Message was edited by: pixxxel schubser

                  • 6. Re: Intermittent Javascript MRAP error
                    baktunatier Level 1

                    Sorry, the code is actually contained within a function.

                     

                    You're correct about the typeos, but it doesn't actually appear that way in the code.

                     

                    I've tried PLACEATEND and PLACEATBEGINNING with similar results.

                     

                    I used app.documents[0], app.activeDocument and variables to try to trace the problem. This one is the one I happened to copy.

                    • 7. Re: Intermittent Javascript MRAP error
                      pixxxel schubser Level 5

                      baktunatier wrote:

                       

                      I have a for loop which moves all elements of an "Artwork" layer to a "working" layer so that I can edit the elemets without a chance of affecting the original layer:

                       

                      for (var i=app.documents[0].layers['Artwork'].pageItems.length-1; i>=0; i--)

                      {

                                try

                                {

                                          app.documents[0].layers['Artwork'].pageItems[r].duplicate(app.documen ts[0].layers['working'], ElementPlacement.PLACEATEND);

                                }

                                catch(e)

                                {

                                          alert(e);

                                }

                      }

                       

                      This seems to work fine for three or four documents, and then begins to return the following error:

                       

                      Error: an Illustrator error occurred: 1346458189 ('MRAP')

                       

                      Action on every document then returns this error, even ones on which it has previously worked. The only solution is to quit Illustrator and relaunch.

                       

                      Am I missing something obvious?

                       

                      Thanks in advance.

                       

                       

                      In my opinion the posted code snippet is not responsible for the described error. The code works for me in CS3 and now tested in CS5.

                      For another answer, there is too little information.

                      Sorry

                      1 person found this helpful
                      • 8. Re: Intermittent Javascript MRAP error
                        baktunatier Level 1

                        I think that is correct, but just wanted input on whether there was something wrong with my loop. Thanks.

                         

                        I'll try another approach.

                        • 9. Re: Intermittent Javascript MRAP error
                          Vladimir Miroshnikov

                          Hello

                          Just for anyone who will google for the same problem

                          In my case (also was a huge batch processing with javascript)  I've found the solution by inserting a delay between each iteration:

                           

                          $.sleep(3000);

                           

                          Maybe even less ms delay will work.