error code -2741 chain error: expected ",", but find identificator
- May 21, 2024
- 1 reply
- 182 views
I have this code but have malfunction:
Any resolve this question? Thanks!!!
--LabelGraphics.applescript
--An InDesign CS5 AppleScript
--
--Adds labels to graphics in the active document.
tell application "Adobe InDesign CC 2019"
if (count documents) > 0 then
set myGraphics to all graphics of document 1
if (count myGraphics) > 0 then
my myDisplayDialog()
else
display dialog "Please open a document containing graphics and try again." buttons "OK"
end if
else
display dialog "Please open a document and try again." buttons "OK"
end if
end tell
on myDisplayDialog()
set myLabelWidth to 132
tell application "Adobe InDesign CC 2019"
set myStyleNames to my myGetStyleNames()
set myLayerNames to my myGetLayerNames()
set myLabelTypes to {"File Name", "File Path", "XMP Description", "XMP Author"}
set myDialog to make dialog with properties {name:"LabelGraphics"}
tell myDialog
tell (make dialog column)
tell (make dialog row)
tell (make dialog column)
make static text with properties {static label:"Label Type:", min width:myLabelWidth}
end tell
tell (make dialog column)
set myLabelTypeDropdown to make dropdown with properties {string list:myLabelTypes, selected index:0}
end tell
end tell
tell (make dialog row)
tell (make dialog column)
make static text with properties {static label:"Label Height:", min width:myLabelWidth}
end tell
tell (make dialog column)
set myLabelHeightField to make measurement editbox with properties {edit value:24, edit units:points}
end tell
end tell
tell (make dialog row)
tell (make dialog column)
make static text with properties {static label:"Label Offset:", min width:myLabelWidth}
end tell
tell (make dialog column)
set myLabelOffsetField to make measurement editbox with properties {edit value:0, edit units:points}
end tell
end tell
tell (make dialog row)
tell (make dialog column)
make static text with properties {static label:"Label Style:", min width:myLabelWidth}
end tell
tell (make dialog column)
set myLabelStyleDropdown to make dropdown with properties {string list:myStyleNames, selected index:0}
end tell
end tell
tell (make dialog row)
tell (make dialog column)
make static text with properties {static label:"Label Layer:", min width:myLabelWidth}
end tell
tell (make dialog column)
set myLabelLayerDropdown to make dropdown with properties {string list:myLayerNames, selected index:0}
end tell
end tell
end tell
end tell
set myResult to show myDialog
if myResult = true then
set myLabelType to item ((selected index of myLabelTypeDropdown) + 1) of myLabelTypes
set myLabelStyleName to item ((selected index of myLabelStyleDropdown) + 1) of myStyleNames
set myLabelLayerName to item ((selected index of myLabelLayerDropdown) + 1) of myLayerNames
set myLabelHeight to edit value of myLabelHeightField
get myLabelHeight
set myLabelOffset to edit value of myLabelOffsetField
my myAddLabels(myLabelType, myLabelStyleName, myLabelLayerName, myLabelHeight, myLabelOffset)
display dialog "Done!"
end if
destroy myDialog
end tell
end myDisplayDialog
on myAddLabels(myLabelType, myLabelStyleName, myLabelLayerName, myLabelHeight, myLabelOffset)
tell application "Adobe InDesign CC 2019"
set myGraphics to all graphics of document 1
repeat with myCounter from 1 to (count myGraphics)
set myGraphic to item myCounter of myGraphics
my myAddLabel(myGraphic, myLabelType, myLabelStyleName, myLabelLayerName, myLabelHeight, myLabelOffset)
end repeat
end tell
end myAddLabels
on myAddLabel(myGraphic, myLabelType, myLabelStyleName, myLabelLayerName, myLabelHeight, myLabelOffset)
tell application "Adobe InDesign CC 2019"
set myDocument to document 1
tell view preferences of myDocument
set myOldXUnits to horizontal measurement units
set myOldYUnits to vertical measurement units
set horizontal measurement units to points
set vertical measurement units to points
end tell
try
set myLabelStyle to paragraph style myLabelStyleName of myDocument
on error
tell myDocument
set myLabelStyle to make paragraph style with properties {name:myLabelStyleName}
end tell
end try
try
set myLabelLayer to layer myLabelLayerName of myDocument
on error
tell myDocument
set myLabelLayer to make layer with properties {name:myLabelLayerName}
end tell
end try
set myLink to item link of myGraphic
if myLabelType is "File Name" then
set myLabel to name of myLink
else if myLabelType is "File Path" then
set myLabel to file path of myLink
else if myLabelType is "XMP Author" then
try
set myLabel to author of link xmp of myLink
on error
set myLabel to "No author available."
end try
else if myLabelType is "XMP Description" then
try
set myLabel to description of link xmp of myLink
on error
set myLabel to "No description available."
end try
else
set myLabel to "No label found."
end if
set myFrame to parent of myGraphic
set myBounds to geometric bounds of myFrame
set myX1 to item 2 of myBounds
set myY1 to (item 3 of myBounds) + myLabelOffset
set myX2 to item 4 of myBounds
set myY2 to myY1 + myLabelHeight
tell parent of myFrame
set myTextFrame to make text frame with properties {item layer:myLabelLayer, contents:myLabel, geometric bounds:{myY1, myX1, myY2, myX2}}
set first baseline offset of text frame preferences of myTextFrame to leading offset
tell myTextFrame
set applied paragraph style of paragraph 1 to myLabelStyle
end tell
end tell
tell view preferences of myDocument
set horizontal measurement units to myOldXUnits
set vertical measurement units to myOldYUnits
end tell
end tell
end myAddLabel
--Get the names of the document paragraph styles.
on myGetStyleNames()
tell application "Adobe InDesign CC 2019"
tell document 1
set myStyleNames to name of every paragraph style
if "Labels" is not in myStyleNames then
copy "Labels" to end of myStyleNames
end if
return myStyleNames
end tell
end tell
end myGetStyleNames
--Get the names of the document layers.
on myGetLayerNames()
tell application "Adobe InDesign CC 2019"
tell document 1
set myLayerNames to name of every layer
if "Labels" is not in myLayerNames then
copy "Labels" to end of myLayerNames
end if
return myLayerNames
end tell
end tell
end myGetLayerNames
