I’m trying to select page items of the same art style or graphic style does anyone know how to do this ?
mcgrailm,
I’m not sure that this is possible or not. Maybe one of the people on here who seem to have access to the hidden knowledge that some seem to have can answer, but this is what I was playing with.
tell application "Adobe Illustrator"
get name of every graphic style of document 1
get properties of graphic style "Harmony Collage" of document 1
if class of fill color of path item 1 of document 1 is graphic style then display dialog "h"
end tell
When I run this or try to get the properties of the fill color of a path item I have applied a graphic style to, it tells me that the fill color is a pattern that has a name such as “Unknown Pattern 7”. I’ll keep working on it as I have time.
PreTech
ok so I have a semi solution
if I put an object on the document to work with I can apply the the style to that object then use system events to select objects witht the same style, I would like to stay away form system events but I don’t think it can be helped
How about something along these lines? I don’t know what you’re trying to accomplish, but here is something you can work with.
tell application "Adobe Illustrator"
set thisDoc to current document
tell thisDoc
set t to every path item
set trackList to {}
repeat with anItem in t
set q to fill color of anItem
set selection to (every path item whose fill color is q)
-- do something here. Of course you have to discount all items that were in a previous selection.
end repeat
end tell
end tell
This only deals with path items but can be adjusted for text also.
PreTech
Ok, refined a bit to hopefully account for duplicate colors.
tell application "Adobe Illustrator"
set trackList to {}
set thisDoc to current document
tell thisDoc
set t to every path item
repeat with aPath in t
set q to fill color of aPath
if q is not in trackList then
set selection to (every path item whose fill color is q)
set trackList's end to q
end if
end repeat
end tell
end tell
PreTech
I haven’t gotten a chance to check out your code but what I’m trying to do is select every page item with the art style “Blue Goo” and apply the a different style to them
the will be done for many objects with may differnt sytles on the same document.
does that make sense?
Hi Mcgrailm
I think Pretech as pretty much got this covered,
I have found it to be a bit buggy when using certain syntax…
Anyhow heres my quick attempt at it you do have to have at least one path item selected with the graphic style you want to change.
Sorry don’t have “Blue Goo” style to test you might waana play around with this:
tell application "Adobe Illustrator"
tell document 1
set s to fill color of selection
set selection to every path item whose fill color is equal to s
end tell
end tell
tell application "Adobe Illustrator"
tell document 1
apply graphic style "Thick Aqua Neon" to selection
end tell
end tell
Yes, it makes sense. Unfortunately, so far, I haven’t been able to use the name to set the selection. You could use the name to get the correct graphic style, make a small path item and fill it with that style, then get the properties of the fill color of the object you just made (because the properties of the graphic style are different than the properties of the fill color) and then select all items with the same fill properties (after deleting the object you made). That’s so far the only way I see to do this. A bit involved, but workable.
PreTech
so moving away from that check this out … I have two files both containing art styles and I want to apply the style that is in one with the other I can run this code and nothing happens
tell application "Adobe Illustrator"
apply graphic style "ASP 100s color" of document "ASP colors.eps" to (path item 1 of layer 1 of document "test.ai")
end tell
any thoughts ?
Does the second document already contain the graphic style you want to apply? If it doesn’t you may have to copy it and add it to the document. I don’t believe that you can set a fill color of any object in one document to the fill color used in another document without first adding the color.
PreTech
no it doesn’t so how do I put in to the second ?
I think the only way to add this to another document is to copy an object that already has that style and paste/duplicate it to the new document. I don’t see any way to create a new graphic style through AppleScript.
PreTech
mcgrailm,
This probably needs some refining, but it is the general idea. Try this out and see if this is anywhere close to what you want.
tell application "Adobe Illustrator"
activate
set trackList to {}
set otherDoc to document 2
--tell otherDoc to set newStyleList to name of every graphic style
set theColor to text returned of (display dialog "What Graphic Style needs to be replaced?" default answer "")
set thisDoc to current document
tell thisDoc
set styleList to name of every graphic style
display dialog styleList as string
tell otherDoc
set the graphStyle to path item 1
set dup to duplicate graphStyle to thisDoc
delete dup
end tell
repeat with j from 1 to (count graphic styles)
if name of item j of graphic styles is not in styleList then
set theStyle to name of item j of graphic styles as text
display dialog theStyle
end if
end repeat
repeat with i from 1 to (count styleList)
if theColor is item i of styleList then
set testColor to make new rectangle with properties {height:10, width:10}
apply graphic style i to testColor
set colorProps to fill color of testColor as list
set colorProps's end to stroke color of testColor
delete testColor
end if
end repeat
set allPaths to every path item
repeat with aPath in allPaths
set pathColor to fill color of aPath as list
set pathColor's end to stroke color of aPath
if colorProps is pathColor then
--set selection to aPath
tell thisDoc to apply graphic style theStyle to aPath
end if
end repeat
end tell
end tell
PreTech
PreTech,
Thank you very much for the work you have done that looks pretty cool. I was having a hard time following your code and I couldn’t get it to work however it did help with what i did get working and here it is.
set LocalWorkFolderPath to ("" & (path to current user folder) & "Desktop:")
set SourceFile to "ASP colors.eps"
set tempPath to ("" & (POSIX path of LocalWorkFolderPath))
set TargetFile to "test.ai"
set aline to "COLOR,FRONTS,PRECIP|ASP"
set TheType to nthfield(aline, ",", 1)
set Code to nthfield(aline, "|", 2)
tell application "Adobe Illustrator"
activate
tell document TargetFile
set currentStyles to name of every graphic style whose name contains TheType
end tell
set current document to document SourceFile
repeat with astyle in currentStyles
set newStyle to Code & " " & (text items 5 through -1 of astyle)
if exists graphic style newStyle of document SourceFile then
tell document SourceFile
apply graphic style newStyle to page item "work"
set selected of page item "work" to true
copy
end tell
set current document to document TargetFile
paste
tell document TargetFile
apply graphic style astyle to page item "work"
try
my SelectSameStyle()
end try
set SelectedItems to selection
repeat with anitem in SelectedItems
apply graphic style newStyle to anitem
set selection to ""
end repeat
delete page item "work"
end tell
end if
end repeat
end tell
on importStyles(filepath, fileName)
tell application "Adobe Illustrator"
activate
tell application "System Events"
tell application process "Adobe Illustrator 10"
if exists menu item "Other Library..." of menu -1 of menu item "Style Libraries" of menu "Window" of menu bar item "Window" of menu bar 1 then
click menu item "Other Library..." of menu -1 of menu item "Style Libraries" of menu "Window" of menu bar item "Window" of menu bar 1
keystroke "G" using {shift down, command down}
keystroke filepath & return
keystroke fileName & return
end if
end tell
end tell
end tell
end importStyles
on SelectSameStyle()
tell application "Adobe Illustrator"
activate
tell application "System Events"
tell application process "Adobe Illustrator 10"
if exists menu item "Style" of menu -1 of menu item "Same" of menu "Select" of menu bar item "Select" of menu bar 1 then
click menu item "Style" of menu -1 of menu item "Same" of menu "Select" of menu bar item "Select" of menu bar 1
end if
end tell
end tell
end tell
end SelectSameStyle
on nthfield(astring, asep, aindex)
try
set tid to AppleScript's text item delimiters
set AppleScript's text item delimiters to asep
set aitem to text item aindex of astring
set AppleScript's text item delimiters to tid
return aitem
on error tryerror --number errnum
--if errnum = -128 then error tryerror number errnum
--writeToLog("error", "Error: problem in nthfield" & tryerror)
end try
end nthfield
there is some code in here that will be used for other parts
but you have any suggestion on cleaning that would be cool
mm
mm,
I didn’t realize that you were also working with Illustrator 10. Sorry my code wasn’t easy to follow. I left in at least one item that didn’t need to be there. This was the end result of a lot of trial and error so the code wasn’t “cleaned” up. The code is supposed to copy an item from a source file and paste it into the file that needs to be changed just to get the graphic style in the document. It deletes this item but leaves behind the style. Then it compares the old list of styles with the new list to get the added graphic style and then cycles through the objects with the style name you want to change and changes them. It was far from being perfected, but I thought it might help some.
I think your code looks very clean and very good. As you’ve posted though I couldn’t see where the Import styles was being called, but I’m assuming that this will be used later. So far as I’ve experienced the scripting of Illustrator, perseverance is the key.
PreTech
yes unfortunately I have to build the code for 10 I have from 9 all the way up to CS2 though
the importSyles was gonna be how I got the styles into the current document but once I got the palette open I still couldn’t access them with out user interaction. and using system events is not a good habit to get into.
anyhow thanks for your help
mm