Skip to main content
Participant
December 22, 2016
Answered

Script to delete paths

  • December 22, 2016
  • 2 replies
  • 3748 views

Hello,

I tinker with scripting but I'm nowhere near a pro.

I need an illustrator script that will find all paths that have no stroke, and delete them.

I feel like this script is really close with a little tweaking:

No Stroke No Fill not recognizing

But I'm having trouble tweaking it properly.

Any help is appreciated. Thanks!!

This topic has been closed for replies.
Correct answer zertle

I think this should do it. Good luck!

#target illustrator

// it's best practice to wrap everything in a function

//   so that you don't accidentally mess up any global

//   variables

function RemoveNoStrokePaths() {

  // if there are no documents open then return, otherwise

  //   store a reference to the active document in 'doc'

  if( !app.documents.length ) return;

  var doc = app.activeDocument;

 

  // store a reference to all the PathItems in the active document

  var paths = doc.pathItems;

 

  // Since we might be removing items from the list, the item indices

  //   could change, and so should loop from the last index to the first

  for( var i = paths.length-1; i >= 0; i-- ) {

    

     // get reference to the current PathItem

     var curPath = paths;

    

     // if the PathItem has a stroke assigned, the 'stroked' property

     //   will equal 'true', so if it's false we know that the path

     //   doesn't have a stroke and we can remove it

     if( !curPath.stroked )

          curPath.remove();

   }

}

RemoveNoStrokePaths();

2 replies

zertleCorrect answer
Inspiring
December 22, 2016

I think this should do it. Good luck!

#target illustrator

// it's best practice to wrap everything in a function

//   so that you don't accidentally mess up any global

//   variables

function RemoveNoStrokePaths() {

  // if there are no documents open then return, otherwise

  //   store a reference to the active document in 'doc'

  if( !app.documents.length ) return;

  var doc = app.activeDocument;

 

  // store a reference to all the PathItems in the active document

  var paths = doc.pathItems;

 

  // Since we might be removing items from the list, the item indices

  //   could change, and so should loop from the last index to the first

  for( var i = paths.length-1; i >= 0; i-- ) {

    

     // get reference to the current PathItem

     var curPath = paths;

    

     // if the PathItem has a stroke assigned, the 'stroked' property

     //   will equal 'true', so if it's false we know that the path

     //   doesn't have a stroke and we can remove it

     if( !curPath.stroked )

          curPath.remove();

   }

}

RemoveNoStrokePaths();

Participant
December 22, 2016

Yes!!

Thank you so much.

Loic.Aigon
Legend
December 22, 2016

If you are not confident with scripting, why not use an action script ?

First select some no path object.

Second, create an action

Third, menu/select/same stroke width

Delete

Stop Action recording

On next run, pick a no stroke item, run the action.

I know it's no script and you have to first select some object but you get the job done in a blink