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

Illustrator Script to select only dashed strokes?

Community Beginner ,
Sep 26, 2016 Sep 26, 2016

Copy link to clipboard

Copied

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

TOPICS
Scripting

Views

1.8K

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
Valorous Hero ,
Sep 26, 2016 Sep 26, 2016

Copy link to clipboard

Copied

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.

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 ,
Sep 26, 2016 Sep 26, 2016

Copy link to clipboard

Copied

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

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 Beginner ,
Sep 26, 2016 Sep 26, 2016

Copy link to clipboard

Copied

Thank you Monika, this worked perfectly.

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
Valorous Hero ,
Sep 26, 2016 Sep 26, 2016

Copy link to clipboard

Copied

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();

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 Beginner ,
Sep 26, 2016 Sep 26, 2016

Copy link to clipboard

Copied

Silly-V

I could be wrong but it looks like "thisPath.strokeDashes" is expecting an array.

Your snippet did not work for me at first, but I changed "thisPath.strokeDashes" to "thisPath.strokeDashes.length" and it worked extremely well.

Thanks!

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
Valorous Hero ,
Sep 26, 2016 Sep 26, 2016

Copy link to clipboard

Copied

Hmm, it worked for me, but maybe something about my document made it work where as yours did not- regarding it being an array.

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 ,
Sep 27, 2016 Sep 27, 2016

Copy link to clipboard

Copied

Silly,

I tested this and it looks like the data browser shows that "strokeDashes" IS an array, but it only has a single element which is the number (in points) of the dash size as shown here:

Screen Shot 2016-09-27 at 1.49.50 PM.jpg

The default value for these fields is 12 pt, null, null etc. And thus you get a single value in the array.

If you choose to input custom values into those boxes, those values will show up in the array, at which point, your snippet would fail Silly.

Setting the values manually, like this:

Screen Shot 2016-09-27 at 1.53.26 PM.jpg

the result of item.strokeDashes would be: [5,2,5,2], which would cause the statement:

item.strokeDashes > 0

to evaluate to false.

I think the correct answer here is this expression:

if(item.strokeDashes != undefined)

     //item has a dashed stroke

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
Valorous Hero ,
Sep 27, 2016 Sep 27, 2016

Copy link to clipboard

Copied

Yes it looks like when I tested, I only used a single value which worked with a math comparison. Good observation.

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 Beginner ,
Sep 26, 2016 Sep 26, 2016

Copy link to clipboard

Copied

Monika, as I said, your response worked -- the only problem is that I am attempting to run the script with an action, apparently CS6 does not record my choices in the dialog box when I record the action using this script.

Silly-V thanks for the basics on this, this is probably going to end up being a bit more helpful to teach me the building blocks.

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 ,
Sep 26, 2016 Sep 26, 2016

Copy link to clipboard

Copied

You can't permanently include a script in an action.

Only works until shutdown.

In the action panel menu you can include a menu command to run an action. But this might not work with the menu select inside the Extend Select script.

The mention of the action would have been crucial information.

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 ,
Sep 27, 2016 Sep 27, 2016

Copy link to clipboard

Copied

Amen, Monika. Rick, welcome to the club of people pissed off that you can't continuously or reliably append a script to an action..

However, fortunately since you're using CS6, you can do things the other way around. you can attach an action to a script with:

app.doScript('actionName', 'setName');

example: app.doScript('Vignette', 'Default Actions');

so even if the majority of your task is currently done by an action, you can simply run the action from inside the script, then when the action is completed, you can then do whatever script work you were trying to do

However, I would recommend doing as much as you possibly can through javascript rather than an action. Actions cannot do anything conditionally, they either execute every step or throw an error because something unexpected happened.

If you'd like, you could post your steps and desired result and perhaps we can help you translate the whole thing (or at least most of it) to javascript where you'll have much more control over the output.

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
Explorer ,
Mar 07, 2023 Mar 07, 2023

Copy link to clipboard

Copied

  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

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
New Here ,
Mar 23, 2023 Mar 23, 2023

Copy link to clipboard

Copied

LATEST

Thank You!! Worked like a charm!

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