resample images for ID

This script is suppose to check if a link is at 100% in ID and if not, resize it to the proper size in PS and relink it in ID. It does a descent job, but for an unknown reason, doesn’t do all links.

I’ve tried to isolate the problem but since I didn’t write the script innitially I have no idea where to look.

I’ve tried to check after the line

set ImagePath to file path of item myCounter of IDLinks as string

with a get IDlinks and every image is listed, so I guess the problem lies further except that I don’t know how to disect the script in portion to isolate the problem.

Anyway, here is the script, it’s pretty long, sorry and thanks for any help.


--ResampleImages.as 
--Resamples all images in the active document (using Photoshop) 
--to their scaled size; sets the scaling on all frames to 100%. 
set myProcessedLinks to {}
set myFolder to choose folder with prompt "Select a destination folder for resampled images"
tell application "InDesign CS"
	set myDocument to active document
	tell myDocument
		set outdateLinks to every link whose status is link out of date
		repeat with OODLinks from (count outdateLinks) to 1 by -1
			update link of item OODLinks of outdateLinks
		end repeat
		set IDLinks to every link whose status is normal
		--Iterate backwards through the links to avoid invalidating objects. 
		repeat with myCounter from (count IDLinks) to 1 by -1
			set myLink to item myCounter of IDLinks
			--Process only image links. 
			set myLinkType to link type of myLink
			--If statement could be expanded to include other image types. 
			if myLinkType = "TIFF" or myLinkType = "EPS" or myLinkType = "Photoshop format" or myLinkType = "PDF" then
				set LinkName to name of myLink
				set theImage to parent of myLink
				set theFrame to parent of theImage
				--get the path 
				set ImagePath to file path of item myCounter of IDLinks as string
				--get the image's location 
				set ImgPos to geometric bounds of theImage
				set FramePos to geometric bounds of theFrame
				--get the scale 
				set myHoriz to horizontal scale of theImage as real
				set myVert to vertical scale of theImage as real
				--get the bounds of the image 
				set myY1 to (item 1 of ImgPos)
				set myX1 to (item 2 of ImgPos)
				set myY2 to (item 3 of ImgPos)
				set myX2 to (item 4 of ImgPos)
				--If the image has been scaled to something other than 100%, 
				--and if it has not already been resized in photoshop... 
				if myHoriz is not 100 and myHoriz = myVert and ImagePath is not in myProcessedLinks then
					set myFileName to my myMakeFileName(myFolder, ImagePath as alias, myHoriz)
					--...then scale the graphic in Photoshop: 
					tell application "Adobe Photoshop CS"
						--activate 
						open file ImagePath
						set docRef to current document
						resize image docRef width percent (myHoriz / 100) resample method bicubic sharper
						--If...else if statement could be expanded to handle other file types. 
						if myLinkType = "TIFF" then
							set myImageDocument to save docRef in file myFileName as TIFF
						else if myLinkType = "EPS" then
							set myImageDocument to save docRef in file myFileName as EPS
						else if myLinkType = "Photoshop format" then
							set myImageDocument to save docRef in file myFileName as Photoshop format
						else if myLinkType = "PDF" then
							set myImageDocument to save docRef in file myFileName as PDF
						end if
						set myFileName to file path of myImageDocument
						close current document saving no
						--close docRef with saving 
					end tell
					relink myLink to myFileName
					--When you update the link, the old link is destroyed 
					--and InDesign returns the new link. 
					set myLink to update myLink
					set theImage to parent of myLink
					set theFrame to parent of theImage
					set properties of theFrame to {horizontal scale:100, vertical scale:100, geometric bounds:FramePos}
					set properties of theImage to {horizontal scale:100, vertical scale:100, geometric bounds:ImgPos}
					copy myFileName to end of myProcessedLinks
				else if ImagePath is in myProcessedLinks then
					set myLink to update myLink
				end if
			end if
		end repeat
	end tell
end tell
on myMakeFileName(myFolder, myFile, myHoriz)
	set myFileInfo to info for myFile
	set myFileName to name of myFileInfo
	set myFolderName to myFolder as string
	if (myHoriz as string) contains "." then
		set myOldDelimiters to text item delimiters
		set text item delimiters to "."
		set myHoriz to text item 1 of (myHoriz as string)
		set text item delimiters to myOldDelimiters
	end if
	if myFileName contains "." then
		set myOldDelimiters to text item delimiters
		set text item delimiters to "."
		set myFileName to text item 1 of myFileName
		set text item delimiters to myOldDelimiters
	end if
	set myNewFileName to myFileName & "_" & (myHoriz as string)
	set myNewFilePath to myFolderName & myNewFileName
	return myNewFilePath
end myMakeFileName

Can you reproduce the problem with consistency? If you have a document that always gets the same items skipped, what do the skipped item(s) have in common?

Could there be some wierd type that are not coinsidered by the script. (like a Jpeg?)

Look at the event log when you run this in script editor. How does the event progression of links that are being skipped differ from those that are processed?

Feel free to post some event log if you have any problem figuring it out.

digest4d,

I can’t post the event log since it’s too long or gets truncated when pasted in here.

I’ve run the script multiple time and it always resulted in the same images getting scaled. They are all Tiff files, not placed in group, all frame are set at 100%, no stroke, some with fill, some without any fill. some times the percentage is an integer like 35% and some other time it’s 28.678% or whatever.

The event logs says that the first part of the script get all the links, but when it starts processing them, it just skips some for no apparent reason.

I can email it to you if you want to take a look at it.
Thanks for the pointers.
Lesta

I think I’m sending you on wild goose chases. Maybe somebody with more experience will weigh in.

I notice there’s a construct being used to avoid invalidating object references…

  set IDLinks to every link whose status is normal 
  --Iterate backwards through the links to avoid invalidating objects. 
  repeat with myCounter from (count IDLinks) to 1 by -1 
             set myLink to item myCounter of IDLinks 

I don’t do it that way because I’m never sure when an operation is going to change the object reference of another object in the list of items I’m looping through. So I don’t know if this is doing what it’s supposed to.

Instead of object references, which can change, I use ID. That’s another property of the base class, so everything on the page has one.

set IDLinks to ID of every link whose status is normal
repeat with myLinkID in IDLinks
set myLink to link myLinkID

end repeat.

That way you’re working with uniqe IDs and not object references.

digiest4d,

I tried your lines and get the error
“InDesign CS got an error: Can’t get link (item 1 of {138, 159}) of document “Untitled-2”.”

You sure this works the same?
TIA

So delete every image except one or two that do get replaced and one or two that don’t. Then look closely at the log, and see what happens differently in each case.

– Shane Stanley

I have done so also Shane. I’ve copied one image that didn’t scale and one that did. The only thing is that it stops before getting the position of the image. If I look at the event log and it’s the last image processed of the two. I pasted it from the original document first, but it gets processed last, is that normal?

Lesta

Sorry – I was typing too fast. I left out an “ID”

set IDLinks to ID of every link whose status is normal
repeat with myLinkID in IDLinks
set myLink to link ID myLinkID

end repeat

Try the ID referencing and then maybe you could just post the progress message of a pic that works and one that doesn’t?

Try adding some log statements like
log “I got to point 1”
around the lines where you think things are hanging up so you can tell exactly how far it’s getting.

If you try to actually do the same things that the script does and do it to one of the problem pictures, does PS give you any funny messages?

Lesta,
Here is the working version. Please study - line by line - differences between your script and this one.

set myProcessedLinks to {}
set myFolder to choose folder with prompt "Select a destination folder for resampled images"
tell application "InDesign CS"
	set myDocument to active document
	tell myDocument
		--If the measurement units of the active document are not inches, set the  
		--measurement units to inches. Units MUST be inches in order to script work.
		if horizontal measurement units of view preferences of myDocument is not inches or ¬
			vertical measurement units of view preferences of myDocument is not inches then
			set myOldViewPreferences to properties of view preferences of myDocument
			set horizontal measurement units of view preferences of myDocument to inches
			set vertical measurement units of view preferences of myDocument to inches
			set myResetUnits to true
		else
			set myResetUnits to false
		end if
		set outdateLinks to every link whose status is link out of date
		repeat with OODLinks from (count outdateLinks) to 1 by -1
			update link of item OODLinks of outdateLinks
		end repeat
		set IDLinks to every link whose status is normal
		--Iterate backwards through the links to avoid invalidating objects. 
		repeat with myCounter from (count IDLinks) to 1 by -1
			set myLink to item myCounter of IDLinks
			--Process only image links. 
			set myLinkType to link type of myLink
			--If statement could be expanded to include other image types. 
			if myLinkType = "TIFF" or myLinkType = "JPEG" or myLinkType = "Photoshop" then
				set LinkName to name of myLink
				set theImage to parent of myLink
				set theFrame to parent of theImage
				--get the path  
				set ImagePath to file path of item myCounter of IDLinks as string
				--get the image's location  
				set ImgPos to geometric bounds of theImage
				set FramePos to geometric bounds of theFrame
				--get the rotation angle
				set myRotation to absolute rotation angle of theImage
				--get the scale  
				set myHoriz to absolute horizontal scale of theImage
				set myVert to absolute vertical scale of theImage
				set myHorizFrameHeight to absolute horizontal scale of theFrame
				set myVertFrameWidth to absolute vertical scale of theFrame
				
				set boxRight to item 4 of FramePos
				set boxleft to item 2 of FramePos
				set boxTop to item 1 of FramePos
				set boxBottom to item 3 of FramePos
				set boxHeight to boxBottom - boxTop
				set boxWidth to boxRight - boxleft
				
				set picX1 to item 2 of ImgPos
				set picY1 to item 1 of ImgPos
				set picX2 to item 4 of ImgPos
				set picY2 to item 3 of ImgPos
				set picXCenter to picX1 + ((picX2 - picX1) / 2)
				set picYCenter to picY1 + ((picY2 - picY1) / 2)
				
				set boxX1 to item 2 of FramePos
				set boxY1 to item 1 of FramePos
				set boxX2 to item 4 of FramePos
				set boxY2 to item 3 of FramePos
				set boxXCenter to boxX1 + ((boxX2 - boxX1) / 2)
				set boxYCenter to boxY1 + ((boxY2 - boxY1) / 2)
				
				set hOff to picXCenter - boxXCenter
				set vOff to picYCenter - boxYCenter
				
				--If image has not already been resized in photoshop... 
				if myHorizFrameHeight is 100 and myHorizFrameHeight = myVertFrameWidth and ImagePath is not in myProcessedLinks then
					set myFileName to my myMakeFileName(myFolder, ImagePath as alias, myHoriz)
					--...then scale the graphic in Photoshop:  
					tell application "Adobe Photoshop CS"
						activate
						set ruler units of settings to inch units
						open file ImagePath
						set docRef to current document
						resize image docRef width percent (myHoriz / 100) resample method none
						resize image docRef resolution 300 resample method bicubic
						tell docRef
							select all
							copy
							paste
							set name of layer "Layer 1" to "Photo"
							delete layer "Background"
							resize canvas width boxWidth height boxHeight
							rotate layer "Photo" angle myRotation
						end tell
						tell layer "Photo" of docRef
							translate delta x hOff
							translate delta y vOff
						end tell
						tell docRef
							flatten
						end tell
						--If...else if statement could be expanded to handle other file types. 
						if myLinkType = "TIFF" then
							set myImageDocument to save docRef in file myFileName as TIFF
						else if myLinkType = "JPEG" then
							set myImageDocument to save docRef in file myFileName as JPEG
						else if myLinkType = "Photoshop" then
							set myImageDocument to save docRef in file myFileName as Photoshop format
						end if
						set myFileName to file path of myImageDocument
						--close docRef with saving 
						close current document saving no
					end tell
					relink myLink to myFileName
					--When you update the link, the old link is destroyed 
					--and InDesign returns the new link. 
					set myLink to update myLink
					set theImage to parent of myLink
					set theFrame to parent of theImage
					set properties of theFrame to {horizontal scale:100, vertical scale:100, geometric bounds:FramePos}
					set properties of theImage to {horizontal scale:100, vertical scale:100, geometric bounds:ImgPos}
					fit theFrame given proportionally
					copy myFileName to end of myProcessedLinks
				else if ImagePath is in myProcessedLinks then
					set myLink to update myLink
				end if
			end if
		end repeat
		--Resets the units  
		if myResetUnits is true then
			tell view preferences of myDocument to set properties to myOldViewPreferences
		end if
	end tell
end tell
on myMakeFileName(myFolder, myFile, myHoriz)
	set myFileInfo to info for myFile
	set myFileName to name of myFileInfo
	set myFolderName to myFolder as string
	if (myHoriz as string) contains "," then
		set myOldDelimiters to text item delimiters
		set text item delimiters to ","
		set myHoriz to text item 1 of (myHoriz as string)
		set text item delimiters to myOldDelimiters
	end if
	if myFileName contains "." then
		set myOldDelimiters to text item delimiters
		set text item delimiters to "."
		set myFileName to text item 1 of myFileName
		set text item delimiters to myOldDelimiters
	end if
	set myNewFileName to myFileName & "_" & (myHoriz as string)
	set myNewFilePath to myFolderName & myNewFileName
	return myNewFilePath
end myMakeFileName

Kari

Sorry to sound like a pain, but debugging can be a tedious business, so you need to be as specific as possible. There is no command asking for “position” – what was the last command that ran for the pic that failed?

– Shane Stanley

Kari… Thanks for the script!

I have found that it need to have some change in the coding in regards of rotate images…

Your script was…


tell docRef
							select all
							copy
							paste
							set name of layer "Layer 1" to "Photo"
							delete layer "Background"
							resize canvas width boxWidth height boxHeight
							rotate layer "Photo" angle myRotation
						end tell

But need to be…

tell docRef
							select all
							copy
							paste
							set name of layer "Layer 1" to "Photo"
							delete layer "Background"
							resize canvas width boxWidth height boxHeight
							rotate layer "Photo" angle -(myRotation)
						end tell

and a change at the end from:


set properties of theFrame to {horizontal scale:100, vertical scale:100, geometric bounds:FramePos}
					set properties of theImage to {horizontal scale:100, vertical scale:100, geometric bounds:ImgPos}

to


set properties of theFrame to {horizontal scale:100, vertical scale:100, geometric bounds:FramePos}
					set properties of theImage to {horizontal scale:100, vertical scale:100, absolute rotation angle:0, geometric bounds:ImgPos}

That way any rotation done to the image itself is done in Photoshop and a straight image is placed in Indesign…

Also, it seems that this script is only working when the frame that contain images are not transformed (as soon as their is a rotation, or flip) the image is not processes.

And the script is not working for image that as been flipped directly (not the frame)…

Kari,

I’ve tried your script. The good news is that it does work through all the images. The bad news is that it crops the image, which I don’t want, and when it relinks the image, they change position in their frame. So the PS part must be at fault here, but I can’t pinpoint where. Anyway, since I don’t want to crop and rotate any image in PS, just resize them, this is irrelevant.

I’ll check to see if I can get part of your script in mine so that I get what I want and be able to process all my links.

Thanks!

digest4d,

I followed your guidance and put some :log “I got to point x” in places where the script might hang.

I see that the image that doesn’t get processed gets stuck after the line

Set myX2 to (item 4 of imgPos)

here is the event log:


tell current application
	choose folder with prompt "Select a destination folder for resampled images"
		alias "G5 Jeff:Users:jeff:Desktop:test pour scripting:2 images:"
end tell
tell application "InDesign CS"
	get active document
		document "Untitled-3"
	get every link of document "Untitled-3" whose status = link out of date
		{}
	get every link of document "Untitled-3" whose status = normal
		{link id 138 of image id 136 of rectangle id 135 of page id 127 of spread id 122 of document "Untitled-3", link id 145 of image id 143 of rectangle id 142 of page id 127 of spread id 122 of document "Untitled-3"}
	(*I got to point 1*)
	get link type of link id 145 of image id 143 of rectangle id 142 of page id 127 of spread id 122 of document "Untitled-3"
		"TIFF"
	get name of link id 145 of image id 143 of rectangle id 142 of page id 127 of spread id 122 of document "Untitled-3"
		"bleu10R_300.tif"
	get parent of link id 145 of image id 143 of rectangle id 142 of page id 127 of spread id 122 of document "Untitled-3"
		image id 143 of rectangle id 142 of page id 127 of spread id 122 of document "Untitled-3"
	get parent of image id 143 of rectangle id 142 of page id 127 of spread id 122 of document "Untitled-3"
		rectangle id 142 of page id 127 of spread id 122 of document "Untitled-3"
	get file path of link id 145 of image id 143 of rectangle id 142 of page id 127 of spread id 122 of document "Untitled-3"
		file "G5 Jeff:Users:jeff:Desktop:test pour scripting:Links:bleu10R_300.tif"
	get geometric bounds of image id 143 of rectangle id 142 of page id 127 of spread id 122 of document "Untitled-3"
		{6.925525247806, 14.729166666667, 38.573162726215, 35.727985354057}
	get geometric bounds of rectangle id 142 of page id 127 of spread id 122 of document "Untitled-3"
		{6.9375, 15.4375, 31.104166666667, 33.354166666667}
	get horizontal scale of image id 143 of rectangle id 142 of page id 127 of spread id 122 of document "Untitled-3"
		46.0
	get vertical scale of image id 143 of rectangle id 142 of page id 127 of spread id 122 of document "Untitled-3"
		46.0
	(*I got to point 2*)
end tell
tell current application
	info for alias "G5 Jeff:Users:jeff:Desktop:test pour scripting:Links:bleu10R_300.tif"
		{name:"bleu10R_300.tif", creation date:date "Friday, September 19, 2003 7:26:19 PM", modification date:date "Friday, September 19, 2003 7:26:31 PM", icon position:{0, 0}, size:2.367694E+7, folder:false, alias:false, name extension:"tif", extension hidden:false, visible:true, package folder:false, file type:"TIFF", file creator:"8BIM", displayed name:"bleu10R_300.tif", default application:alias "G5 Jeff:Applications:Adobe Photoshop CS:Adobe Photoshop CS.app:", kind:"Adobe Photoshop TIFF file", locked:false, busy status:false, short version:"", long version:""}
	(*I got to point 6*)
	(*I got to point 3*)
end tell
tell application "Adobe Photoshop CS"
	open file "G5 Jeff:Users:jeff:Desktop:test pour scripting:Links:bleu10R_300.tif"
		current application
	get current document
		document "bleu10R_300.tif"
	resize image document "bleu10R_300.tif" width percent 0.46 resample method bicubic sharper
		current application
	save document "bleu10R_300.tif" in file "G5 Jeff:Users:jeff:Desktop:test pour scripting:2 images:bleu10R_300_46" as TIFF
		document "bleu10R_300_46.tif"
	get file path of document "bleu10R_300_46.tif"
		alias "G5 Jeff:Users:jeff:Desktop:test pour scripting:2 images:bleu10R_300_46.tif"
	close current document saving no
		current application
	(*I got to point 4*)
end tell
tell application "InDesign CS"
	relink link id 145 of image id 143 of rectangle id 142 of page id 127 of spread id 122 of document "Untitled-3" to alias "G5 Jeff:Users:jeff:Desktop:test pour scripting:2 images:bleu10R_300_46.tif"
	update link id 145 of image id 143 of rectangle id 142 of page id 127 of spread id 122 of document "Untitled-3"
		link id 162 of image id 157 of rectangle id 142 of page id 127 of spread id 122 of document "Untitled-3"
	get parent of link id 162 of image id 157 of rectangle id 142 of page id 127 of spread id 122 of document "Untitled-3"
		image id 157 of rectangle id 142 of page id 127 of spread id 122 of document "Untitled-3"
	get parent of image id 157 of rectangle id 142 of page id 127 of spread id 122 of document "Untitled-3"
		rectangle id 142 of page id 127 of spread id 122 of document "Untitled-3"
	set properties of rectangle id 142 of page id 127 of spread id 122 of document "Untitled-3" to {horizontal scale:100, vertical scale:100, geometric bounds:{6.9375, 15.4375, 31.104166666667, 33.354166666667}}
	set properties of image id 157 of rectangle id 142 of page id 127 of spread id 122 of document "Untitled-3" to {horizontal scale:100, vertical scale:100, geometric bounds:{6.925525247806, 14.729166666667, 38.573162726215, 35.727985354057}}
	(*I got to point 1*)
	get link type of link id 138 of image id 136 of rectangle id 135 of page id 127 of spread id 122 of document "Untitled-3"
		"TIFF"
	get name of link id 138 of image id 136 of rectangle id 135 of page id 127 of spread id 122 of document "Untitled-3"
		"bleu4R_300.tif"
	get parent of link id 138 of image id 136 of rectangle id 135 of page id 127 of spread id 122 of document "Untitled-3"
		image id 136 of rectangle id 135 of page id 127 of spread id 122 of document "Untitled-3"
	get parent of image id 136 of rectangle id 135 of page id 127 of spread id 122 of document "Untitled-3"
		rectangle id 135 of page id 127 of spread id 122 of document "Untitled-3"
	get file path of link id 138 of image id 136 of rectangle id 135 of page id 127 of spread id 122 of document "Untitled-3"
		file "G5 Jeff:Users:jeff:Desktop:test pour scripting:Links:bleu4R_300.tif"
	get geometric bounds of image id 136 of rectangle id 135 of page id 127 of spread id 122 of document "Untitled-3"
		{39.180694444444, 15.968666666667, 63.421694444444, 34.364666666667}
	get geometric bounds of rectangle id 135 of page id 127 of spread id 122 of document "Untitled-3"
		{40.5, 16.25, 58.416666666667, 34.166666666667}
	get horizontal scale of image id 136 of rectangle id 135 of page id 127 of spread id 122 of document "Untitled-3"
		35.0
	get vertical scale of image id 136 of rectangle id 135 of page id 127 of spread id 122 of document "Untitled-3"
		35.0
	(*I got to point 2*)
end tell

I didn’t use the ID link line because I keep getting an error saying that it can’t conver the class to string or something like that.

TIA

jctremblay,

Sorry, I didn’t test enough.

This is how I fixed rotation issue:

Change this line:
set myRotation to absolute rotation angle of theImage
to:
set myRotation to rotation angle of theImage

Change this line:
rotate layer “Photo” angle myRotation
to:
rotate layer “Photo” angle -(myRotation)

Change this line:
set properties of theImage to {horizontal scale:100, vertical scale:100, geometric bounds:ImgPos}
to:
set properties of theImage to {horizontal scale:100, vertical scale:100, rotation angle:0, geometric bounds:ImgPos}

Alas, it seems that those flipped images can’t be affected by scripting…

Kari

Kari and all,

I finally came up with a decent version that will reset scaling on the frame first, then do it’s thing. The only thing that doesn’t work is if you have a flipped frame. If the image inside the frame is flipped, it works, but not if the frame itself is flipped.

oh, I had forgoten that there is still a problem with the resulting image not being exactly at 100%.

Here it is:


--ResampleImages13.as 
--Resamples all images in the active document (using Photoshop) 
--to their scaled size; sets the scaling on all frames to 100%. 
set myProcessedLinks to {}
set myFolder to choose folder with prompt "Select a destination folder for resampled images"
tell application "InDesign CS"
	set myDocument to active document
	tell myDocument
		--If the measurement units of the active document are not inches, set the  
		--measurement units to inches. Units MUST be inches in order to script work. 
		if horizontal measurement units of view preferences of myDocument is not inches or ¬
			vertical measurement units of view preferences of myDocument is not inches then
			set myOldViewPreferences to properties of view preferences of myDocument
			set horizontal measurement units of view preferences of myDocument to inches
			set vertical measurement units of view preferences of myDocument to inches
			set myResetUnits to true
		else
			set myResetUnits to false
		end if
		
		set outdateLinks to every link whose status is link out of date
		repeat with OODLinks from (count outdateLinks) to 1 by -1
			update link of item OODLinks of outdateLinks
		end repeat
		set IDLinks to every link whose status is normal
		--Iterate backwards through the links to avoid invalidating objects. 
		repeat with myCounter from (count IDLinks) to 1 by -1
			set myLink to item myCounter of IDLinks
			
			--Process only image links. 
			set myLinkType to link type of myLink
			--If statement could be expanded to include other image types. 
			if myLinkType = "TIFF" or myLinkType = "Photoshop format" then
				set LinkName to name of myLink
				set theImage to parent of myLink
				set theFrame to parent of theImage
				-- resets the graphic frame to 100
				reset scaling of theFrame
				--get the path 
				set ImagePath to file path of item myCounter of IDLinks as string
				--get the image's location 
				set ImgPos to geometric bounds of theImage
				set FramePos to geometric bounds of theFrame
				
				--get the scale 
				set myHoriz to absolute horizontal scale of theImage
				set myVert to absolute vertical scale of theImage
				set myHorizFrameHeight to absolute horizontal scale of theFrame
				set myVertFrameWidth to absolute vertical scale of theFrame
				
				--get the rotation and Shear of the frame
				set FrameRot to rotation angle of theFrame
				set FrameShear to shear angle of theFrame
				
				--get the bounds of the image 
				set myY1 to (item 1 of ImgPos)
				set myX1 to (item 2 of ImgPos)
				set myY2 to (item 3 of ImgPos)
				set myX2 to (item 4 of ImgPos)
				
				--If the image has been scaled to something other than 100%, 
				--and if it has not already been resized in photoshop... 
				if myHorizFrameHeight is 100 and myHorizFrameHeight = myVertFrameWidth and ImagePath is not in myProcessedLinks then
					set myFileName to my myMakeFileName(myFolder, ImagePath as alias, myHoriz)
					
					--...then scale the graphic in Photoshop: 
					tell application "Adobe Photoshop CS"
						--activate 
						set ruler units of settings to inch units
						open file ImagePath
						set docRef to current document
						resize image docRef width percent (myHoriz / 100) resample method bicubic sharper
						--If...else if statement could be expanded to handle other file types. 
						if myLinkType = "TIFF" then
							set myImageDocument to save docRef in file myFileName as TIFF
						else if myLinkType = "Photoshop format" then
							set myImageDocument to save docRef in file myFileName as Photoshop format
						end if
						set myFileName to file path of myImageDocument
						close current document saving no
						--close docRef with saving 
end tell
					relink myLink to myFileName
					--When you update the link, the old link is destroyed 
					--and InDesign returns the new link. 
					set myLink to update myLink
					set theImage to parent of myLink
					set theFrame to parent of theImage
					set properties of theFrame to {horizontal scale:100, vertical scale:100, geometric bounds:FramePos, rotation angle:FrameRot, shear angle:FrameShear}
					set properties of theImage to {horizontal scale:100, vertical scale:100, geometric bounds:ImgPos}
					copy myFileName to end of myProcessedLinks
				else if ImagePath is in myProcessedLinks then
					set myLink to update myLink
				end if
			end if
		end repeat
		--Resets the units  
		if myResetUnits is true then
			tell view preferences of myDocument to set properties to myOldViewPreferences
		end if
	end tell
end tell
on myMakeFileName(myFolder, myFile, myHoriz)
	set myFileInfo to info for myFile
	set myFileName to name of myFileInfo
	set myFolderName to myFolder as string
	if (myHoriz as string) contains "." then
		set myOldDelimiters to text item delimiters
		set text item delimiters to "."
		set myHoriz to text item 1 of (myHoriz as string)
		set text item delimiters to myOldDelimiters
	end if
	if myFileName contains "." then
		set myOldDelimiters to text item delimiters
		set text item delimiters to "."
		set myFileName to text item 1 of myFileName
		set text item delimiters to myOldDelimiters
	end if
	set myNewFileName to myFileName & "_" & (myHoriz as string)
	set myNewFilePath to myFolderName & myNewFileName
	return myNewFilePath
end myMakeFileName

I think I’ll just make anothe thread for the flip frame thing…

Thanks all who have helped!

With the version (together with the changes I made) I posted I allways get 100%

Kari

This is getting rediculus…

This morning, not one of my changes to the rotate and shear frame work. How is this possible? It worked fine yesterday all day! I didn’t do anything to them and this morning it doesn’t work:-(

I even restarted my machine to no avail, what the heck can cause this? I’m sure I didn’t dream it was working yesterday…

This scripting business is giving me nightmares…
Lesta

Well, well,… what do you know. It turns out that I had to check the option “Transformation are totals” in the transform palette for the script to work. I had modified this at the end of the previous day but didn’t think it would affect the script.

anyway, I’ll post the final version when it’s done for those interested.

lesta