Copy link to clipboard
Copied
I'm trying to achieve the same command as enacted by Object > Path > Outline Stroke.
I can't find any reference to a method for this in the Javascript reference PDF, and you can't trigger menu commands in Javascript.
Applescript allows you to access the menu commands, so I wrote this:
tell application "Adobe Illustrator"
set thisDoc to current document
set locked of layer ("walls") of thisDoc to false
end tell
tell application "System Events"
click menu item "All" of menu "Select" of menu bar item "Select" of menu bar 1 of process "Adobe Illustrator"
click menu item "Outline Stroke" of menu "Path" of menu item "Path" of menu "Object" of menu bar item "Object" of menu bar 1 of process "Adobe Illustrator"
end tell
But it has a very annoying problem: if you run the script form within Illustrator the 'Outline Stroke' command fails. But, if you run the script in the Applescript editor with the illustrator document open it works. Which is just plain weird. If anybody understands why this is the case I'd love to hear the reason (and fix).
If anybody has any ideas for successfully outlining strokes in either Javascript or Applescript please respond.
Thanks,
Barry
Copy link to clipboard
Copied
Since you're using AppleScript why not just make an action to do what you want and call it using the doScript construct. You can also do this in ExtendScript now in CS6.
Copy link to clipboard
Copied
Thanks for replying. Unfortunately, doScript is an InDesign command, it's not available in Illustrator, so I can't trigger a bit of Applescript from my Extendscript (or vice versa).
Copy link to clipboard
Copied
also heard, you can run Menu Commands with CS6
Copy link to clipboard
Copied
Thanks Carlos, from reading the Illustrator scripting guide for Javascript there's no way to trigger menu commands. You can do that in Applescript, but you have to allow access to assistive devices first in order for it to work.
Copy link to clipboard
Copied
This works in both Script Editor and from AI script menu…
tell application "Adobe Illustrator"
activate
tell the current document
set selected of every page item to true
end tell
end tell
tell application "System Events"
click menu item "Outline Stroke" of menu "Path" of menu item "Path" of menu "Object" of menu bar item "Object" of menu bar 1 of process "Adobe Illustrator"
end tell
Copy link to clipboard
Copied
Hi Mark,
Yes, that does work. Unfortunately, it only works if all layers containing objects are unlocked. My problem requires me to outline only the items on certain layers, so I need to pick them off layer by layer.
I've accepted that I'm going to have to trigger my script outside of Illustrator. Not ideal, as the workflow is nicer when you trigger it from within. The only other thing I might try is to trigger a script in AI which then triggers my actual script. Sounds a bit mad, but it could work.
Thanks for your help ![]()
Barry
Copy link to clipboard
Copied
Re-word the object selection…
Copy link to clipboard
Copied
That got me thinking. Did a re-write, and this works:
tell application "Adobe Illustrator"
activate
set thisDoc to current document
set layerRef to layer ("walls") of thisDoc
set locked of layerRef to false
set selected of (every page item of thisDoc whose container is layerRef) to true
end tell
tell application "System Events"
click menu item "Outline Stroke" of menu "Path" of menu item "Path" of menu "Object" of menu bar item "Object" of menu bar 1 of process "Adobe Illustrator"
end tell
Works inside AI too
Cheers
Now if I can just get the SVG export right I'll be sorted.
Copy link to clipboard
Copied
Yup a good old bit of whose filtering does the job… Now whats up with your export…?
Copy link to clipboard
Copied
What I need to do is save the file as a .svg in the same folder as the .ai
So, this works:
set newFilePath to "Macintosh HD:Users:barry:Desktop:test.svg"
export current document to file newFilePath as SVG with options {class:SVG export options, embed raster images:true}
However, I need the file path to dynamically work out where to save the file, as the .ai files will be in different folders across the drive.
Copy link to clipboard
Copied
Update:
Part of the reason for my problems was trying to recursively select objects and then outline them; I've re-written my code to do all the slects together and then outline all of them together.
I've also got the file saving as an svg, but I've got one last problem: the svg being saved is a snapshot of the file *before* the outling takes place. In AI I can see the objects are outlined, but if I open the new svg file, they've been saved as stroked paths. This is my code:
tell application "System Events"
click menu item "Outline Stroke" of menu "Path" of menu item "Path" of menu "Object" of menu bar item "Object" of menu bar 1 of process "Adobe Illustrator"
end tell
set fileDir to replaceString(fileDir, "ai", "svg")
tell application "Adobe Illustrator"
activate
export current document to file fileDir as SVG with options {class:SVG export options, embed raster images:true}
end tell
It seems as though the export is being triggered and completing before the outlining can finish. I've tried adding a 'delay' but that doesn't seem to help. What I need is a callback function, but I'm not sure Applescript or Extendscript support them
![]()
Copy link to clipboard
Copied
Have you tried Saving the file after outlining?
Copy link to clipboard
Copied
I think a manual save after outlining is the answer. Without a callback function there's no way of knowing if the outlining has completed (other than writing a potentially endlessly looping script to check, but that just seems like a good way to cause a crash).
Copy link to clipboard
Copied
You can run menu commands but it looks like only those assigned a shortcut key… Not as useful as I had hoped… In CS6 there is also a new feature to send commands to plug-in… Now you might have some luck with that… but I have had none finding a real world example of how this works… My hope is that someone cracks this with pathfinder and other such plug-ins and posts here… There is one sample in the guides…
string sendScriptMessage (pluginName: string, messageSelector: string, inputString: string)
Sends the script message to the required plugin.
| Parameter | Type | Description |
|---|---|---|
| pluginName | string | Plugin to which message needs to be sent. |
| messageSelector | string | Functionality that is to be executed. |
| inputString | string | Pass any data encoded in a string. |
Get ready! An upgraded Adobe Community experience is coming in January.
Learn more