Skip to main content
New Participant
September 26, 2016
Answered

Illustrator Script to select only dashed strokes?

  • September 26, 2016
  • 3 replies
  • 4728 views

I am fairly new to Illustrator scripting, although I do have moderate experience with JavaScript.

I am trying to come up with a simple script that will just select all objects in the document that have a dashed stroke, regardless of any other attributes.

Many people have suggested downloading the 3rd-party .aip plugin for this from Graffix, but I am unable to get it to work in CS6 for some reason.

Can anyone walk me through the basics of how I might do this?

Thanks,

-Rick

This topic has been closed for replies.
Correct answer __Alain__
  1. Open a Texteditor like Notepad
  2.  Import this 

 

// Selects all dashed lines in the current document
var doc = app.activeDocument;
var dashedLines = [];

// Loop through all page items in the document
for (var i = 0; i < doc.pageItems.length; i++) {
  var item = doc.pageItems[i];
  // Check if the item is a path
  if (item.typename == "PathItem") {
    // Check if the stroke is dashed
    if (item.strokeDashes != null && item.strokeDashes.length > 0) {
      // Add the item to the list of dashed lines
      dashedLines.push(item);
    }
  }
}

// Select all the dashed lines
doc.selection = dashedLines;​

 

  •  Save the file as for example: select-dashed-lines.jsx
  •  Open Illustrator
  •  Open the file you want to select the dashed lines
  •  Hit Ctrl-F12
  •  Select "select-dashed-lines.jsx", wait and you will smile 🙂

 

This has been done with the help of openAI

 

Kind regards

Alain

3 replies

__Alain__
__Alain__Correct answer
Inspiring
March 7, 2023
  1. Open a Texteditor like Notepad
  2.  Import this 

 

// Selects all dashed lines in the current document
var doc = app.activeDocument;
var dashedLines = [];

// Loop through all page items in the document
for (var i = 0; i < doc.pageItems.length; i++) {
  var item = doc.pageItems[i];
  // Check if the item is a path
  if (item.typename == "PathItem") {
    // Check if the stroke is dashed
    if (item.strokeDashes != null && item.strokeDashes.length > 0) {
      // Add the item to the list of dashed lines
      dashedLines.push(item);
    }
  }
}

// Select all the dashed lines
doc.selection = dashedLines;​

 

  •  Save the file as for example: select-dashed-lines.jsx
  •  Open Illustrator
  •  Open the file you want to select the dashed lines
  •  Hit Ctrl-F12
  •  Select "select-dashed-lines.jsx", wait and you will smile 🙂

 

This has been done with the help of openAI

 

Kind regards

Alain

emilym8260986
New Participant
March 23, 2023

Thank You!! Worked like a charm!

Monika Gause
Brainiac
September 26, 2016

In case the dashes are set up differently and you can't get the aip to work, try: Arid Ocean - ExtendedSelect Script

RickShagAuthor
New Participant
September 26, 2016

Thank you Monika, this worked perfectly.

Silly-V
Brainiac
September 26, 2016

If you want to explore javascript for yourself, see this snippet:

function test(){

  var doc = app.activeDocument, thisPath;

  for(var i=0; i < doc.pathItems.length; i++){

    thisPath = doc.pathItems;

    if(thisPath.strokeDashes > 0 ){

      thisPath.selected = true;

    }

  };

 

};

test();

Silly-V
Brainiac
September 26, 2016

You can try to work with "select same appearance" or same graphic style commands, if your document has stroked items which are the same appearance as far as strokes go.