• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Select all items on the entire artboard and delete

Contributor ,
Mar 23, 2020 Mar 23, 2020

Copy link to clipboard

Copied

With js scripting is there away to select all the artboard items.  Means everything text, shapes etc.  and delete?

I tried 

 app.activeDocument.selection = true;

But that didn't do anything.   

TOPICS
Scripting

Views

1.5K

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe
Guide ,
Mar 23, 2020 Mar 23, 2020

Copy link to clipboard

Copied

To select all items:

 

//select all items, by selecting each item individually, thru a loop
for (i = 0; i < activeDocument.pageItems.length; i++) {
  activeDocument.pageItems[i].selected = true;
}

 

To delete all items, without needing to select them:

 

//delete all items
activeDocument.pageItems.removeAll()

 

I use CS6.  I don't know if this works in CC.  For example, I don't need to make app. explicit. 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Mar 24, 2020 Mar 24, 2020

Copy link to clipboard

Copied

wouldnt it be easier to use an action? The script above - will it select locked items? you can create an action that will do it all.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Mar 24, 2020 Mar 24, 2020

Copy link to clipboard

Copied

If the goal is to simply select everything and delete, then an action would do fine. But assuming you only want to delete stuff that's on the artboard (and leave anything on the drawing area alone), an action won't suffice unfortunately. Actions can't conditionally decide what's on the artboard and what isn't.

 

It is possible to use "Insert Menu Item" to hit "Select All On Active Artboard", but if there is more than one artboard, there's no way for an action to decide which is the desired one.

 

Another potential drawback of actions is that I don't believe you can lock/unlock layers with an action. So if there are mutltiple layers in the document and one or more of them are locked, there's no way to unlock them afaik. You could do "Unlock All" via action, but that only works for objects, not layers.

 

The script above does not select or remove locked/hidden art, but the logic required to do so reliably is trivial and the results would be more predictable than with actions.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Mar 24, 2020 Mar 24, 2020

Copy link to clipboard

Copied

LATEST

give this a shot. I'm assuming you mean you want to delete everything in the document. If you only want to delete stuff that's on the artboard, let me know and we can work that in as well. This will ensure that everything is unlocked and visible, and will then delete all pageItems per @femkeblanco's suggestion of the removeAll() method. If you want to leave stuff that's locked/hidden alone, then you can use femkeblanco's second option as it is.

#target Illustrator
//Description: reveal all pageItems and layers, then delete all pageItems
function test()
{
	var docRef = app.activeDocument;
	var layers = docRef.layers;

	for(var l=0,len=layers.length;l<len;l++)
	{
		layers[l].locked = false;
		layers[l].visible = true;
	}

	app.executeMenuCommand("unlockAll");
	app.executeMenuCommand("showAll");

	docRef.pageItems.removeAll();
	
}
test();

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines