Hollow Road Script

Having difficulty finding these definitions, in other words, I don’t know where to start.
I am looking for a script to create hollow map roads with no fills in Illustrator CS.
The script would begin with the below script, converting certain strokes with no fills to a 10 pt. stroke.
At that point I want the script to apply Object>Path>Outline Stroke
Then apply a no filled 1 pt black stroke (0,0,0,100).
Then choose Pathfinder>Add to Shape Area with Expand applied.
Then finally a try to Ungroup.

I can do the second part to work with actions. So if there is a way for an AppleScript to target an action in Illustrator, that would work as well?

Can any give me some advice or help with this?

Thanks,

jeff

tell application "Illustrator CS"
	activate
	tell document 1
		set X to (every path item whose stroke width < 2.25)
		repeat with i in X
			if (stroke width of i > 0.75) then
				if filled of i is false then
					set stroke width of i to 10
				end if
			end if
		end repeat
	end tell
end tell

I thought that using system events may have helped me here. I assigned the Illustrator Action “Cmd-Shift-F9”.
Unfortunately this part of the script isn’t accessing the Action in Illustrator. Does anyone know what is wrong with the System Events part of this script.

tell application "Illustrator CS"
	activate
	tell document 1
		set X to (every path item whose stroke width < 2.25)
		repeat with i in X
			if (stroke width of i > 0.75) then
				if filled of i is false then
					set stroke width of i to 10
				end if
			end if
		end repeat
	end tell
	tell application "System Events" to keystroke "F9" using {command down, shift down}
end tell

Jeffkr,

This is what I came up with. I tried this on a simple curving line in Ill. This uses UI scripting. I was having problems with setting the fill color after the path conversion until I used the get properties command. Through this I realized that something was getting grouped in the process. This works on my machine.

tell application "Illustrator CS"
	activate
	set selection to path item 1 of current document
	set properties of selection to {stroke width:7}
	tell application "System Events"
		tell process "Illustrator CS"
			tell menu bar 1
				click menu item "Outline Stroke" of menu "Path" of menu item "Path" of menu "Object" of menu bar item "Object"
			end tell
		end tell
	end tell
	set selection to path item 1 of current document
	get properties of selection
	set thePaths to every path item of selection
	repeat with anItem in thePaths
		set fill color of anItem to {class:no color info}
		set stroke color of anItem to {class:CMYK color info, cyan:0, magenta:0, yellow:0, black:100}
		set stroke width of anItem to 1
	end repeat
end tell

Hope this helps.

PreTech

Model: dual 1.8 G5
AppleScript: 2.1 (80)
Browser: Safari 412.5
Operating System: Mac OS X (10.4)

You’re telling it to “press” the letter F, then “press” the number 9. Try this instead:

tell application "System Events" to key code 101 using {command down, shift down}

See also: Key Codes

Hi Pretech,
This works OK. But it appears to only when there is one stroke/line on a document. I really need it to work on overlapping strokes. btw, the result should not leave strokes appearing to overlapping. So a road pattern that resembled a “plus” sign character should appear as an outlined “plus” sign when finished with the script.
Also, I was hoping it could only work on selected strokes, and not effect strokes that had a fill. This would negate any road signs that may have accidentally been selected by an operator.

Bruce, I am going to try your code in just a minute.

Thank you both for helping me out.

Bruce,
That worked, I can’t believe it!. Thank you for the advice and link to that helpful application.

Jeffkr,

My previous script just had it select the first path item in a document. This script should select all stroked path items. However, I don’t know how to combine two intersecting path items into one object without using the Pathfinder pallette and as far as I know the pallettes are not scriptable. I looked in the CS scripting guide but couldn’t find anything about this (not that that means you can’t do it). The best I can do right now is this.

tell application "Illustrator CS"
	activate
	set selection to every path item of current document whose filled is false
	set t to selection
	set properties of selection to {stroke width:10}
	tell application "System Events"
		tell process "Illustrator CS"
			tell menu bar 1
				click menu item "Outline Stroke" of menu "Path" of menu item "Path" of menu "Object" of menu bar item "Object"
			end tell
		end tell
	end tell
	set thePaths to every path item of t
	repeat with anItem in thePaths
		set fill color of anItem to {class:no color info}
		set stroke color of anItem to {class:CMYK color info, cyan:0, magenta:0, yellow:0, black:100}
		set stroke width of anItem to 1
	end repeat
end tell

Hope this gets you closer. I’ll keep looking into the combining of the elements though.

PreTech

Jeffkr,

Sorry Jeffkr, I have just realized that the above script needs some serious work. It actually only completes making the stroke width the size you want and then outlining the paths. Beyond that it is not working. I’ve been trying to work this out. I’ll keep at it.

PreTech

Thanks PreTech.
No problem, I simply appreciate you trying to figure this out. I must be honest, without the Pathfinder I can’t see how this would work either :frowning:
That is why I have the script calling an Action. Obviously calling an action is not preferred, but I can’t see an alternative?
Btw, I have utilized one of your other scripts from another post and combined it to work with this. Let me point out that I was overly ambitious in trying to have the script trying to Not perform on selected strokes that had a fill. In hindsight that was bad logic. Because so often when building a map, the lines used are the default white fill and black stroke yet never noticed by an operator. So it actually helps for these to be converted via the script.
In conjunction with my Action this is working as planned. An operator manually selects the paths he/her wants affected and it does its thing. Luckily we are only working with very simple maps, only 4 or 5 roads maximum.

Btw, does AppleScript offer anything like javascripts scriptlistener code that can record such non defined actions such as the Pathfinder functions?

Once again, many thanks for all of your hard work.

tell application "Illustrator CS"
	activate
	tell document 1
		set sel to selection
		set thePaths to sel
		repeat with anItem in thePaths
			set fill color of anItem to {class:no color info}
			set stroke color of anItem to {class:CMYK color info, cyan:0, magenta:0, yellow:0, black:100}
			set stroke width of anItem to 1
		end repeat
		repeat with thisPath in sel
			try
				if stroked of thisPath then set stroke width of thisPath to 10
			end try
		end repeat
	end tell
end tell
tell application "System Events" to key code 101 using {command down, shift down}

Jeff, not a fix for you but you can also call your action like this.

tell application "Illustrator CS"
	set docRef to the current document
	do script "Jeffs Path Action" from "Jeffs Actions" without dialogs
end tell

Mark,
Actually this is fantastic. You just saved me from assigning a keyboard shortcut. (A good thing when practically all are already taken)
Thanks a lot.
-jeff