Copy link to clipboard
Copied
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
}
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.
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
This is executed directly from Illustrator (like a normal user).
Copy link to clipboard
Copied
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
} catch(e){
alert(e);
};
};
Does it get the same error?
Which Illustrator version are you using? Which OS?
Copy link to clipboard
Copied
The AI guide suggests wrapping your snytax inside of functions and calling them… to avoid these types of errors…
Copy link to clipboard
Copied
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
}
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.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
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
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
.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
Copy link to clipboard
Copied
I think that is correct, but just wanted input on whether there was something wrong with my loop. Thanks.
I'll try another approach.
Copy link to clipboard
Copied
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.