Thread: Numbering boxes
View Single Post
If I needed to do this kind of thing regularly, I would probably use a script of some kind, roughly along these lines:

(Assumes that all the boxes have been given the "type"="box" key-value pair with the data inspector - you can do this as a batch by selecting them all, of course)

Code:
-- NUMBER BOXES SEQUENTIALLY BY COLUMN AND ROW
-- ASSUMES THAT ALL BOXES ARE TAGGED WITH INSPECTORS > NOTE > DATA KEY=TYPE > DATA VALUE=BOX


-- PROMPT USER FOR NUMBER OF COLUMNS
-- AND NUMBER OF ROWS
-- (SEPARATED BY A COMMA)
set {dlm, my text item delimiters} to {my text item delimiters, ","}
tell (display dialog "Enter number of cols and rows" & return & return & "(Two integers, separated by a comma)" default answer "")
	try
		set lstColRows to text items of (text returned)
		repeat with i from 1 to 2
			set item i of lstColRows to item i of lstColRows as integer
		end repeat
		set {lngCols, lngRows} to lstColRows
	on error
		return
	end try
end tell

-- MAKE A LIST OF EACH TAGGED SHAPE, WITH ITS ID AND HORIZONTAL AND VERTICAL POSITION
set my text item delimiters to tab
tell application id "OGfl"
	tell canvas of front window
		set {lstID, lstPosn} to {id, origin} of (shapes where value of user data item "Type" = "box")
		set strList to ""
		set lngID to length of lstID
		repeat with i from 1 to lngID
			set strList to strList & item i of lstID & tab & ((item i of lstPosn) as string) & linefeed
		end repeat
		
		-- SORT ALL THE SHAPES BY THEIR VERTICAL POSITION
		set my text item delimiters to linefeed
		set lstID to items 2 thru -1 of paragraphs of (do shell script "echo " & quoted form of strList & " | sort -n -k 3")
		
		-- ROW BY ROW, SORT THE SHAPES BY THEIR HORIZONTAL POSITION
		set lngPrev to 0
		repeat with iRow from 1 to lngRows
			set {lngFirst, lngLast} to {lngPrev + 1, lngPrev + lngCols}
			set lstRow to items lngFirst thru lngLast of lstID
			set lstRowID to paragraphs of (do shell script "echo " & quoted form of (lstRow as string) & " | sort -n -k 2 | cut -f 1")
			
			-- NUMBER THE MEMBERS OF THE SORTED ROW
			repeat with i from 1 to lngCols
				set text of (shape id ((item i of lstRowID) as integer)) to ((lngPrev + i) as string)
			end repeat
			set lngPrev to lngLast
		end repeat
	end tell
end tell

set my text item delimiters to dlm

Last edited by RobTrew; 2012-04-01 at 03:46 PM.. Reason: added "set my text item delimiters to dlm" to tidy up