Skip to main content
rcraighead
Legend
August 2, 2018
Answered

Select and delete objects by "type" Javascript

  • August 2, 2018
  • 1 reply
  • 1905 views

I am trying to write a Javascript snippet that will select all "Text Objects" and "Brush Objects" on the current document's visible, unlocked layers, then delete the objects.

This thread about "Execute Menu Item" seemed promising, but I could not figure out the proper object names to use. Executing a menu item may not be the most efficient approach anyway.

Can someone help me with this? Thanks.

This topic has been closed for replies.
Correct answer Disposition_Dev

function test()

{

    var docRef = app.activeDocument;

    var sel;

    docRef.selection = null;

    app.executeMenuCommand("Brush Strokes menu item");

    sel = docRef.selection;

    for(var x=sel.length-1;x>=0;x--)

    {

        sel.remove();

    }

    app.executeMenuCommand("Text Objects menu item");

    sel = docRef.selection;

    for(var x=sel.length-1;x>=0;x--)

    {

        sel.remove();

    }

  

}

test();

1 reply

Disposition_Dev
Disposition_DevCorrect answer
Legend
August 2, 2018

function test()

{

    var docRef = app.activeDocument;

    var sel;

    docRef.selection = null;

    app.executeMenuCommand("Brush Strokes menu item");

    sel = docRef.selection;

    for(var x=sel.length-1;x>=0;x--)

    {

        sel.remove();

    }

    app.executeMenuCommand("Text Objects menu item");

    sel = docRef.selection;

    for(var x=sel.length-1;x>=0;x--)

    {

        sel.remove();

    }

  

}

test();

rcraighead
Legend
August 2, 2018

Thank you, William! Works like a charm. Where's the tip jar?

I will study this and see what I can learn for next time.