Skip to main content
rcraighead
Legend
March 6, 2019
Answered

Why does a Locked Item still appear selected after script is run?

  • March 6, 2019
  • 1 reply
  • 335 views

This is the script:

var doc = app.activeDocument;

idoc.selection[0].locked = true;

redraw();

I want to "Lock" the current selection. The script works but does not update the screen, leaving the object appearing still selected.

My workaround is to toggle "Hide Edges" on and off, but that I'm sure that's not the best way to handle the issue.

Your suggestions are appreciated.

This topic has been closed for replies.
Correct answer Silly-V

Set the .selected to false to de-select the item.

But one of the most useful tricks is to first do a loop and push each of the selection elements to your own custom array. This way, you can store the selection and do a 'deselect all' command first (redraw if needed) so that there's no longer a user-selection but you can still affect all the items you wish with actions such as setting their locked state to true.

With scripting it lets us do various operations with bypassing any regular procedures Illustrator does when the user interacts with the UI in normal operation, such as removing all of the document swatches and causing Illustrator to crash because such a state of being is something it can't grapple with (when the vital swatches are gone such as the Registration swatch). Since your locking an item doesn't automatically de-select it, I think the user-operations do an equivalent of several such actions like making sure to de-select all items when they're being locked through the UI.

1 reply

Silly-V
Silly-VCorrect answer
Legend
March 6, 2019

Set the .selected to false to de-select the item.

But one of the most useful tricks is to first do a loop and push each of the selection elements to your own custom array. This way, you can store the selection and do a 'deselect all' command first (redraw if needed) so that there's no longer a user-selection but you can still affect all the items you wish with actions such as setting their locked state to true.

With scripting it lets us do various operations with bypassing any regular procedures Illustrator does when the user interacts with the UI in normal operation, such as removing all of the document swatches and causing Illustrator to crash because such a state of being is something it can't grapple with (when the vital swatches are gone such as the Registration swatch). Since your locking an item doesn't automatically de-select it, I think the user-operations do an equivalent of several such actions like making sure to de-select all items when they're being locked through the UI.