This script works perfectly for increasing the stroke weight of an active selection path item. But there is one drawback. It does not appear to increase the stroke weights on compound paths.
Can anyone please help me make that work on such paths. For instance, if I typeset the letter “O” and created outlines, applied a stroke, and then ran this script, it would not increase the stroke weight.
Please, if someone could get that to work in addition to what it already does that would be fantastic!!!
tell application "Illustrator CS"
tell document 1
set sel to selection
if class of sel is list then
repeat with thisPath in sel
try
if class of thisPath is not text frame and class of thisPath is not group item then
if stroked of thisPath then set stroke width of thisPath to (stroke width of thisPath) + 0.5
else if class of thisPath is text frame then
if class of stroke color of (text of story of thisPath) is not no color info then
tell text of story of thisPath to set stroke weight to stroke weight + 0.5
end if
else if class of thisPath is group item then
set tmp to every path item of thisPath
repeat with thisGroupItem in tmp
if stroked of thisGroupItem then set stroke width of thisGroupItem to (stroke width of thisGroupItem) + 0.5
end repeat
end if
end try
end repeat
else if class of sel is text then
if class of stroke color of sel is not no color info then
tell sel to set stroke weight to stroke weight + 0.5
end if
end if
end tell
end tell
I think that this should do it.
I konw it is not the most elegent way, but it works.
the try is to let the script run in case it is not a compound path.
I used the “of selection” way of specifying the object but you cat try and improve it.
Jeffkrtell application "Illustrator CS"
tell document 1
try
set pathItemList to count every path item of compound path items of selection
if pathItemList > 0 then
set pathWidth to stroke width of (path item 1 of compound path items of selection) as number
if pathWidth > 0 then set stroke width of (path item 1 of compound path items of selection) to (pathWidth + 1)
end if
end try
set sel to selection
if class of sel is list then
repeat with thisPath in sel
try
if class of thisPath is not text frame and class of thisPath is not group item then
if stroked of thisPath then set stroke width of thisPath to (stroke width of thisPath) + 0.5
else if class of thisPath is text frame then
if class of stroke color of (text of story of thisPath) is not no color info then
tell text of story of thisPath to set stroke weight to stroke weight + 0.5
end if
else if class of thisPath is group item then
set tmp to every path item of thisPath
repeat with thisGroupItem in tmp
if stroked of thisGroupItem then set stroke width of thisGroupItem to (stroke width of thisGroupItem) + 0.5
end repeat
end if
end try
end repeat
else if class of sel is text then
if class of stroke color of sel is not no color info then
tell sel to set stroke weight to stroke weight + 0.5
end if
end if
end tell
end tell
Yarnin,
This is the best!!! I am so happy with this. You may claim is not elegant, etc. I don’t know what you mean This is working and working with every parameter I need it to be working on.
Jeff, I don’t know if this will affect your script but also look at unexpanded pathfinder shapes if you have any. Im new to this but they don’t get selected I tested with this sample script. Expand the pathfinder shape and it becomes both a path item and compound path item. May be worth looking out for.
tell application "Illustrator CS"
tell document 1
get count of every path item
set selection to every path item
delay 3
set selection to {}
set selection to every path item of compound path items
delay 3
set selection to {}
end tell
end tell
Mark,
You pointed out a pretty interesting limitation. It would be nice for the script to work on such non expanded pathfinder created items. Although it is a limitation I could live with for now. For our work purposes, I usually preach to expand upon creating such items. The two most common pathfinder functions we use are “Add to Shape Area” and “Exclude Overlapping Shape Areas.” Until a fix is discovered I will just reinforce the fact that they should be expanding via “option” when performing such functions.
Jeff, I think I will need to do the same for the time being. Adding these 2 lines selects the objects as class plugin items, but I see no way to modify the properties of these. I have a lot to learn with this yet.
tell application "Illustrator CS"
tell document 1
get count of every path item
set selection to every path item
delay 3
set selection to {}
set selection to every path item of compound path items
set properties of every path item of selection to {stroke width:3}
delay 3
set selection to {}
set selection to every plugin item
get properties of every plugin item
end tell
end tell
I think it is posible to get to every path item in any document.
the thing is that i need to know if to restrict it to selected objects only,
or it is OK to run it over every item in the document?
I will try to work it out, tomorrow. but I need your answer.
Here’s the original script modified to handle compound path items (which is a lot like yarnin’s just within the current testing block):
tell application "Adobe Illustrator"
tell document 1
set sel to selection
if class of sel is list then
repeat with thisPath in sel
try
if class of thisPath is not text frame and class of thisPath is not group item and class of thisPath is not compound path item then
if stroked of thisPath then set stroke width of thisPath to (stroke width of thisPath) + 0.5
else if class of thisPath is text frame then
if class of stroke color of (text of story of thisPath) is not no color info then
tell text of story of thisPath to set stroke weight to stroke weight + 0.5
end if
else if class of thisPath is group item then
set tmp to every path item of thisPath
repeat with thisGroupItem in tmp
if stroked of thisGroupItem then set stroke width of thisGroupItem to (stroke width of thisGroupItem) + 0.5
end repeat
else if class of thisPath is compound path item then
set subPaths to path items of thisPath
repeat with thisSubPath in subPaths
if stroked of thisSubPath then set stroke width of thisSubPath to (stroke width of thisSubPath) + 0.5
end repeat
end if
end try
end repeat
else if class of sel is text then
if class of stroke color of sel is not no color info then
tell sel to set stroke weight to stroke weight + 0.5
end if
end if
end tell
end tell
Yarnin,
This would have to work on only “selected” objects, no matter if they are grouped or not. (You get this to work, I will be amazed)
Funny, I am missing something here? I don’t know why Illustrator doesn’t offer this keyboard shortcut? Or is it because of all these nuances that make it too difficult to develop?
this should work.
I don’t know to which extent though.
what you need to do is to assign a keyboard shortcut to the “Expand Appearance” in Illustrator.
then to formate the script to the same shortcut - now it is: “keystroke “1” using command down & shift down”
under the the “tell System Events” line.
the delete line is to remove the unneaded group.
see if it works for you and let me know.
tell application "Illustrator CS"
tell document 1
try
set pathItemList to count every path item of compound path items of selection
if pathItemList > 0 then
set pathWidth to stroke width of (path item 1 of compound path items of selection) as number
if pathWidth > 0 then set stroke width of (path item 1 of compound path items of selection) to (pathWidth + 1)
end if
end try
if class of selection is plugin item then
activate
tell application "System Events"
keystroke "1" using command down & shift down
end tell
set selection to selection
set tt to every group item of selection
set rr to path item 1 of first item of tt
if stroked of rr then set stroke width of rr to (stroke width of rr) + 3
delete last item of tt
end if
set sel to selection
if class of sel is list then
repeat with thisPath in sel
try
if class of thisPath is not text frame and class of thisPath is not group item then
if stroked of thisPath then set stroke width of thisPath to (stroke width of thisPath) + 0.5
else if class of thisPath is text frame then
if class of stroke color of (text of story of thisPath) is not no color info then
tell text of story of thisPath to set stroke weight to stroke weight + 0.5
end if
else if class of thisPath is group item then
set tmp to every path item of thisPath
repeat with thisGroupItem in tmp
if stroked of thisGroupItem then set stroke width of thisGroupItem to (stroke width of thisGroupItem) + 0.5
end repeat
end if
end try
end repeat
else if class of sel is text then
if class of stroke color of sel is not no color info then
tell sel to set stroke weight to stroke weight + 0.5
end if
end if
end tell
end tell
Yarnin,
I appreciate you looking into this. I am receiving an error on the following type of object I create and select:
Create a box with a 1 pt. fill, duplicate it with another and overlap. Select both boxes and apply the Pathfinder function: “Add To Shape Area” without holding option.
Selecting this “non expanded” compound path and running this script will error out on this line:
set tt to every group item of selection
With the error:
“Illustrator CS got an error: Can’t get every group item of selection of document 1.”
As for the system events and the keyboard shortcut for expanding objects, I wonder how this will work. I say this only because when I use this menu item an additional dialog box appears which asks me to expand fills or strokes. (The default would probably work using “fill and stroke” but would this require another system events asking for a “Return” keyboard motion?
FWIW, I am very pleased with you fix as is in your prior post. Having to expand such shapes prior to increasing the stroke weight will be extremely uncommon. I just don’t want you to spend too much of your valuable time trying to develop this.
Yarnin,
I am very sorry for not reading your past post correctly. After assigning the proper keyboard shortcut the script is real close to working perfectly, but with one minor issue.
When I perform the script on objects like those mentioned in my prior post, the script does expand them but the Applescript generates this error:
Can’t get item 1 of {}.
This line is highlighted: set rr to path item 1 of first item of tt
But the good news is, as soon as that error is done with the script will work perfectly. So if I were to embed this script in a Quickey, I could fix the issue without any need to fix the code (by telling the Quickey to stop shortcut without a warning). The subsequent Quickey clicks would then work and increase the stroke. But it would be nice to have the fix in the Applescript.
Sorry for taking so long to get back to you. Busy day for me here at work
that should be easy to fix.
Add a try statement.
The try should be after the “set selection to selection”
and the end try shoul be after the delete line.
so in any case of an error the script will go on without the need to rerun it.
Yarnin,
If you are still up for a challenge, I do have one. What I never realized after all this time was that I was only testing this script on one letter of text created to outlines. I never tested an entire line of text created to outlines. (Such a group of compound path items does not work with this script). Your last posted script will work on a single compound path item, such as the letter “e” created to outlines.
I am not so concerned about a shapes non expanded via the use of a Pathfinder function). (Those are rare instances, at least in our workflow)
With that in mind, you last post was practically dead on.
But our operators often take a headline to text, create outlines, and then modify the stroke. (So it would be nice if this parameter worked)
I have tried and tried, hacking away at your last post. looking at the event log, etc. But this is complicated. I don’t know if this is possible? All I know is that I am years away from being able to solve this myself
I hope this will do it.
I post 2 scripts.
the first one is just the part taking care of the objects in a selection created after converting text box to outline.
the second one is the long - all in one - script.
in bouth scripts I added 2 functions. one to check if ther is any selection and the second to let you choose the increment of the paths width.
in the - all in one - I set it to ungroup a cumpoung item in to a path.
I hope it will work fine for you
tell application "Illustrator CS"
(* Check for selection Objects *)
if number of items in selection is 0 then
display dialog "No item is selected." & return & "Please select an item and try again." buttons {"OK"} default button 1
error number -128
end if
display dialog "set stoke width increment" default answer "0.5" buttons {"OK", "Cancel"} default button 1
copy the result as list to {text_returned, button_pressed}
if button_pressed is "Cancel" then
error number -128
else
set Add_2_Width to text_returned as number
end if
set ItemsinSelection to number of every compound path item of selection
repeat with x from 1 to ItemsinSelection
set theItem to path item 1 of compound path item x of selection
if stroke width of theItem > 0 then set (stroke width of theItem) to (stroke width of theItem) + Add_2_Width
end repeat
end tell
tell application "Illustrator CS"
(* Check for selection Objects *)
if number of items in selection is 0 then
display dialog "No item is selected." & return & "Please select an item and try again." buttons {"OK"} default button 1
error number -128
end if
(* set stoke width increment *)
tell document 1
display dialog "set stoke width increment" default answer "0.5" buttons {"OK", "Cancel"} default button 1
copy the result as list to {text_returned, button_pressed}
if button_pressed is "Cancel" then
error number -128
else
set Add_2_Width to text_returned as number
end if
(* plugin item *)
if class of selection is plugin item then
activate
tell application "System Events"
keystroke "1" using command down & shift down
end tell
set selection to selection
try
set tt to every group item of selection
delete last item of tt
tell application "System Events"
keystroke "g" using command down & shift down
keystroke "g" using command down & shift down
end tell
end try
end if
try
(* text box converted to outline *)
set ItemsinSelection to number of every compound path item of selection
repeat with x from 1 to ItemsinSelection
set theItem to path item 1 of compound path item x of selection
if stroke width of theItem > 0 then set (stroke width of theItem) to (stroke width of theItem) + Add_2_Width
end repeat
end try
if class of selection is compound path item then
set theItem to first path item of selection
if stroke width of theItem > 0 then set (stroke width of theItem) to (stroke width of theItem) + Add_2_Width --end try
end if
set sel to selection
if class of sel is list then
repeat with thisPath in sel
try
if class of thisPath is not text frame and class of thisPath is not group item then
if stroked of thisPath then set stroke width of thisPath to (stroke width of thisPath) + Add_2_Width
else if class of thisPath is text frame then
if class of stroke color of (text of story of thisPath) is not no color info then
tell text of story of thisPath to set stroke weight to stroke weight + Add_2_Width
end if
else if class of thisPath is group item then
try
set pathItemList to count every path item of compound path items of selection
if pathItemList > 0 then
set pathWidth to stroke width of (path item 1 of compound path items of selection) as number
if pathWidth > 0 then set stroke width of (path item 1 of compound path items of selection) to (pathWidth + Add_2_Width)
end if
end try
set tmp to every path item of thisPath
repeat with thisGroupItem in tmp
if stroked of thisGroupItem then set stroke width of thisGroupItem to (stroke width of thisGroupItem) + Add_2_Width
end repeat
end if
end try
end repeat
else if class of sel is text then
if class of stroke color of sel is not no color info then
tell sel to set stroke weight to stroke weight + Add_2_Width
end if
end if
end tell
end tell
It is difficult to tell you the following because your script would have worked as you designed it. What I failed to mention was that I am using this script repetitively. This will allow the user to increase the stroke weight on the fly with multiple clicks of a keyboard shortcut assigned to this script which I will embed in a Quickey. Therefore I don’t desire the dialog box that prompts the user. Instead it would be preferred to always add .5 to a preexisting stroke wieght. So I commented out this dialog box leaving the line:
set Add_2_Width to 0.5
With that in mind, the script still has one issue. But maybe there is a simple fix, such as rearranging the order? I haven’t looked at it myself, but I am rather useless in my scripting abilities so I thought I would seek your guidance, for you may have a quick fix???
The issue is when there is a single letter of type created to Outlines. The script is adding .5 twice.
This is the ONLY thing remaining. You have every other parameter covered. I am very impressed. And for its worth, you have supplied many crucial code lines that I surely will be able to implement into other scripts in the future. Not sure what they will be? But it is good to know these workarounds with compound paths.
I reciently wrote a script to set overprints, and needed to expand appearance. Rather than adding keyboard shortcuts I just wrote the following line for system events line and added it into my Illustrator tell statement where needed:
tell application "System Events" to tell process "Illustrator CS" to tell menu bar 1 to tell menu bar item "Object" to tell menu "Object" to click menu item "Expand Appearance"
Thank you Jerome,
I do prefer avoid using system events when possible. (But I more so like saving the assigned keyboard shortcut”and the prevention of someone using it outside of the script without knowing)
It is nice when everything is happening all from within the script.