Re: INDESIGN: Duplicating Char Style from One Doc to Another
Re: INDESIGN: Duplicating Char Style from One Doc to Another
- Subject: Re: INDESIGN: Duplicating Char Style from One Doc to Another
- From: Rick Gordon <email@hidden>
- Date: Fri, 05 Apr 2013 15:19:03 -0700
Title: Re: INDESIGN: Duplicating Char Style from One Doc
to Anoth
For now, I've got it working using copy and paste. I wish there
were a more elegant way, but at least this works. Still open to
suggestions.
---------------------------------------
tell application
"Adobe InDesign CS5.5"
set vApp to it
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 vDoesNotAlreadyExist to
((nested
grep styles
where grep
_expression_
is equal to grep
_expression_
of
vCurrentSourceGrepRef) is equal to {})
is true
if vDoesNotAlreadyExist then
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
tell vSourceDoc
set vSourceTempFrame to make
new text frame with
properties {fill color:"Black", fill tint:20, geometric
bounds:{0, "-6p",
"4p", "-2p"}, nonprinting:true,
label:"TEMP"}
set properties of insertion point 1 of parent story of vSourceTempFrame to {contents:"X",
applied paragraph style:paragraph style
"[No Paragraph Style]", applied character style:applied
character style of
vCurrentSourceGrepRef}
set vSourceWindow to layout window 1
bring to front
vSourceWindow
select
vSourceTempFrame
tell vApp to copy
end tell
tell vDestDoc
set vDestWindow to layout window 1
bring to front
vDestWindow
tell vApp to paste
set vDestTempFrame to
(some text
frame
where label is "TEMP")
end tell
set vDestAppliedCharStyle to applied character style of
character 1 of
parent story of
vDestTempFrame
tell vSourceDoc to delete
vSourceTempFrame
tell vDestDoc to delete
vDestTempFrame
end if
make new nested grep style at end with properties {applied
character style:vDestAppliedCharStyle, grep
_expression_:grep _expression_ of vCurrentSourceGrepRef}
end if
end repeat
end tell
end tell
end tell
------------------
On 4/5/13 at 1:42 PM -0700, Stan Cleveland wrote in a message
entitled
"Re: INDESIGN: Duplicating Char Style from One Doc to
Anothe":
On Apr 5, 2013, at 12:57 PM, Rick Gordon
wrote:
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 ofvCurrentSourceGrepRef)) --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?
Hi Rick,
At the moment, I'm not in a position to
actually test this, but it's my understanding that you can't define
AND use a reference in the same command line. You need to split it
into two lines, something like this:
set
propsToCopy to properties of applied character style of
vCurrentSourceGrepRef
tell
vDestDoc to set vDestAppliedCharStyle to make new character style at
end with properties propsToCopy
Also, you should NOT pass any properties
that are inappropriate in the target document, such as
class, object reference, parent, and
properties. Capture and pass only needed properties, such as
include footnotes, etc.
No guarantees, but hope one or both of
those thoughts are of help.
Stan C.
--
___________________________________________________
RICK GORDON
EMERALD VALLEY GRAPHICS AND CONSULTING
___________________________________________________
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