Skip to main content
pixxxelschubser
Community Expert
Community Expert
December 23, 2021
Question

[JS] [Action] Split or break a dashed line into separate (real) lines by script

  • December 23, 2021
  • 33 replies
  • 11915 views

Illustrator does not offer a direct way to convert dashed lines (e.g. for cutting plotters or CNC engraving).

 

Please do not reply to suggest the way to set the outline thickness to a very small value e.g. 0.0001pt. This way still creates filled rectangles and not real lines and is therefore unsuitable.

 

I also know some existing scripts that try to redraw the dash line. Unfortunately, these scripts are not an option either, because the results sometimes differ from the originals.

 

For several years I have used the manual way to break up a dashed line into single (real) lines:
- select the dashed line
- (optionally) create a duplicate and turn off the visibility of the original
- draw a horizontal straight line (helper object)
- remove the dash line attribute from the straight line (helper object)
- create an artbrush from this line (option: Artbrush, no further options, usually just confirm twice)
- delete the line (helper object)
- assign the newly created brush to the original dashed line (or its duplicate)
- use the menu command Object --> Expand Appearance
- ungroup two times
- group the selection and name the group as desired
- delete the artbrush

 

Since this process is rare, but needs to be done over and over again, I wanted to create a script.

Unfortunately there is a problem. Adobe Extendscript cannot be used to create or delete a brush. But it is possible to create a brush with an action. This action can be included in a script. But this way always needs additional confirmations by the user:

- select the option: Artbrush
- confirmation of the selection with [OK]
- confirming the options dialog with [OK] (usually without further settings)

 

 

Question: Does anyone know a way to create an art brush via script or action without additional user interaction (and delete it afterwards)?

 

-------------------------------------------------------------------------------------------

For those interested, here is an example action to create a brush in text form:

 

/version 3
/name [ 16
	63726561746544756d6d794272757368
]
/isOpen 1
/actionCount 1
/action-1 {
	/name [ 16
		63726561746544756d6d794272757368
	]
	/keyIndex 0
	/colorIndex 0
	/isOpen 1
	/eventCount 1
	/event-1 {
		/useRulersIn1stQuadrant 0
		/internalName (ai_plugin_brush)
		/localizedName [ 6
			50696e73656c
		]
		/isOpen 1
		/isOn 1
		/hasDialog 0
		/parameterCount 1
		/parameter-1 {
			/key 1835363957
			/showInPalette -1
			/type (enumerated)
			/name [ 12
				4e657565722050696e73656c
			]
			/value 1
		}
	}
}

 

Many thanks in advance.

 

This topic has been closed for replies.

33 replies

Kurt Gold
Community Expert
Community Expert
December 24, 2021

I think there are some good news, pixxxelschubser.

 

A flying reindeer just knocked at my window and told me that I should take a look at my actions archive. There should be something less bumpy. And indeed, I knew that I once made an action that converts dashed lines into separate stroked lines without using any helper objects.

 

You can download it here:

 

[Link to wrong files removed]

 

The .zip file contains a sample Illustrator file (dashed_lines_sample_001.ai) and an action set file (dashed_lines_nipper.aia).

 

- Open dashed_lines_sample_001.ai
- In the Actions palette import the action set file
- Select all objects
- Run the action

 

Give it a try.

 

pixxxelschubser
Community Expert
Community Expert
December 24, 2021

Hello Kurt,

Thank you for your answer.

 

This variant would certainly be possible. However, I generally try to create actions or scripts as independent of additional files as possible. This way the scripts can be used on different computers and you don't have to worry about additional (necessary) files.

 

Maybe I also have to describe the initial situation a bit more detailed:
Basically, any artbrush (from a simple straight line) is suitable for conversion. But unfortunately another artbrush changes the properties of the stroke line. And in every delivered file there are differences. Although it would have no effect in the final file, there is a default that the attributes must remain the same. (The saved file is later matched with the original file).

While you could reassign the attributes in the script with a loop over each of the split small lines, any unnecessary loop is a performance killer. It's faster if you already assign the attributes to the straight line that serves as the base for the artbrush, as shown above.

 

Have a great holiday season to you and everyone else.

Translated with DeepL.com/Translator (free version)

Kurt Gold
Community Expert
Community Expert
December 24, 2021

One way is to use an additional helper document (helper_brush_001.ai) that contains just one object to which the helper brush (dashes_helper_001) is applied.

 

Given that you have opened just one document with a couple of dashed lines, you can take the following route.

 

 

Of course, depending on the contents of your files, the action will have to be modified.

 

Admittedly, a bit bumpy, but it works.