How to reference tagged rectangle in layer Indesgn CS4


What I am trying to do is access a tagged rectangle called IMAGE, with a script label of IMAGE in a group on a locked layer, and replace that rectangles content with a new image, and have not had much success.

When I unlock the layer and un-group the group, I can then access the tagged rectangle¨with the code below.¨(the code was cobbled together from here

Could someone please show me how to reference a tagged rectangle on a locked layer in a group please, if I need to unlock the layer then that’s fine.

tell application "Adobe InDesign CS4"
	tell the active document
		set the rectangle_list to every rectangle of every spread ¬
			whose label is not "" and content type is graphic type
		if the rectangle_list is {} then
			error "There are no tagged image rectangles."
		end if
		if the class of the rectangle_list is not list then
			set the rectangle_list to the rectangle_list as list
		end if
	end tell
	repeat with i from 1 to the count of the rectangle_list
			set error_indicator to 1
			set this_rectangle to item i of the rectangle_list
			set this_tag to the label of this_rectangle
			set this_image to "PATH TO IMAGE" as alias --testing
			set error_indicator to 2
			tell this_rectangle
				set this_image to place this_image
				if the class of this_image is list then set this_image to item 1 of this_image
				fit given content to frame
				set image_h to the horizontal scale of this_image
				set the image_v to the vertical scale of this_image
				if the image_v is greater than or equal to image_h then
					set horizontal scale of this_image to image_v
					set the vertical scale of this_image to image_h
				end if
				fit given center content
			end tell
		on error error_message
			if the error_indicator is 1 then
				set the error_message to "Image "" & this_tag & ¬
					"" could not be found in the database."
			end if
			display dialog error_message buttons {"Cancel", "Continue"} default button 2
		end try
	end repeat
end tell


Shane Stanley kindly helped me out here,

cheers Shane

tell application  "Adobe InDesign CS4"

tell document 1

set theRects to every item of all page items whose class is rectangle and label is "IMAGE"

repeat with i from 1 to count of theRects

set oneRect to item i of theRects

-- unlock layer if necessary

if locked of item layer of oneRect is true then

set lockFlag to true

set locked of item layer of oneRect to false


set lockFlag to false

end if

set this_image to place this_image on oneRect


-- do your stuff to the image


if lockFlag is true then set locked of item layer of oneRect to true -- relock the layer

end repeat

end tell

end tell

Hey, Budgie. There’s really no need to unlock layers, as long as your variable is an alias.

cheers for the heads up on that Marc :smiley: