Skip to main content
Participating Frequently
November 16, 2013
Answered

Illustrator Script code for removing selected items

  • November 16, 2013
  • 2 replies
  • 4901 views

Hello, I have an Illustrator script to go through certain functions and after it runs there are items selected that I need deleted. I cannot figure out the simple script to remove the selected items. I tried

var docSelected = app.activeDocument.selection;

docSelected.selected.remove();

but to no avail. Please help. I would greatly appreciate any tips and suggestions as I just need to know how to have the script to delete selected items. Thank you very much!

This topic has been closed for replies.
Correct answer CarlosCanto

another way...

var docSelected = app.activeDocument.selection;

for (j=0; j<docSelected.length; j++)

    docSelected.remove();

2 replies

CarlosCanto
CarlosCantoCorrect answer
Braniac
November 16, 2013

another way...

var docSelected = app.activeDocument.selection;

for (j=0; j<docSelected.length; j++)

    docSelected.remove();

Inspiring
November 21, 2013

Hi.

How do otherwise, delete the items that are not selected?

pixxxelschubser
Braniac
November 21, 2013

There are many possibilities.

For simple path e.g. like this:

var docItems = app.activeDocument.pathItems;

var docSelection = app.activeDocument.selection;

if (docSelection.length) {

    for ( j=docItems.length-1; j>0; j--) {

        if (!docItems.selected) {

            docItems.remove();

            }

        }

    } else {alert("no selection")}

Have fun

Larry G. Schneider
Inspiring
November 16, 2013

This works

var docSelected = app.activeDocument.selection;

app.cut();