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

Is it possible in Extendscript/Javascript to 'Outline Stroke' a path

Community Beginner ,
Apr 19, 2013 Apr 19, 2013

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

TOPICS
Scripting
5.0K
Translate
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
Adobe
LEGEND ,
Apr 19, 2013 Apr 19, 2013

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.

Translate
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 ,
Apr 22, 2013 Apr 22, 2013

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).

Translate
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 ,
Apr 19, 2013 Apr 19, 2013

also heard, you can run Menu Commands with CS6

Translate
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 ,
Apr 22, 2013 Apr 22, 2013

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.

Translate
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
Mentor ,
Apr 22, 2013 Apr 22, 2013

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

Translate
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 ,
Apr 22, 2013 Apr 22, 2013

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

Translate
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
Mentor ,
Apr 22, 2013 Apr 22, 2013

Re-word the object selection…

Translate
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 ,
Apr 22, 2013 Apr 22, 2013

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.

Translate
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
Mentor ,
Apr 22, 2013 Apr 22, 2013

Yup a good old bit of whose filtering does the job… Now whats up with your export…?

Translate
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 ,
Apr 22, 2013 Apr 22, 2013

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.

Translate
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 ,
Apr 22, 2013 Apr 22, 2013

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

Translate
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
LEGEND ,
Apr 22, 2013 Apr 22, 2013

Have you tried Saving the file after outlining?

Translate
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 ,
Apr 23, 2013 Apr 23, 2013
LATEST

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).

Translate
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
Mentor ,
Apr 22, 2013 Apr 22, 2013

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.

ParameterTypeDescription
pluginNamestringPlugin to which message needs to be sent.
messageSelectorstringFunctionality that is to be executed.
inputStringstringPass any data encoded in a string.
Translate
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