As my first attempt with Scriptographer, I've created a very simple script to run through all selected items in document and randomly delete them.
It works like a charm when I first use it, but if I "Undo" after using the script and try running it on the same items again, I run into this error:
Error: The item is no longer valid, either due to deletion or undoing. Use isValid() checks to avoid this error.
Can somebody please explain to me what is happening behind the scenes that causes this error? Very much appreciated! The full code of my script is posted below:
if(document.selectedItems.length) { // Set our starting y point var originY = 100; for (var i=0; i < document.selectedItems.length; i++) { var thisY = document.selectedItems[i].position.y; // Set our random number var randBase = Math.random(); if (randBase > 0.3) { document.selectedItems[i].remove(); } } } else { Dialog.alert('Please selected at least 1 path first'); }