Undo in Illustrator CS3

I wrote a simple applescript to replace names of layers in Illustrator. It works great and thanks to Applescript studio, it has a better interface than the Java script we were using until recently. The Java script was made to run from within Illustrator via File > Scripts > Other Scripts…

Just like the Java script, the applescript loops through all layers and renames them. However, when the javascript does it, it only adds one undo. With the applescript, every renamed layer comes in as an undo, very quickly making us run out of undo’s.

Is there a way to change properties of many layers in an applescript so it only comes in as one undo?

That depends on what the criteria for renaming the layers. Two potential options are:

tell application "Adobe Illustrator"
	tell document 1
		set x to name of layers 1 through 2
		set name of layers 1 through 2 to "Test This" --renames the top two layers in the stacking order
		set name of (every layer whose name contains "Layer") to "Test"--renames any layer with "Layer" in it's name to Test
	end tell
end tell

I see, so the idea is to avoid a loop.

Unfortunately, I’m renaming the layers as “New Name 01” , “New Name 02” … I’m guessing you can only do that with a repeat-loop.

It looks like you are stuck with looping through the layers, it would be interesting to see how the javascript does it with only one undo. Is there something in the code or is it in the way the JavaScript is handled by the program.

Well, the Javascript uses a loop too. The only difference I can think of is that the Javascript runs from within Illustrator, the Applescript is a standalone application.

Thanks for the help, there’s few scripts I should be able to optimise with your pointers.