Can somebody PLEASE help me out here?
I would love to have this javascript converted to AppleScript. Problem is, Illustrator CS upon restart doesn’t hold actions that are assigned to a Quickey. But if this were in Applescript, I could then embed it in the Quickey and hopefully that would do the trick?
The script is designed to change a stroke width by .5 pt increments. (a keyboard shortcut, I am surprised doesn’t exist). I will obviously need one to decrease by .5 pt increments as well, but that should be easy to modify.
If someone could solve this dilemma, it would be appreciated beyond belief.
Don’t know if this is what you’re looking for but here it goes.
tell application "Illustrator CS"
activate
set thisDoc to current document
tell thisDoc
set theItems to every page item
repeat with theItem in theItems
if selected of theItem is true then
set strokeWidth to stroke width of theItem
set properties of theItem to {stroke width:(strokeWidth + 0.5)}
end if
end repeat
end tell
end tell
I tried setting a variable to page item whose stroked is true but was running into problems with that line. I’ll see if I can streamline it some. Meanwhile someone else will probably get something that will work a little quicker.
PreTech
P.S. This will run into problems if the selected item is text or a group item. You’ll have to add code for these situations.
Pretech,
This is definitely a plus, and it is on the right track. Having it increase the stroke widths of a selected group would be preferred.
Unfortunately, I still don’t know enough to include that group parameter. So if anyone could join in that would be much appreciated.
Regardless, this is great and I am very grateful for your help.
Thanks,
jeff
tell application "Illustrator CS"
activate
set thisDoc to current document
tell thisDoc
set theItems to every group item
set itemCount to count theItems
display dialog itemCount
repeat with i from 1 to itemCount
if selected of page item i is true then
set theItem to page item i
get properties of theItem
if class of theItem is not (group item) then
set strokeWidth to stroke width of theItem
set properties of theItem to {stroke width:(strokeWidth + 0.5)}
else
move every path item of selection to beginning of layer "Layer 1"
set gItems to every page item of layer "Layer 1"
repeat with newItem in gItems
set strokeWidth to stroke width of newItem
set stroke width of newItem to (strokeWidth + 0.5)
end repeat
end if
end if
end repeat
end tell
end tell
This will do group items (as long as there is no text) and single path items. If you need this to work for text, that can be arranged.
PreTech
P.S. Forgot to say that the move every path item line ungroups the grouped item. I have not figured out how to regroup selected items. Don’t know if it’s possible. I can make new items and put them in a group but grouping existing items is another question.
Pretech, I really appreciate you looking into this. This script did throw up a dialog box, returning a 0 for one selected object, and no result. So it seems to only work on a selection of grouped paths. Oddly when I activated the script was giving me an error saying:
Adobe Illustrator CS got an error: Can’t get stroke width of text frame 1 of layer 1 of document 1.
Yes, my mistake, I did have text on the document, but it wasn’t selected (I thought that is what you meant). But it dawned on me, after removing the text and selecting a grouped object, the script worked but it affected all the paths on the document, not just the selected ones?
Unfortunately I do need the script to work on grouped and non grouped objects and only the selected paths. And it has to work with text appearing somewhere else on the document. But it doesn’t have to work on stroked text, the javascript doesn’t do that either.
Now for some bad news:
I did give out false information before. The javascript, targeted by a Quickey will hold even after a restart.
But that is not to say I wouldn’t rather have an Applescript. It is nice to have everything unified into one Quickey. And javascripts cannot be embedded into the Quickey the way AppleScripts can. Well, at least with the version of Quickeys I am using.
Sorry Jeff, I posted this too quickly. I’ll look into it more in the morning unless someone posts a solution before that. I have it set to iterate only through the grouped items. Now strangely it doesn’t work on my computer even for just the grouped item. I’ll figure it out.
As usual I made this harder than it needs to be. You do not have to ungroup a grouped set of path items in order to perform some action on the elements. So here is another try.
tell application "Illustrator CS"
activate
set thisDoc to current document
try
set pathItems to every path item of thisDoc
on error
display dialog "There are no path items in this doc." giving up after 2
end try
set cnt to count pathItems
repeat with anItem in pathItems
if selected of anItem is true then
set strokeWidth to stroke width of anItem
set properties of anItem to {stroke width:(strokeWidth + 0.5)}
end if
end repeat
try
set textItems to every text frame of thisDoc
on error
display dialog "There are no text items in thisDoc" giving up after 2
end try
set txtCnt to count textItems
repeat with tItem in textItems
if selected of tItem is true then
--do something with the text
display dialog "selected text"
end if
end repeat
end tell
I’ve finally upgraded to CS2 so I can’t guarantee this will work but I’m pretty sure it will (except for the app name).
tell application "Adobe Illustrator"
tell document 1
set sel to selection
repeat with thisPath in sel
try
if stroked of thisPath then set stroke width of thisPath to (stroke width of thisPath) + 0.5
end try
end repeat
end tell
end tell
This will increase the stroke width of only selected items, doesn’t matter if they are in a group or not. Did you only want to effect objects a part of a group? If an element of a group is selected but not the entire group, did you still want to effect the rest of the group? The ‘try’ block is to avoid errors due to elements that don’t respond to ‘stroke width’. And I’m not sure if it will increase the stroke width of unstroked items without the if statement (I’ll check).
Just checked: it doesn’t. Here’s a script that makes unstroked paths stroked and gives them a 0.5 pt stroke width:
tell application "Adobe Illustrator"
tell document 1
set sel to selection
repeat with thisPath in sel
try
if stroked of thisPath then
set stroke width of thisPath to (stroke width of thisPath) + 0.5
else
set properties of thisPath to {stroked:true, stroke width:0.5}
end if
end try
end repeat
end tell
end tell
This is working great!
I can’t see a flaw in it. But I must be honest, and this wasn’t the intention, but how difficult would this be to have such a scrip also work on stroked text. It wasn’t until now, that I realized my old javascript didn’t work on stroked text either. But come to think of it, increasing stroke weights on logos is one of the more common Illustrator tasks our operators do
Just thought I would throw the idea out there.
Yet this script alone is awesome, nice job
Thank you.
tell application "Adobe Illustrator"
tell document 1
set sel to selection
repeat with thisPath in sel
try
if class of thisPath is not text frame then
if stroked of thisPath then
set stroke width of thisPath to (stroke width of thisPath) + 0.5
else
set properties of thisPath to {stroked:true, stroke width:0.5}
end if
else
if class of stroke color of (text of story of thisPath) is no color info then
tell text of story of thisPath to set stroke weight to 0.5
else
tell text of story of thisPath to set stroke weight to stroke weight + 0.5
end if
end if
end try
end repeat
end tell
end tell
I’ve discovered a small problem. Adding a stroke to an unstroked item at first made the stroke black, after testing the text frame mods, the stroke it added to path items was white. So the script might need to assign the stroke a color to get reliable results.
Joseph,
That would be great. But in all honestly, I would like for the script to behave as close to the way Illustrator normally would as if someone had to enter the stroke palette. Keeping that in mind, it should increase the stroke weights of a selected “group”. In other words, no need to use the “group selection” tool. Yet a selected item of a group selected via the “group selection” tool should only have the specific grouped item’s strokes increased.
And it should not add a stroke if a path item had no stroke in the first place.
PreTech’s last script seemed to have had all those variables accounted for. Yet, I am trying to test and type as fast as possible, so I may not have caught everything.
Joseph, you have kicked the type issue. Is it possible to account for highlighted type? Your script works off of selecting type via the selection tools. Don’t get me wrong, I am not upset, only asking. This is a huge improvement.
Now, if your type functionality could only be combined with the functionality of PreTech’s script, the world may stop
Well, that makes it easier (before your last post).
tell application "Adobe Illustrator"
tell document 1
set sel to selection
repeat with thisPath in sel
try
if class of thisPath is not text frame then
if stroked of thisPath then set stroke width of thisPath to (stroke width of thisPath) + 0.5
else
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
end if
end try
end repeat
end tell
end tell
Okay. This checks if the selection is text or if it’s a list (of selected path items).
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 then
if stroked of thisPath then set stroke width of thisPath to (stroke width of thisPath) + 0.5
else
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
end if
end try
end repeat
else if class of sel is text then
tell sel to set stroke weight to stroke weight + 0.5
end if
end tell
end tell
Joseph, this is almost dead on. Unfortunately, it would be 100% perfect if it also included a parameter that PreTech’s script did. That script allowed for grouped items to have their strokes increased without the need for direct selecting the path.
I may be able to tweak both scripts to allow for this. But then again, it would take me awhile if I were to even be successful.
Thanks again for you fast and nice work!
Not exactly,
It should only work on selected items. But if the selected items happen to be grouped then it should increase the stroke weight on those items. Presently your script will not increase the stroke weight on a selection that contains a grouped item.
I was referring to “Direct Selection” as the Illustrator tool, that allows one to select the individual paths of a grouped item (as opposed to the “Selection Tool”). You were probably thinking that I meant I wasn’t selecting them at all. Sorry about the confusion.
Okay, I totally understand now. I think it was a mental block on my part since I always use the direct selection tool, sorry.
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 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
Joseph,
You did it!!!
This is working exactly as I want it to. Thank you so much for all the time invested in this. I hope others use this as well, it makes sense to. After all, it should be in the program in the first place.