Objects names to a text block
I've got a few thousand object names I need added to a text block. Copy & pasting will take forever. Even exporting them to a text document would work. Is there anything out there to heklp with this?
I've got a few thousand object names I need added to a text block. Copy & pasting will take forever. Even exporting them to a text document would work. Is there anything out there to heklp with this?
Hi @rcraighead . Sorry, I just noticed that if iterating backwards, the loop condition should be i >= 0 or i > -1, i.e. the line should be
for (var i = aDoc.pageItems.length - 1; i > -1; i--) {This is extraneous to the subject of this thread, but forward vs. backward iteration can be summarised like this: When removing items from, or moving items to, the beginning of a collection, forward iteration will cause problems because of indices changing. For example, when removing items, every other item will be skipped. So, say you want to remove all items from a collection (here the array and splice(i, 1) substitute for a collection and remove() in illustrator):
// forward iteration
var a = ["A", "B", "C"];
for (var i = 0; i < a.length; i++) {
a.splice(i, 1);
}
alert( a ); // B"B" was skipped. This breaks down like this
- At iteration 0
a[0] = "A"
a[1] = "B"
a[2] = "C"
The value of a[0], i.e. "A", is removed; "B" becomes a[0]
a[0] = "B"
a[1] = "C"
- At iteration 1
a[0] = "B"
a[1] = "C"
The value of a[1], i.e. "C", is removed; notice that "B" was skipped
a[0] = "B"
- At iteration 2, the condition (i < a.length) is not met and the loop ends
This is solved thus
// backward iteration
var a = ["A", "B", "C", "D", "E", "F", "G"];
for(var i = a.length - 1; i > -1; i--) {
a.splice(i, 1);
}
alert( a ); // empty array
Already have an account? Login
Enter your E-mail address. We'll send you an e-mail with instructions to reset your password.