INDESIGN: Duplicating Char Style from One Doc to Another
INDESIGN: Duplicating Char Style from One Doc to Another
- Subject: INDESIGN: Duplicating Char Style from One Doc to Another
- From: Rick Gordon <email@hidden>
- Date: Fri, 05 Apr 2013 12:57:47 -0700
Title: INDESIGN: Duplicating Char Style from One Doc to
Another
I'm building a script intended to take one or more GREP styles
from a single paragraph style in a source document and add them to a
chosen paragraph style in a destination document.
My problem, at this point, is that if the destination doc does
not have a character style with the name of the applied character
style of the incoming GREP style, that I have not found a successful
way to import that character style (just that one, not all char
styles) into the destination doc. Two unsuccessful tries are in
the last
else block of the code sample, repeated here:
duplicate
vCurrentSourceGrepRef
to end
of vDestDoc --NOPE
tell
vDestDoc to
set
vDestAppliedCharStyle to
(make new character style at end with properties (properties of applied
character style of
vCurrentSourceGrepRef))
--NOPE
I know that import style is a possibility, but I don't know how
to limit the styles to just one.
Another laborious possibility is to make a new style and set all
properties individually, avoiding problem properties that refer back
to the source doc, but that's error-prone with an object with lots of
properties that might be important.
Another possibility might be to build a temp element in the
source doc containing the applied character style, and cut it, then
paste it into the destination doc, and then delete it. But that seems
hackish.
What's the best way to approach this kind of thing?
Rick Gordon
----------------------------------------
/* CODE SAMPLE */
tell application
"Adobe InDesign CS5.5"
set vDocCount to count documents
if
vDocCount 2 then
set vDocNameList to
name
of
documents
tell me to set vSourceDocName to item 1 of
(choose
from list
vDocNameList with
prompt "Choose Source
Document." default
items {item 1
of
vDocNameList})
set DestDocNameList to
{}
repeat with vItem in
vDocNameList
if vItem as string is not equal to vSourceDocName then
set end of DestDocNameList to vItem
end if
end repeat
tell me to set vDestDocName to item 1 of
(choose
from list
DestDocNameList with
prompt "Choose Destination
Document." default
items {item 1
of
DestDocNameList})
set vSourceDoc to document
vSourceDocName
set vDestDoc to document
vDestDocName
else
tell me
set vSourceDocAlias to choose file with prompt
"Choose Source File."
repeat
set vDestDocAlias to choose file with prompt
"Choose Destination File."
if vDestDocAlias is equal to vSourceDocAlias then
display alert
"Source and destination must be different files."
else
exit repeat
end if
end repeat
end tell
open
vDestDocAlias
set vDestDoc to document 1
open
vSourceDocAlias
set vSourceDoc to document 1
end
if
tell
vSourceDoc
set vsourceParaStyleList to
object reference of items of all
paragraph styles
set vSourceNameList to
{}
repeat with vItem in
vsourceParaStyleList
tell vItem
if properties of nested grep styles is not {} then
if class of parent is paragraph style group then
set end of vSourceNameList to name of
parent & ": "
& name
else
set end of vSourceNameList to name
end if
end if
end tell
end repeat
tell me to set vChosenItem to item 1 of
(choose
from list
vSourceNameList with
prompt "Choose Source
Paragraph Style.")
set my text item delimiters to
{": "}
set vChosenName to last item of text items of
vChosenItem
set my text item delimiters to
{""}
set vCount to count items in
vsourceParaStyleList
repeat with i from
1 to vCount
if vChosenName is equal to ((name of item
i
in
vsourceParaStyleList) as string) then
set vsourceParaStyleRef to
object reference of item
i
in
vsourceParaStyleList
end if
end repeat
set vGrepExpression to
grep _expression_ of nested grep styles of
vsourceParaStyleRef
tell me to set vGrepList to
(choose
from list
vGrepExpression with
prompt ¬
"Choose one or more from the source GREP
Style." default
items
vGrepExpression with multiple
selections allowed)
set vSourceGrepRefList to
{}
set vCharStyleRefList to
{}
tell vsourceParaStyleRef
repeat with i from
1 to count items in
vGrepList
set vGrepStyleRef to
(object reference of nested grep
styles
where grep
_expression_
is equal to item
i
of vGrepList)
set end of vSourceGrepRefList to vGrepStyleRef
set end of vCharStyleRefList to object reference of applied character style of vGrepStyleRef
end repeat
end tell
end tell
tell
vDestDoc
set vDestParaStyleList to
object reference of items 2 thru -1
of all paragraph
styles
set vDestNameList to
{}
repeat with vItem in
vDestParaStyleList
tell vItem
if class of parent is paragraph style group then
set end of vDestNameList to name of
parent & ": "
& name
else
set end of vDestNameList to name
end if
end tell
end repeat
tell me to set vChosenItem to item 1 of
(choose
from list
vDestNameList with
prompt "Choose destination
paragraph style to add GREP styles into.")
tell paragraph
style vChosenItem
repeat with i from
1 to (count items in vGrepList)
set vCurrentSourceGrepRef to item i of
vSourceGrepRefList
set vCharStyleName to
name
of applied character
style
of
vCurrentSourceGrepRef
set vDestAppliedCharStyle to (items of
all character styles of
vDestDoc
where name is equal
to vCharStyleName)
if length of
vDestAppliedCharStyle >
0 then
set vDestAppliedCharStyle to item 1
of
vDestAppliedCharStyle
else --THREE UNSUCCESSFUL
APPROACHES
--duplicate
vCurrentSourceGrepRef to end of vDestDoc --NOPE
--tell vDestDoc to set
vDestAppliedCharStyle to (make new character style at end with
properties (properties of applied character style of
vCurrentSourceGrepRef))
--NOPE
--set
vDestAppliedCharStyle to applied character style of
vCurrentSourceGrepRef --NEED
TO GET CHAR STYLE INTO DOC FIRST
end if
make new nested grep style at end with properties {applied
character style:vDestAppliedCharStyle, grep
_expression_:grep _expression_ of vCurrentSourceGrepRef}
end repeat
end tell
end tell
end tell
--
___________________________________________________
RICK GORDON
EMERALD VALLEY GRAPHICS AND CONSULTING
___________________________________________________
EMAIL: email@hidden
PHONE: 415-663-8652
WWW: http://www.shelterpub.com
_______________________________________________
Do not post admin requests to the list. They will be ignored.
AppleScript-Users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
Archives: http://lists.apple.com/archives/applescript-users
This email sent to email@hidden