Author Topic: Locking images that are in the document multiple times  (Read 488 times)

0 Members and 1 Guest are viewing this topic.

Offline mbornbach

  • Newbie
  • *
  • Posts: 34
  • Karma: 0
Locking images that are in the document multiple times
« on: June 02, 2016, 05:45:44 PM »
I'm writing this script that duplicates images, changes the height of the duplicate image and adds a drop shadow to the duplicate image. The problem is some of the documents I'm working with will have some images that are already duplicated and have a drop shadow on the duplicate. I want the script to look through the document and lock all images that are in the document more than once. Then, once those images are locked, it can duplicate and create drop shadows for the unlocked images.

I have everything working EXCEPT the script only locks the duplicate image and not the original image. When it counts the images, it thinks there is only one image the first time it comes across the name, so it doesn't lock the first image. Since, one copy isn't locked, it creates a second drop shadow for the images that already had one. How do I change the part that checks how many times the image is in the document so that it locks BOTH copies of the image and not just one?



Code: [Select]
on open of droppedFiles --> This is the line of code that begins a droplet. 


tell application "Adobe InDesign CC 2014"

repeat with afile in droppedFiles
open afile

-----------------------------------------------------------------------------------------


--CREATING A DROP SHADOW OBJECT STYLE TO BE APPLIED LATER ON

tell document 1

try
set dropShadowStyle to object style "Drop Shadow"
on error
--The character style did not exist, so create it.
set dropShadowStyle to make object style with properties {name:"Drop Shadow", enable drop shadow:true, enable transparency:true, enable stroke:false}

tell dropShadowStyle
--Applying the drop shadow to the text
tell transparency settings
set properties of drop shadow settings to {mode:drop, use global light:true, opacity:40, spread:10.0, blend mode:multiply, noise:1.0, x offset:".02", y offset:".02", distance:".04", size:".04", effect color:"Black"}
end tell
end tell
end try

---------------------------------------------------------------


--COUNTING THE NUMBER OF TIMES AN IMAGE IS IN THE DOCUMENT
set TheGraphics to all graphics
set theLinksList to {}

repeat with n from 1 to (count TheGraphics)
set TheGraphic to item n of TheGraphics
set theLink to item link of TheGraphic
set linkName to name of item link of TheGraphic as string
set theLinksList to theLinksList & linkName
set matchCount to my count_matches(theLinksList, linkName)

--Getting the full path to each link to be used later on in thes script
set linkPath to file path of theLink as string

--other information that will be used later on in the script
set theImage to parent of theLink
set theFrame to parent of theImage

-----------------------------------------------------------------------------------------


--DUPLICATING PRODUCT IMAGES AND ADDING A DROP SHADOW IF THE FRAME THE IMAGE IS IN DOESN'T ALREADY HAVE A DROP SHADOW

if matchCount is greater than 1 then
set locked of theFrame to true
end if


if linkPath contains "1_4c IMAGES" then --Choosing everything that has 1_4c IMAGES in the path of it's link (basically all the product images)

--Getting coordinates of each side of the frame to be used in creating the duplicated frame for the drop shadow
--Geometric bounds is {top of frame, left side of frame, bottom of frame, right side of frame} or {item 1, item 2, item 3, item 4}
tell theFrame
set topOfFrame to item 1 of geometric bounds
set leftSideOfFrame to item 2 of geometric bounds
set bottomOfFrame to item 3 of geometric bounds
set rightSideOfFrame to item 4 of geometric bounds
set frameHeight to bottomOfFrame - topOfFrame as number --Getting height to be used later on in removing short frames with drop shadows
set offsetTopOfFrame to bottomOfFrame - 0.05 --This is the coordinate for the top of the duplicated frame that contains the drop shadow. We want it to be only slightly above the bottom of the frame.
end tell


--Duplicating the product image frame and resizing so it is only .05" tall instead of the full height of the image
--We just want a short little box at the bottom of the image for the drop shadow
if locked of theFrame is false then
set duplicateFrame to duplicate theFrame
set geometric bounds of duplicateFrame to {offsetTopOfFrame, leftSideOfFrame, bottomOfFrame, rightSideOfFrame}


--Sending the image frame with the drop shadow back one step
send backward duplicateFrame


--Applying the drop shadow to the duplicated image frame
tell duplicateFrame
apply object style using dropShadowStyle
end tell
end if


end if
end repeat


close saving yes



end tell
end repeat
end tell
end open







on count_matches(this_list, this_item)
set the match_counter to 0
repeat with i from 1 to the count of this_list
if item i of this_list is this_item then
set the match_counter to the match_counter + 1
end repeat
return the match_counter
end count_matches

Offline mbornbach

  • Newbie
  • *
  • Posts: 34
  • Karma: 0
Re: Locking images that are in the document multiple times
« Reply #1 on: September 23, 2016, 07:22:48 PM »
I have this working now, I should post the solution when I have the script handy and remember.