InDesign CS4 Scripts Panel Double-Click Issue

I am stumped as to why I can always run this script using the script editor without an issue. But it will not always run completely when accessing it via double-clicking the script in InDeisgn’s “Script’s panel”. FWIW, the script is being targeted when I double-click the script in the Script’s panel choice, but it is only getting a bit further than the dialog that asks for the amount of rows, columns, and gutter values.

I noticed once when I put in a dialog that displays the class of the selected item, I was receiving “<>” which is odd, because when I use the same exact script on same selected object and document, script editor will display “rectangle”

Any ideas as to what my be causing this mix up?

--MakeGrid.applescript
--An InDesign CS4 AppleScript
--
--Divides the selected frame (or frames) into grid(s) of frames.
--
--For more on InDesign scripting, go to http://www.adobe.com/products/indesign/scripting.html
--or visit the InDesign Scripting User to User forum at http://www.adobeforums.com.
--

global myStrokeWidth
global myAlign
global myNumberOfRows
global myNumberOfColumns
global errorNumber

on theError()
	tell application "SystemUIServer"
		activate
		set userResponse to display dialog "You must have at least 1 row and 1 column." buttons {" Cancel "} default button " Cancel " with icon 2
		
		if button returned of userResponse contains " Cancel " then
			set errorNumber to 1
		end if
		if button returned of userResponse contains " Cancel " then
			return
		end if
	end tell
end theError


set errorNumber to 0
set myObjectList to {}
tell application "Adobe InDesign CS4"
	set myPageItemTypes to {rectangle, oval, text frame, group}
	if (count documents) > 0 then
		--tell document 1
		set mySelection to selection
		--end tell
		if (count mySelection) > 0 then
			repeat with MyCounter from 1 to (count mySelection)
				if (class of item MyCounter of mySelection) is group then
					display dialog "Does not work on grouped items." buttons {"Cancel"} default button "Cancel" with icon 2
				end if
				set xClass to class of item MyCounter of mySelection as text
				--display dialog xClass as string
				if (class of item MyCounter of mySelection) is in myPageItemTypes then
					copy item MyCounter of mySelection to end of myObjectList
					set myStrokeWidth to stroke weight of selection
					set myAlign to stroke alignment of selection as string
					--display dialog myAlign
				end if
			end repeat
			if (count myObjectList) > 1 then
				display dialog "You have more than one frame selected. Select only one frame and try again." buttons {"Cancel"} default button "Cancel" with icon 2
			end if
			if (count myObjectList) < 2 then
				my myDisplayDialog(myObjectList)
				--set myStrokeWeight to stroke weight of selection
				--stroke alignment:inside alignment}
			else
				display dialog "You must have a frame selected." buttons {"Cancel"} default button "Cancel" with icon 2
			end if
		else
			display dialog "You must have a frame selected." buttons {"Cancel"} default button "Cancel" with icon 2
		end if
	else
		display dialog "Please open a document, select a page item, and try again."
	end if
end tell
on myDisplayDialog(myObjectList)
	tell application "Adobe InDesign CS4"
		set myLabelWidth to 100
		set myFrameTypes to {"Unassigned", "Text", "Graphic"}
		set myDialog to make dialog with properties {name:"MakeGrid"}
		tell myDialog
			tell (make dialog column)
				tell (make dialog row)
					tell (make dialog column)
						make static text with properties {static label:"Rows _-_-_-_-_-_- ", min width:myLabelWidth}
						make static text with properties {static label:"Columns | | | | | | | |", min width:myLabelWidth}
					end tell
					tell (make dialog column)
						set myNumberOfRowsField to make integer editbox with properties {edit value:1}
						set myNumberOfColumnsField to make integer editbox with properties {edit value:4}
					end tell
				end tell
				tell (make dialog row)
					tell (make dialog column)
						make static text with properties {static label:"Gutter width:", min width:myLabelWidth}
					end tell
					tell (make dialog column)
						set myRowGutterField 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:"Column Gutter:", min width:myLabelWidth}
					end tell
					tell (make dialog column)
						set myColumnGutterField 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:"Frame Type:", min width:myLabelWidth}
					end tell
					tell (make dialog column)
						set myFrameTypeDropdown to make dropdown with properties {string list:myFrameTypes, selected index:0}
					end tell
				end tell
				set myRetainFormattingCheckbox to {checked state:true}
				set myDeleteObjectCheckbox to make checkbox control with properties {static label:"Delete Original Object", checked state:true}
			end tell
		end tell
		set myResult to show myDialog
		if myResult is true then
			set myNumberOfRows to edit value of myNumberOfRowsField
			set myNumberOfColumns to edit value of myNumberOfColumnsField
			set myRowGutter to edit value of myRowGutterField
			set myColumnGutter to edit value of myRowGutterField
			
			
			
			--display dialog myColumnGutter
			
			
			
			set myRetainFormatting to checked state of myRetainFormattingCheckbox
			set myDeleteObject to checked state of myDeleteObjectCheckbox
			get selected index of myFrameTypeDropdown
			if selected index of myFrameTypeDropdown is 0 then
				set myFrameType to unassigned
			else if selected index of myFrameTypeDropdown is 1 then
				set myFrameType to text type
			else if selected index of myFrameTypeDropdown is 2 then
				set myFrameType to graphic type
			end if
			destroy myDialog
			my mySplitFrames(myObjectList, myNumberOfRows, myNumberOfColumns, myRowGutter, myColumnGutter, myFrameType, myRetainFormatting, myDeleteObject)
		else
			destroy myDialog
		end if
	end tell
end myDisplayDialog
------
if errorNumber is equal to 1 then
	tell application "Adobe InDesign CS4"
		activate
	end tell
end if
if errorNumber is equal to 1 then error number -128

on mySplitFrames(myObjectList, myNumberOfRows, myNumberOfColumns, myRowGutter, myColumnGutter, myFrameType, myRetainFormatting, myDeleteObject)
	tell application "Adobe InDesign CS4"
		set myDocument to active document
		
		--Save the current measurement units.
		set myOldXUnits to horizontal measurement units of view preferences of myDocument
		set myOldYUnits to vertical measurement units of view preferences of myDocument
		--Set the current measurement units to points.
		set horizontal measurement units of view preferences of myDocument to points
		set vertical measurement units of view preferences of myDocument to points
		repeat with MyCounter from 1 to (count myObjectList)
			my mySplitFrame(item MyCounter of myObjectList, myNumberOfRows, myNumberOfColumns, myRowGutter, myColumnGutter, myFrameType, myRetainFormatting, myDeleteObject)
		end repeat
		set horizontal measurement units of view preferences of myDocument to myOldXUnits
		set vertical measurement units of view preferences of myDocument to myOldYUnits
	end tell
end mySplitFrames
on mySplitFrame(myObject, myNumberOfRows, myNumberOfColumns, myRowGutter, myColumnGutter, myFrameType, myRetainFormatting, myDeleteObject)
	if myColumnGutter is equal to 0 and myRowGutter is equal to 0 and myAlign is equal to "inside alignment" then
		tell application "Adobe InDesign CS4"
			set myBounds to geometric bounds of myObject
			--display dialog myBounds as list
			set myWidth to (item 4 of myBounds) - (item 2 of myBounds) - myStrokeWidth
			set myHeight to (item 3 of myBounds) - (item 1 of myBounds) - myStrokeWidth
			--Don't bother making the frames if the width/height of the frame is too small
			--to accomodate the row/column gutter values.	
			if ((myRowGutter * (myNumberOfRows - 1) < myHeight) and (myColumnGutter * (myNumberOfColumns - 1) < myWidth)) then
				set myColumnWidth to (myWidth - (myColumnGutter * (myNumberOfColumns - 1))) / myNumberOfColumns
				try
					set myRowHeight to (myHeight - (myRowGutter * (myNumberOfRows - 1))) / myNumberOfRows
				on error
					my theError()
					if errorNumber is equal to 1 then
						return
					end if
				end try
				
				
				repeat with myRowCounter from 0 to myNumberOfRows - 1
					set myY1 to (item 1 of myBounds) + (myRowHeight * myRowCounter) + (myRowGutter * myRowCounter)
					set myY2 to myY1 + (myRowHeight + myStrokeWidth)
					repeat with myColumnCounter from 0 to myNumberOfColumns - 1
						set myX1 to (item 2 of myBounds) + (myColumnWidth * myColumnCounter) + (myColumnGutter * myColumnCounter)
						--set myX2 to myX1 + myColumnWidth
						set myX2 to myX1 + (myColumnWidth + myStrokeWidth)
						if myRetainFormatting is true then
							set myNewObject to duplicate myObject
							set geometric bounds of myNewObject to {myY1, myX1, myY2, myX2}
							(* else
						tell parent of myObject
							set myNewObject to make rectangle with properties {geometric bounds:{myY1, myX1, myY2, myX2}, content type:myFrameType}
						end tell *)
						end if
					end repeat
				end repeat
				if myDeleteObject is true then
					delete myObject
				end if
			end if
		end tell
	end if
	
	
	
	
	
	if myColumnGutter is equal to 0 and myRowGutter is greater than 0 and myAlign is equal to "inside alignment" then --and right here determine the alignment of stroke, if it is inside then use this below script. Anthying else we use the one far below.
		
		tell application "Adobe InDesign CS4"
			set myBounds to geometric bounds of myObject
			set myWidth to (item 4 of myBounds) - (item 2 of myBounds) - myStrokeWidth
			set myHeight to (item 3 of myBounds) - (item 1 of myBounds) + myStrokeWidth
			--Don't bother making the frames if the width/height of the frame is too small
			--to accomodate the row/column gutter values.	
			if ((myRowGutter * (myNumberOfRows - 1) < myHeight) and (myColumnGutter * (myNumberOfColumns - 1) < myWidth)) then
				set myColumnWidth to (myWidth - (myColumnGutter * (myNumberOfColumns - 1))) / myNumberOfColumns
				try
					set myRowHeight to (myHeight - (myRowGutter * (myNumberOfRows - 1))) / myNumberOfRows
				on error
					my theError()
					if errorNumber is equal to 1 then
						return
					end if
				end try
				repeat with myRowCounter from 0 to myNumberOfRows - 1
					set myY1 to (item 1 of myBounds) + (myRowHeight * myRowCounter) + (myRowGutter * myRowCounter)
					set myY2 to myY1 + (myRowHeight - myStrokeWidth)
					repeat with myColumnCounter from 0 to myNumberOfColumns - 1
						set myX1 to (item 2 of myBounds) + (myColumnWidth * myColumnCounter) + (myColumnGutter * myColumnCounter)
						set myX2 to myX1 + (myColumnWidth + myStrokeWidth)
						if myRetainFormatting is true then
							set myNewObject to duplicate myObject
							set geometric bounds of myNewObject to {myY1, myX1, myY2, myX2}
							(* else
						tell parent of myObject
							set myNewObject to make rectangle with properties {geometric bounds:{myY1, myX1, myY2, myX2}, content type:myFrameType}
						end tell *)
						end if
					end repeat
				end repeat
				if myDeleteObject is true then
					delete myObject
				end if
			end if
		end tell
	end if
	
	--display dialog myAlign
	--display dialog myColumnGutter
	--display dialog myRowGutter
	
	if myColumnGutter is greater than 0 and myRowGutter is equal to 0 and myAlign is equal to "inside alignment" then
	end if
	----
	----
	----
	----
	----
	----Number of Rows is greater than 1
	if myColumnGutter is greater than 0 and myRowGutter is equal to 0 and my myNumberOfRows is greater than 1 and myAlign is equal to "inside alignment" then
		
		tell application "Adobe InDesign CS4"
			set myBounds to geometric bounds of myObject
			set myWidth to (item 4 of myBounds) - (item 2 of myBounds) -- myStrokeWidth
			set myHeight to (item 3 of myBounds) - (item 1 of myBounds) + myStrokeWidth
			--Don't bother making the frames if the width/height of the frame is too small
			--to accomodate the row/column gutter values.	
			if ((myRowGutter * (myNumberOfRows - 1) < myHeight) and (myColumnGutter * (myNumberOfColumns - 1) < myWidth)) then
				set myColumnWidth to (myWidth - (myColumnGutter * (myNumberOfColumns - 1))) / myNumberOfColumns
				try
					set myRowHeight to (myHeight - (myRowGutter * (myNumberOfRows - 1))) / myNumberOfRows
				on error
					my theError()
					if errorNumber is equal to 1 then
						return
					end if
				end try
				repeat with myRowCounter from 0 to myNumberOfRows - 1
					set myY1 to (item 1 of myBounds) + (myRowHeight * myRowCounter) + (myRowGutter * myRowCounter)
					set myY2 to myY1 + (myRowHeight) - myStrokeWidth
					repeat with myColumnCounter from 0 to myNumberOfColumns - 1
						set myX1 to (item 2 of myBounds) + (myColumnWidth * myColumnCounter) + (myColumnGutter * myColumnCounter)
						set myX2 to myX1 + (myColumnWidth)
						if myRetainFormatting is true then
							set myNewObject to duplicate myObject
							set geometric bounds of myNewObject to {myY1, myX1, myY2, myX2}
							(* else
						tell parent of myObject
							set myNewObject to make rectangle with properties {geometric bounds:{myY1, myX1, myY2, myX2}, content type:myFrameType}
						end tell *)
						end if
					end repeat
				end repeat
				if myDeleteObject is true then
					delete myObject
				end if
			end if
		end tell
		
	end if
	----
	----
	----
	----
	----
	----
	----
	----
	----
	----
	----Number of Coulumns is greater than 1
	if myColumnGutter is greater than 0 and myRowGutter is equal to 0 and my myNumberOfColumns is greater than 1 and myAlign is equal to "inside alignment" then
		
		tell application "Adobe InDesign CS4"
			set myBounds to geometric bounds of myObject
			set myWidth to (item 4 of myBounds) - (item 2 of myBounds) + myStrokeWidth
			set myHeight to (item 3 of myBounds) - (item 1 of myBounds) -- myStrokeWidth
			--Don't bother making the frames if the width/height of the frame is too small
			--to accomodate the row/column gutter values.	
			if ((myRowGutter * (myNumberOfRows - 1) < myHeight) and (myColumnGutter * (myNumberOfColumns - 1) < myWidth)) then
				set myColumnWidth to (myWidth - (myColumnGutter * (myNumberOfColumns - 1))) / myNumberOfColumns
				try
					set myRowHeight to (myHeight - (myRowGutter * (myNumberOfRows - 1))) / myNumberOfRows
				on error
					my theError()
					if errorNumber is equal to 1 then
						return
					end if
				end try
				repeat with myRowCounter from 0 to myNumberOfRows - 1
					set myY1 to (item 1 of myBounds) + (myRowHeight * myRowCounter) + (myRowGutter * myRowCounter)
					set myY2 to myY1 + (myRowHeight)
					repeat with myColumnCounter from 0 to myNumberOfColumns - 1
						set myX1 to (item 2 of myBounds) + (myColumnWidth * myColumnCounter) + (myColumnGutter * myColumnCounter)
						set myX2 to myX1 + (myColumnWidth) - myStrokeWidth
						if myRetainFormatting is true then
							set myNewObject to duplicate myObject
							set geometric bounds of myNewObject to {myY1, myX1, myY2, myX2}
							(* else
						tell parent of myObject
							set myNewObject to make rectangle with properties {geometric bounds:{myY1, myX1, myY2, myX2}, content type:myFrameType}
						end tell *)
						end if
					end repeat
				end repeat
				if myDeleteObject is true then
					delete myObject
				end if
			end if
		end tell
		
	end if
	----
	----
	----
	----
	----
	if myColumnGutter is greater than 0 and myRowGutter is greater than 0 and myAlign is equal to "inside alignment" then
		
		tell application "Adobe InDesign CS4"
			set myBounds to geometric bounds of myObject
			set myWidth to (item 4 of myBounds) - (item 2 of myBounds) -- myStrokeWidth
			set myHeight to (item 3 of myBounds) - (item 1 of myBounds) -- myStrokeWidth
			--Don't bother making the frames if the width/height of the frame is too small
			--to accomodate the row/column gutter values.	
			if ((myRowGutter * (myNumberOfRows - 1) < myHeight) and (myColumnGutter * (myNumberOfColumns - 1) < myWidth)) then
				set myColumnWidth to (myWidth - (myColumnGutter * (myNumberOfColumns - 1))) / myNumberOfColumns
				try
					set myRowHeight to (myHeight - (myRowGutter * (myNumberOfRows - 1))) / myNumberOfRows
				on error
					my theError()
					if errorNumber is equal to 1 then
						return
					end if
				end try
				repeat with myRowCounter from 0 to myNumberOfRows - 1
					set myY1 to (item 1 of myBounds) + (myRowHeight * myRowCounter) + (myRowGutter * myRowCounter)
					set myY2 to myY1 + (myRowHeight)
					repeat with myColumnCounter from 0 to myNumberOfColumns - 1
						set myX1 to (item 2 of myBounds) + (myColumnWidth * myColumnCounter) + (myColumnGutter * myColumnCounter)
						set myX2 to myX1 + (myColumnWidth)
						if myRetainFormatting is true then
							set myNewObject to duplicate myObject
							set geometric bounds of myNewObject to {myY1, myX1, myY2, myX2}
							(* else
						tell parent of myObject
							set myNewObject to make rectangle with properties {geometric bounds:{myY1, myX1, myY2, myX2}, content type:myFrameType}
						end tell *)
						end if
					end repeat
				end repeat
				if myDeleteObject is true then
					delete myObject
				end if
			end if
		end tell
	end if
	
	--display dialog myAlign & " 2nd attempt"
	
	
	
	---------------------
	---------------------
	---------------------
	---------------------Center
	--Do nothing for center alignment
	if myColumnGutter is equal to 0 and myRowGutter is equal to 0 and myAlign is equal to "center alignment" then
		
		
		tell application "Adobe InDesign CS4"
			set myBounds to geometric bounds of myObject
			--display dialog myBounds as list
			set myWidth to (item 4 of myBounds) - (item 2 of myBounds) -- (myStrokeWidth )
			set myHeight to (item 3 of myBounds) - (item 1 of myBounds) -- (myStrokeWidth )
			--Don't bother making the frames if the width/height of the frame is too small
			--to accomodate the row/column gutter values.	
			if ((myRowGutter * (myNumberOfRows - 1) < myHeight) and (myColumnGutter * (myNumberOfColumns - 1) < myWidth)) then
				set myColumnWidth to (myWidth - (myColumnGutter * (myNumberOfColumns - 1))) / myNumberOfColumns
				try
					set myRowHeight to (myHeight - (myRowGutter * (myNumberOfRows - 1))) / myNumberOfRows
				on error
					display dialog "wow"
					my theError()
					if errorNumber is equal to 1 then
						return
					end if
				end try
				
				
				repeat with myRowCounter from 0 to myNumberOfRows - 1
					set myY1 to (item 1 of myBounds) + (myRowHeight * myRowCounter) + (myRowGutter * myRowCounter)
					set myY2 to myY1 + (myRowHeight) --+ (myStrokeWidth / 2)
					repeat with myColumnCounter from 0 to myNumberOfColumns - 1
						set myX1 to (item 2 of myBounds) + (myColumnWidth * myColumnCounter) + (myColumnGutter * myColumnCounter)
						--set myX2 to myX1 + myColumnWidth
						set myX2 to myX1 + (myColumnWidth) --+ (myStrokeWidth / 2)
						if myRetainFormatting is true then
							set myNewObject to duplicate myObject
							set geometric bounds of myNewObject to {myY1, myX1, myY2, myX2}
							(* else
						tell parent of myObject
							set myNewObject to make rectangle with properties {geometric bounds:{myY1, myX1, myY2, myX2}, content type:myFrameType}
						end tell *)
						end if
					end repeat
				end repeat
				if myDeleteObject is true then
					delete myObject
				end if
			end if
		end tell
	end if
	
	
	if myColumnGutter is greater than 0 and myRowGutter is equal to 0 and myAlign is equal to "center alignment" then
		
		
		tell application "Adobe InDesign CS4"
			set myBounds to geometric bounds of myObject
			--display dialog myBounds as list
			set myWidth to (item 4 of myBounds) - (item 2 of myBounds) + (myStrokeWidth)
			set myHeight to (item 3 of myBounds) - (item 1 of myBounds)
			--Don't bother making the frames if the width/height of the frame is too small
			--to accomodate the row/column gutter values.	
			if ((myRowGutter * (myNumberOfRows - 1) < myHeight) and (myColumnGutter * (myNumberOfColumns - 1) < myWidth)) then
				set myColumnWidth to (myWidth - (myColumnGutter * (myNumberOfColumns - 1))) / myNumberOfColumns
				try
					set myRowHeight to (myHeight - (myRowGutter * (myNumberOfRows - 1))) / myNumberOfRows
				on error
					my theError()
					if errorNumber is equal to 1 then
						return
					end if
				end try
				
				
				repeat with myRowCounter from 0 to myNumberOfRows - 1
					set myY1 to (item 1 of myBounds) + (myRowHeight * myRowCounter) + (myRowGutter * myRowCounter)
					set myY2 to myY1 + (myRowHeight)
					repeat with myColumnCounter from 0 to myNumberOfColumns - 1
						set myX1 to (item 2 of myBounds) + (myColumnWidth * myColumnCounter) + (myColumnGutter * myColumnCounter)
						--set myX2 to myX1 + myColumnWidth
						set myX2 to myX1 + (myColumnWidth) - (myStrokeWidth)
						if myRetainFormatting is true then
							set myNewObject to duplicate myObject
							set geometric bounds of myNewObject to {myY1, myX1, myY2, myX2}
							(* else
						tell parent of myObject
							set myNewObject to make rectangle with properties {geometric bounds:{myY1, myX1, myY2, myX2}, content type:myFrameType}
						end tell *)
						end if
					end repeat
				end repeat
				if myDeleteObject is true then
					delete myObject
				end if
			end if
		end tell
	end if
	
	
	if myColumnGutter is equal to 0 and myRowGutter is greater than 0 and myAlign is equal to "center alignment" then
		
		
		tell application "Adobe InDesign CS4"
			set myBounds to geometric bounds of myObject
			--display dialog myBounds as list
			set myWidth to (item 4 of myBounds) - (item 2 of myBounds)
			set myHeight to (item 3 of myBounds) - (item 1 of myBounds) + (myStrokeWidth)
			--Don't bother making the frames if the width/height of the frame is too small
			--to accomodate the row/column gutter values.	
			if ((myRowGutter * (myNumberOfRows - 1) < myHeight) and (myColumnGutter * (myNumberOfColumns - 1) < myWidth)) then
				set myColumnWidth to (myWidth - (myColumnGutter * (myNumberOfColumns - 1))) / myNumberOfColumns
				try
					set myRowHeight to (myHeight - (myRowGutter * (myNumberOfRows - 1))) / myNumberOfRows
				on error
					my theError()
					if errorNumber is equal to 1 then
						return
					end if
				end try
				
				
				repeat with myRowCounter from 0 to myNumberOfRows - 1
					set myY1 to (item 1 of myBounds) + (myRowHeight * myRowCounter) + (myRowGutter * myRowCounter)
					set myY2 to myY1 + (myRowHeight) - (myStrokeWidth)
					repeat with myColumnCounter from 0 to myNumberOfColumns - 1
						set myX1 to (item 2 of myBounds) + (myColumnWidth * myColumnCounter) + (myColumnGutter * myColumnCounter)
						--set myX2 to myX1 + myColumnWidth
						set myX2 to myX1 + (myColumnWidth) -- (myStrokeWidth)
						if myRetainFormatting is true then
							set myNewObject to duplicate myObject
							set geometric bounds of myNewObject to {myY1, myX1, myY2, myX2}
							(* else
						tell parent of myObject
							set myNewObject to make rectangle with properties {geometric bounds:{myY1, myX1, myY2, myX2}, content type:myFrameType}
						end tell *)
						end if
					end repeat
				end repeat
				if myDeleteObject is true then
					delete myObject
				end if
			end if
		end tell
	end if
	
	
	if myColumnGutter is greater than 0 and myRowGutter is greater than 0 and myAlign is equal to "center alignment" then
		
		
		tell application "Adobe InDesign CS4"
			set myBounds to geometric bounds of myObject
			--display dialog myBounds as list
			set myWidth to (item 4 of myBounds) - (item 2 of myBounds) + (myStrokeWidth)
			set myHeight to (item 3 of myBounds) - (item 1 of myBounds) + (myStrokeWidth)
			--Don't bother making the frames if the width/height of the frame is too small
			--to accomodate the row/column gutter values.	
			if ((myRowGutter * (myNumberOfRows - 1) < myHeight) and (myColumnGutter * (myNumberOfColumns - 1) < myWidth)) then
				set myColumnWidth to (myWidth - (myColumnGutter * (myNumberOfColumns - 1))) / myNumberOfColumns
				try
					set myRowHeight to (myHeight - (myRowGutter * (myNumberOfRows - 1))) / myNumberOfRows
				on error
					my theError()
					if errorNumber is equal to 1 then
						return
					end if
				end try
				
				
				repeat with myRowCounter from 0 to myNumberOfRows - 1
					set myY1 to (item 1 of myBounds) + (myRowHeight * myRowCounter) + (myRowGutter * myRowCounter)
					set myY2 to myY1 + (myRowHeight) - (myStrokeWidth)
					repeat with myColumnCounter from 0 to myNumberOfColumns - 1
						set myX1 to (item 2 of myBounds) + (myColumnWidth * myColumnCounter) + (myColumnGutter * myColumnCounter)
						--set myX2 to myX1 + myColumnWidth
						set myX2 to myX1 + (myColumnWidth) - (myStrokeWidth)
						if myRetainFormatting is true then
							set myNewObject to duplicate myObject
							set geometric bounds of myNewObject to {myY1, myX1, myY2, myX2}
							(* else
						tell parent of myObject
							set myNewObject to make rectangle with properties {geometric bounds:{myY1, myX1, myY2, myX2}, content type:myFrameType}
						end tell *)
						end if
					end repeat
				end repeat
				if myDeleteObject is true then
					delete myObject
				end if
			end if
		end tell
	end if
	---------------------
	---------------------
	---------------------
	---------------------end Center
	
	
	---------------------
	---------------------
	---------------------
	---------------------outside
	--
	if myColumnGutter is equal to 0 and myRowGutter is equal to 0 and myAlign is equal to "outside alignment" then
		
		
		tell application "Adobe InDesign CS4"
			set myBounds to geometric bounds of myObject
			--display dialog myBounds as list
			set myWidth to (item 4 of myBounds) - (item 2 of myBounds) + myStrokeWidth
			set myHeight to (item 3 of myBounds) - (item 1 of myBounds) + myStrokeWidth
			--Don't bother making the frames if the width/height of the frame is too small
			--to accomodate the row/column gutter values.	
			if ((myRowGutter * (myNumberOfRows - 1) < myHeight) and (myColumnGutter * (myNumberOfColumns - 1) < myWidth)) then
				set myColumnWidth to (myWidth - (myColumnGutter * (myNumberOfColumns - 1))) / myNumberOfColumns
				try
					set myRowHeight to (myHeight - (myRowGutter * (myNumberOfRows - 1))) / myNumberOfRows
				on error
					my theError()
					if errorNumber is equal to 1 then
						return
					end if
				end try
				
				
				repeat with myRowCounter from 0 to myNumberOfRows - 1
					set myY1 to (item 1 of myBounds) + (myRowHeight * myRowCounter) + (myRowGutter * myRowCounter)
					set myY2 to myY1 + (myRowHeight) - myStrokeWidth
					repeat with myColumnCounter from 0 to myNumberOfColumns - 1
						set myX1 to (item 2 of myBounds) + (myColumnWidth * myColumnCounter) + (myColumnGutter * myColumnCounter)
						--set myX2 to myX1 + myColumnWidth
						set myX2 to myX1 + (myColumnWidth) - myStrokeWidth
						if myRetainFormatting is true then
							set myNewObject to duplicate myObject
							set geometric bounds of myNewObject to {myY1, myX1, myY2, myX2}
							(* else
						tell parent of myObject
							set myNewObject to make rectangle with properties {geometric bounds:{myY1, myX1, myY2, myX2}, content type:myFrameType}
						end tell *)
						end if
					end repeat
				end repeat
				if myDeleteObject is true then
					delete myObject
				end if
			end if
		end tell
	end if
	
	
	if myColumnGutter is greater than 0 and myRowGutter is equal to 0 and myAlign is equal to "outside alignment" then
		
		
		tell application "Adobe InDesign CS4"
			set myBounds to geometric bounds of myObject
			--display dialog myBounds as list
			set myWidth to (item 4 of myBounds) - (item 2 of myBounds)
			set myHeight to (item 3 of myBounds) - (item 1 of myBounds)
			--Don't bother making the frames if the width/height of the frame is too small
			--to accomodate the row/column gutter values.	
			if ((myRowGutter * (myNumberOfRows - 1) < myHeight) and (myColumnGutter * (myNumberOfColumns - 1) < myWidth)) then
				set myColumnWidth to (myWidth - (myColumnGutter * (myNumberOfColumns - 1))) / myNumberOfColumns
				try
					set myRowHeight to (myHeight - (myRowGutter * (myNumberOfRows - 1))) / myNumberOfRows
				on error
					my theError()
					if errorNumber is equal to 1 then
						return
					end if
				end try
				
				repeat with myRowCounter from 0 to myNumberOfRows - 1
					set myY1 to (item 1 of myBounds) + (myRowHeight * myRowCounter) + (myRowGutter * myRowCounter)
					set myY2 to myY1 + (myRowHeight)
					repeat with myColumnCounter from 0 to myNumberOfColumns - 1
						set myX1 to (item 2 of myBounds) + (myColumnWidth * myColumnCounter) + (myColumnGutter * myColumnCounter)
						--set myX2 to myX1 + myColumnWidth
						set myX2 to myX1 + (myColumnWidth) + (myStrokeWidth)
						if myRetainFormatting is true then
							set myNewObject to duplicate myObject
							set geometric bounds of myNewObject to {myY1, myX1, myY2, myX2}
							(* else
						tell parent of myObject
							set myNewObject to make rectangle with properties {geometric bounds:{myY1, myX1, myY2, myX2}, content type:myFrameType}
						end tell *)
						end if
					end repeat
				end repeat
				if myDeleteObject is true then
					delete myObject
				end if
			end if
		end tell
	end if
	
	
	if myColumnGutter is equal to 0 and myRowGutter is greater than 0 and myAlign is equal to "outside alignment" then
		
		
		tell application "Adobe InDesign CS4"
			set myBounds to geometric bounds of myObject
			--display dialog myBounds as list
			set myWidth to (item 4 of myBounds) - (item 2 of myBounds) + (myStrokeWidth)
			set myHeight to (item 3 of myBounds) - (item 1 of myBounds) + (myStrokeWidth * 2)
			--Don't bother making the frames if the width/height of the frame is too small
			--to accomodate the row/column gutter values.	
			if ((myRowGutter * (myNumberOfRows - 1) < myHeight) and (myColumnGutter * (myNumberOfColumns - 1) < myWidth)) then
				set myColumnWidth to (myWidth - (myColumnGutter * (myNumberOfColumns - 1))) / myNumberOfColumns
				try
					set myRowHeight to (myHeight - (myRowGutter * (myNumberOfRows - 1))) / myNumberOfRows
				on error
					my theError()
					if errorNumber is equal to 1 then
						return
					end if
				end try
				
				repeat with myRowCounter from 0 to myNumberOfRows - 1
					set myY1 to (item 1 of myBounds) + (myRowHeight * myRowCounter) + (myRowGutter * myRowCounter)
					set myY2 to myY1 + (myRowHeight) - (myStrokeWidth * 2)
					repeat with myColumnCounter from 0 to myNumberOfColumns - 1
						set myX1 to (item 2 of myBounds) + (myColumnWidth * myColumnCounter) + (myColumnGutter * myColumnCounter)
						--set myX2 to myX1 + myColumnWidth
						set myX2 to myX1 + (myColumnWidth) - (myStrokeWidth)
						if myRetainFormatting is true then
							set myNewObject to duplicate myObject
							set geometric bounds of myNewObject to {myY1, myX1, myY2, myX2}
							(* else
						tell parent of myObject
							set myNewObject to make rectangle with properties {geometric bounds:{myY1, myX1, myY2, myX2}, content type:myFrameType}
						end tell *)
						end if
					end repeat
				end repeat
				if myDeleteObject is true then
					delete myObject
				end if
			end if
		end tell
	end if
	
	
	if myColumnGutter is greater than 0 and myRowGutter is greater than 0 and myAlign is equal to "outside alignment" then
		
		
		tell application "Adobe InDesign CS4"
			set myBounds to geometric bounds of myObject
			--display dialog myBounds as list
			set myWidth to (item 4 of myBounds) - (item 2 of myBounds) + (myStrokeWidth * 2)
			set myHeight to (item 3 of myBounds) - (item 1 of myBounds) + (myStrokeWidth * 2)
			--Don't bother making the frames if the width/height of the frame is too small
			--to accomodate the row/column gutter values.	
			if ((myRowGutter * (myNumberOfRows - 1) < myHeight) and (myColumnGutter * (myNumberOfColumns - 1) < myWidth)) then
				set myColumnWidth to (myWidth - (myColumnGutter * (myNumberOfColumns - 1))) / myNumberOfColumns
				try
					set myRowHeight to (myHeight - (myRowGutter * (myNumberOfRows - 1))) / myNumberOfRows
				on error
					my theError()
					if errorNumber is equal to 1 then
						return
					end if
				end try
				
				
				repeat with myRowCounter from 0 to myNumberOfRows - 1
					set myY1 to (item 1 of myBounds) + (myRowHeight * myRowCounter) + (myRowGutter * myRowCounter)
					set myY2 to myY1 + (myRowHeight) - (myStrokeWidth * 2)
					repeat with myColumnCounter from 0 to myNumberOfColumns - 1
						set myX1 to (item 2 of myBounds) + (myColumnWidth * myColumnCounter) + (myColumnGutter * myColumnCounter)
						--set myX2 to myX1 + myColumnWidth
						set myX2 to myX1 + (myColumnWidth) - (myStrokeWidth * 2)
						if myRetainFormatting is true then
							set myNewObject to duplicate myObject
							set geometric bounds of myNewObject to {myY1, myX1, myY2, myX2}
							(* else
						tell parent of myObject
							set myNewObject to make rectangle with properties {geometric bounds:{myY1, myX1, myY2, myX2}, content type:myFrameType}
						end tell *)
						end if
					end repeat
				end repeat
				if myDeleteObject is true then
					delete myObject
				end if
			end if
		end tell
	end if
	---------------------
	---------------------
	---------------------
	---------------------end outside
	
end mySplitFrame


That’s correct behavior, and probably a clue to what your problem is.

When a compiled script is saved, all the commands and properties are saved as four-letter codes; they are converted to terms like “rectangle” by Script Editor when it opens them, and back to the codes when you save. To do this translation, Script Editor has to load the app’s dictionary.

But once a script is compiled, it would only slow things down needlessly if the dictionary had to be loaded and the terminology translated every time the script was run. So you should never rely on coercion of terminology.

That’s where I’d start looking – the result in Script Editor is going to be the full English-like term, but in a compiled script it will be the four-letter code. Don’t try to coerce terminology to text.

Wow Shane, you help me out so much. I can’t thank you enough.

FWIW, this script is a modified version of one that ships with InDesign. Unfortunately, the script that ships doesn’t account for the stroke alignment, which could yield inconsistent gutter widths based on what the operator applies in the gutter width dialog field.

So, I must now ask.

You state: “Don’t try to coerce terminology to text.”

I assume this means, use the non-English like terms within the script, which I did and it works well with my if statements.

So my test for stroke alignments now look like this:

myAlign contains “stAI” then → inside alignment
myAlign contains “stAC” then → center alignment
myAlign contains “stAO” then → outside alignment

Ironically, we use QuicKeys where I work. And this same script embedded in a QuicKey does not require the modified code directly above. Does this mean that QuicKeys is performing a dictionary conversion when it runs?

--MakeGrid.applescript
--An InDesign CS4 AppleScript
--
--Divides the selected frame (or frames) into grid(s) of frames.
--
--For more on InDesign scripting, go to http://www.adobe.com/products/indesign/scripting.html
--or visit the InDesign Scripting User to User forum at http://www.adobeforums.com.
--

global myStrokeWidth
global myAlign
global myNumberOfRows
global myNumberOfColumns
global errorNumber

on theError()
	tell application "SystemUIServer"
		activate
		set userResponse to display dialog "You must have at least 1 row and 1 column." buttons {" Cancel "} default button " Cancel " with icon 2
		
		if button returned of userResponse contains " Cancel " then
			set errorNumber to 1
		end if
		if button returned of userResponse contains " Cancel " then
			return
		end if
	end tell
end theError


set errorNumber to 0
set myObjectList to {}
tell application "Adobe InDesign CS4"
	
	set myPageItemTypes to {rectangle, oval, text frame, group}
	if (count documents) > 0 then
		tell document 1
			set mySelection to selection
			--end tell
			if (count mySelection) > 0 then
				repeat with MyCounter from 1 to (count mySelection)
					if (class of item MyCounter of mySelection) is group then
						display dialog "Does not work on grouped items." buttons {"Cancel"} default button "Cancel" with icon 2
					end if
					set xClass to class of item MyCounter of mySelection as text
					--display dialog xClass as string
					if (class of item MyCounter of mySelection) is in myPageItemTypes then
						copy item MyCounter of mySelection to end of myObjectList
						set myStrokeWidth to stroke weight of selection
						set myAlign to stroke alignment of selection as string
						--display dialog myAlign
					end if
				end repeat
				if (count myObjectList) > 1 then
					display dialog "You have more than one frame selected. Select only one frame and try again." buttons {"Cancel"} default button "Cancel" with icon 2
				end if
				if (count myObjectList) < 2 then
					my myDisplayDialog(myObjectList)
					--set myStrokeWeight to stroke weight of selection
					--stroke alignment:inside alignment}
				else
					display dialog "You must have a frame selected." buttons {"Cancel"} default button "Cancel" with icon 2
				end if
				
			else
				display dialog "You must have a frame selected." buttons {"Cancel"} default button "Cancel" with icon 2
				
			end if
		end tell
	else
		display dialog "Please open a document, select a page item, and try again."
	end if
	
end tell
on myDisplayDialog(myObjectList)
	tell application "Adobe InDesign CS4"
		set myLabelWidth to 100
		set myFrameTypes to {"Unassigned", "Text", "Graphic"}
		set myDialog to make dialog with properties {name:"MakeGrid"}
		tell myDialog
			tell (make dialog column)
				tell (make dialog row)
					tell (make dialog column)
						make static text with properties {static label:"Rows _-_-_-_-_-_- ", min width:myLabelWidth}
						make static text with properties {static label:"Columns | | | | | | | |", min width:myLabelWidth}
					end tell
					tell (make dialog column)
						set myNumberOfRowsField to make integer editbox with properties {edit value:1}
						set myNumberOfColumnsField to make integer editbox with properties {edit value:4}
					end tell
				end tell
				tell (make dialog row)
					tell (make dialog column)
						make static text with properties {static label:"Gutter width:", min width:myLabelWidth}
					end tell
					tell (make dialog column)
						set myRowGutterField 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:"Column Gutter:", min width:myLabelWidth}
					end tell
					tell (make dialog column)
						set myColumnGutterField 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:"Frame Type:", min width:myLabelWidth}
					end tell
					tell (make dialog column)
						set myFrameTypeDropdown to make dropdown with properties {string list:myFrameTypes, selected index:0}
					end tell
				end tell
				set myRetainFormattingCheckbox to {checked state:true}
				set myDeleteObjectCheckbox to make checkbox control with properties {static label:"Delete Original Object", checked state:true}
			end tell
		end tell
		set myResult to show myDialog
		if myResult is true then
			set myNumberOfRows to edit value of myNumberOfRowsField
			set myNumberOfColumns to edit value of myNumberOfColumnsField
			set myRowGutter to edit value of myRowGutterField
			set myColumnGutter to edit value of myRowGutterField
			
			
			
			--display dialog myColumnGutter
			
			
			
			set myRetainFormatting to checked state of myRetainFormattingCheckbox
			set myDeleteObject to checked state of myDeleteObjectCheckbox
			get selected index of myFrameTypeDropdown
			if selected index of myFrameTypeDropdown is 0 then
				set myFrameType to unassigned
			else if selected index of myFrameTypeDropdown is 1 then
				set myFrameType to text type
			else if selected index of myFrameTypeDropdown is 2 then
				set myFrameType to graphic type
			end if
			destroy myDialog
			my mySplitFrames(myObjectList, myNumberOfRows, myNumberOfColumns, myRowGutter, myColumnGutter, myFrameType, myRetainFormatting, myDeleteObject)
		else
			destroy myDialog
		end if
	end tell
end myDisplayDialog
------
if errorNumber is equal to 1 then
	tell application "Adobe InDesign CS4"
		activate
	end tell
end if
if errorNumber is equal to 1 then error number -128

on mySplitFrames(myObjectList, myNumberOfRows, myNumberOfColumns, myRowGutter, myColumnGutter, myFrameType, myRetainFormatting, myDeleteObject)
	tell application "Adobe InDesign CS4"
		set myDocument to active document
		
		--Save the current measurement units.
		set myOldXUnits to horizontal measurement units of view preferences of myDocument
		set myOldYUnits to vertical measurement units of view preferences of myDocument
		--Set the current measurement units to points.
		set horizontal measurement units of view preferences of myDocument to points
		set vertical measurement units of view preferences of myDocument to points
		repeat with MyCounter from 1 to (count myObjectList)
			my mySplitFrame(item MyCounter of myObjectList, myNumberOfRows, myNumberOfColumns, myRowGutter, myColumnGutter, myFrameType, myRetainFormatting, myDeleteObject)
		end repeat
		set horizontal measurement units of view preferences of myDocument to myOldXUnits
		set vertical measurement units of view preferences of myDocument to myOldYUnits
	end tell
end mySplitFrames
on mySplitFrame(myObject, myNumberOfRows, myNumberOfColumns, myRowGutter, myColumnGutter, myFrameType, myRetainFormatting, myDeleteObject)
	--if myColumnGutter is equal to 0 and myRowGutter is equal to 0 and myAlign is equal to "inside alignment" then
	
	if myColumnGutter is equal to 0 and myRowGutter is equal to 0 and myAlign contains "stAI" then
		tell application "Adobe InDesign CS4"
			set myBounds to geometric bounds of myObject
			--display dialog myBounds as list
			set myWidth to (item 4 of myBounds) - (item 2 of myBounds) - myStrokeWidth
			set myHeight to (item 3 of myBounds) - (item 1 of myBounds) - myStrokeWidth
			--Don't bother making the frames if the width/height of the frame is too small
			--to accomodate the row/column gutter values.	
			if ((myRowGutter * (myNumberOfRows - 1) < myHeight) and (myColumnGutter * (myNumberOfColumns - 1) < myWidth)) then
				set myColumnWidth to (myWidth - (myColumnGutter * (myNumberOfColumns - 1))) / myNumberOfColumns
				try
					set myRowHeight to (myHeight - (myRowGutter * (myNumberOfRows - 1))) / myNumberOfRows
				on error
					my theError()
					if errorNumber is equal to 1 then
						return
					end if
				end try
				
				
				repeat with myRowCounter from 0 to myNumberOfRows - 1
					set myY1 to (item 1 of myBounds) + (myRowHeight * myRowCounter) + (myRowGutter * myRowCounter)
					set myY2 to myY1 + (myRowHeight + myStrokeWidth)
					repeat with myColumnCounter from 0 to myNumberOfColumns - 1
						set myX1 to (item 2 of myBounds) + (myColumnWidth * myColumnCounter) + (myColumnGutter * myColumnCounter)
						--set myX2 to myX1 + myColumnWidth
						set myX2 to myX1 + (myColumnWidth + myStrokeWidth)
						if myRetainFormatting is true then
							set myNewObject to duplicate myObject
							set geometric bounds of myNewObject to {myY1, myX1, myY2, myX2}
							(* else
						tell parent of myObject
							set myNewObject to make rectangle with properties {geometric bounds:{myY1, myX1, myY2, myX2}, content type:myFrameType}
						end tell *)
						end if
					end repeat
				end repeat
				if myDeleteObject is true then
					delete myObject
				end if
			end if
		end tell
	end if
	
	
	
	
	
	--if myColumnGutter is equal to 0 and myRowGutter is greater than 0 and myAlign is equal to "inside alignment" then --and right here determine the alignment of stroke, if it is inside then use this below script. Anthying else we use the one far below.
	if myColumnGutter is equal to 0 and myRowGutter is greater than 0 and myAlign contains "stAI" then
		tell application "Adobe InDesign CS4"
			set myBounds to geometric bounds of myObject
			set myWidth to (item 4 of myBounds) - (item 2 of myBounds) - myStrokeWidth
			set myHeight to (item 3 of myBounds) - (item 1 of myBounds) + myStrokeWidth
			--Don't bother making the frames if the width/height of the frame is too small
			--to accomodate the row/column gutter values.	
			if ((myRowGutter * (myNumberOfRows - 1) < myHeight) and (myColumnGutter * (myNumberOfColumns - 1) < myWidth)) then
				set myColumnWidth to (myWidth - (myColumnGutter * (myNumberOfColumns - 1))) / myNumberOfColumns
				try
					set myRowHeight to (myHeight - (myRowGutter * (myNumberOfRows - 1))) / myNumberOfRows
				on error
					my theError()
					if errorNumber is equal to 1 then
						return
					end if
				end try
				repeat with myRowCounter from 0 to myNumberOfRows - 1
					set myY1 to (item 1 of myBounds) + (myRowHeight * myRowCounter) + (myRowGutter * myRowCounter)
					set myY2 to myY1 + (myRowHeight - myStrokeWidth)
					repeat with myColumnCounter from 0 to myNumberOfColumns - 1
						set myX1 to (item 2 of myBounds) + (myColumnWidth * myColumnCounter) + (myColumnGutter * myColumnCounter)
						set myX2 to myX1 + (myColumnWidth + myStrokeWidth)
						if myRetainFormatting is true then
							set myNewObject to duplicate myObject
							set geometric bounds of myNewObject to {myY1, myX1, myY2, myX2}
							(* else
						tell parent of myObject
							set myNewObject to make rectangle with properties {geometric bounds:{myY1, myX1, myY2, myX2}, content type:myFrameType}
						end tell *)
						end if
					end repeat
				end repeat
				if myDeleteObject is true then
					delete myObject
				end if
			end if
		end tell
	end if
	
	--display dialog myAlign
	--display dialog myColumnGutter
	--display dialog myRowGutter
	
	(* if myColumnGutter is greater than 0 and myRowGutter is equal to 0 and myAlign is equal to "inside alignment" then
	end if *)
	----
	----
	----
	----
	----
	----Number of Rows is greater than 1
	--if myColumnGutter is greater than 0 and myRowGutter is equal to 0 and my myNumberOfRows is greater than 1 and myAlign is equal to "inside alignment" then
	
	
	if myColumnGutter is greater than 0 and myRowGutter is equal to 0 and my myNumberOfRows is greater than 1 and myAlign contains "stAI" then
		
		tell application "Adobe InDesign CS4"
			set myBounds to geometric bounds of myObject
			set myWidth to (item 4 of myBounds) - (item 2 of myBounds) -- myStrokeWidth
			set myHeight to (item 3 of myBounds) - (item 1 of myBounds) + myStrokeWidth
			--Don't bother making the frames if the width/height of the frame is too small
			--to accomodate the row/column gutter values.	
			if ((myRowGutter * (myNumberOfRows - 1) < myHeight) and (myColumnGutter * (myNumberOfColumns - 1) < myWidth)) then
				set myColumnWidth to (myWidth - (myColumnGutter * (myNumberOfColumns - 1))) / myNumberOfColumns
				try
					set myRowHeight to (myHeight - (myRowGutter * (myNumberOfRows - 1))) / myNumberOfRows
				on error
					my theError()
					if errorNumber is equal to 1 then
						return
					end if
				end try
				repeat with myRowCounter from 0 to myNumberOfRows - 1
					set myY1 to (item 1 of myBounds) + (myRowHeight * myRowCounter) + (myRowGutter * myRowCounter)
					set myY2 to myY1 + (myRowHeight) - myStrokeWidth
					repeat with myColumnCounter from 0 to myNumberOfColumns - 1
						set myX1 to (item 2 of myBounds) + (myColumnWidth * myColumnCounter) + (myColumnGutter * myColumnCounter)
						set myX2 to myX1 + (myColumnWidth)
						if myRetainFormatting is true then
							set myNewObject to duplicate myObject
							set geometric bounds of myNewObject to {myY1, myX1, myY2, myX2}
							(* else
						tell parent of myObject
							set myNewObject to make rectangle with properties {geometric bounds:{myY1, myX1, myY2, myX2}, content type:myFrameType}
						end tell *)
						end if
					end repeat
				end repeat
				if myDeleteObject is true then
					delete myObject
				end if
			end if
		end tell
		
	end if
	----
	----
	----
	----
	----
	----
	----
	----
	----
	----
	----Number of Coulumns is greater than 1
	--if myColumnGutter is greater than 0 and myRowGutter is equal to 0 and my myNumberOfColumns is greater than 1 and myAlign is equal to "inside alignment" 
	
	if myColumnGutter is greater than 0 and myRowGutter is equal to 0 and my myNumberOfColumns is greater than 1 and myAlign contains "stAI" then
		
		tell application "Adobe InDesign CS4"
			set myBounds to geometric bounds of myObject
			set myWidth to (item 4 of myBounds) - (item 2 of myBounds) + myStrokeWidth
			set myHeight to (item 3 of myBounds) - (item 1 of myBounds) -- myStrokeWidth
			--Don't bother making the frames if the width/height of the frame is too small
			--to accomodate the row/column gutter values.	
			if ((myRowGutter * (myNumberOfRows - 1) < myHeight) and (myColumnGutter * (myNumberOfColumns - 1) < myWidth)) then
				set myColumnWidth to (myWidth - (myColumnGutter * (myNumberOfColumns - 1))) / myNumberOfColumns
				try
					set myRowHeight to (myHeight - (myRowGutter * (myNumberOfRows - 1))) / myNumberOfRows
				on error
					my theError()
					if errorNumber is equal to 1 then
						return
					end if
				end try
				repeat with myRowCounter from 0 to myNumberOfRows - 1
					set myY1 to (item 1 of myBounds) + (myRowHeight * myRowCounter) + (myRowGutter * myRowCounter)
					set myY2 to myY1 + (myRowHeight)
					repeat with myColumnCounter from 0 to myNumberOfColumns - 1
						set myX1 to (item 2 of myBounds) + (myColumnWidth * myColumnCounter) + (myColumnGutter * myColumnCounter)
						set myX2 to myX1 + (myColumnWidth) - myStrokeWidth
						if myRetainFormatting is true then
							set myNewObject to duplicate myObject
							set geometric bounds of myNewObject to {myY1, myX1, myY2, myX2}
							(* else
						tell parent of myObject
							set myNewObject to make rectangle with properties {geometric bounds:{myY1, myX1, myY2, myX2}, content type:myFrameType}
						end tell *)
						end if
					end repeat
				end repeat
				if myDeleteObject is true then
					delete myObject
				end if
			end if
		end tell
		
	end if
	----
	----
	----
	----
	----
	--if myColumnGutter is greater than 0 and myRowGutter is greater than 0 and myAlign is equal to "inside alignment" then
	
	if myColumnGutter is greater than 0 and myRowGutter is greater than 0 and myAlign contains "stAI" then
		
		tell application "Adobe InDesign CS4"
			set myBounds to geometric bounds of myObject
			set myWidth to (item 4 of myBounds) - (item 2 of myBounds) -- myStrokeWidth
			set myHeight to (item 3 of myBounds) - (item 1 of myBounds) -- myStrokeWidth
			--Don't bother making the frames if the width/height of the frame is too small
			--to accomodate the row/column gutter values.	
			if ((myRowGutter * (myNumberOfRows - 1) < myHeight) and (myColumnGutter * (myNumberOfColumns - 1) < myWidth)) then
				set myColumnWidth to (myWidth - (myColumnGutter * (myNumberOfColumns - 1))) / myNumberOfColumns
				try
					set myRowHeight to (myHeight - (myRowGutter * (myNumberOfRows - 1))) / myNumberOfRows
				on error
					my theError()
					if errorNumber is equal to 1 then
						return
					end if
				end try
				repeat with myRowCounter from 0 to myNumberOfRows - 1
					set myY1 to (item 1 of myBounds) + (myRowHeight * myRowCounter) + (myRowGutter * myRowCounter)
					set myY2 to myY1 + (myRowHeight)
					repeat with myColumnCounter from 0 to myNumberOfColumns - 1
						set myX1 to (item 2 of myBounds) + (myColumnWidth * myColumnCounter) + (myColumnGutter * myColumnCounter)
						set myX2 to myX1 + (myColumnWidth)
						if myRetainFormatting is true then
							set myNewObject to duplicate myObject
							set geometric bounds of myNewObject to {myY1, myX1, myY2, myX2}
							(* else
						tell parent of myObject
							set myNewObject to make rectangle with properties {geometric bounds:{myY1, myX1, myY2, myX2}, content type:myFrameType}
						end tell *)
						end if
					end repeat
				end repeat
				if myDeleteObject is true then
					delete myObject
				end if
			end if
		end tell
	end if
	
	--display dialog myAlign & " 2nd attempt"
	
	
	
	---------------------
	---------------------
	---------------------
	---------------------Center
	--Do nothing for center alignment
	--display dialog myColumnGutter & "   my colulmn gutter" as string
	--display dialog myAlign & "    my align" as string
	--if myColumnGutter is less than 1 and myRowGutter is less than 1 and myAlign  "center alignment" then
	
	if myColumnGutter is less than 1 and myRowGutter is less than 1 and myAlign contains "stAC" then
		--display dialog myAlign as string
		
		
		tell application "Adobe InDesign CS4"
			set myBounds to geometric bounds of myObject
			--display dialog myBounds as list
			set myWidth to (item 4 of myBounds) - (item 2 of myBounds) -- (myStrokeWidth )
			set myHeight to (item 3 of myBounds) - (item 1 of myBounds) -- (myStrokeWidth )
			--Don't bother making the frames if the width/height of the frame is too small
			--to accomodate the row/column gutter values.	
			if ((myRowGutter * (myNumberOfRows - 1) < myHeight) and (myColumnGutter * (myNumberOfColumns - 1) < myWidth)) then
				set myColumnWidth to (myWidth - (myColumnGutter * (myNumberOfColumns - 1))) / myNumberOfColumns
				try
					set myRowHeight to (myHeight - (myRowGutter * (myNumberOfRows - 1))) / myNumberOfRows
				on error
					my theError()
					if errorNumber is equal to 1 then
						return
					end if
				end try
				
				
				repeat with myRowCounter from 0 to myNumberOfRows - 1
					set myY1 to (item 1 of myBounds) + (myRowHeight * myRowCounter) + (myRowGutter * myRowCounter)
					set myY2 to myY1 + (myRowHeight) --+ (myStrokeWidth / 2)
					repeat with myColumnCounter from 0 to myNumberOfColumns - 1
						set myX1 to (item 2 of myBounds) + (myColumnWidth * myColumnCounter) + (myColumnGutter * myColumnCounter)
						--set myX2 to myX1 + myColumnWidth
						set myX2 to myX1 + (myColumnWidth) --+ (myStrokeWidth / 2)
						if myRetainFormatting is true then
							set myNewObject to duplicate myObject
							set geometric bounds of myNewObject to {myY1, myX1, myY2, myX2}
							(* else
						tell parent of myObject
							set myNewObject to make rectangle with properties {geometric bounds:{myY1, myX1, myY2, myX2}, content type:myFrameType}
						end tell *)
						end if
					end repeat
				end repeat
				if myDeleteObject is true then
					--display dialog "should delete"
					delete myObject
				end if
			end if
		end tell
	end if
	
	
	if myColumnGutter is greater than 0 and myRowGutter is equal to 0 and myAlign contains "stAC" then
		
		
		tell application "Adobe InDesign CS4"
			set myBounds to geometric bounds of myObject
			--display dialog myBounds as list
			set myWidth to (item 4 of myBounds) - (item 2 of myBounds) + (myStrokeWidth)
			set myHeight to (item 3 of myBounds) - (item 1 of myBounds)
			--Don't bother making the frames if the width/height of the frame is too small
			--to accomodate the row/column gutter values.	
			if ((myRowGutter * (myNumberOfRows - 1) < myHeight) and (myColumnGutter * (myNumberOfColumns - 1) < myWidth)) then
				set myColumnWidth to (myWidth - (myColumnGutter * (myNumberOfColumns - 1))) / myNumberOfColumns
				try
					set myRowHeight to (myHeight - (myRowGutter * (myNumberOfRows - 1))) / myNumberOfRows
				on error
					my theError()
					if errorNumber is equal to 1 then
						return
					end if
				end try
				
				
				repeat with myRowCounter from 0 to myNumberOfRows - 1
					set myY1 to (item 1 of myBounds) + (myRowHeight * myRowCounter) + (myRowGutter * myRowCounter)
					set myY2 to myY1 + (myRowHeight)
					repeat with myColumnCounter from 0 to myNumberOfColumns - 1
						set myX1 to (item 2 of myBounds) + (myColumnWidth * myColumnCounter) + (myColumnGutter * myColumnCounter)
						--set myX2 to myX1 + myColumnWidth
						set myX2 to myX1 + (myColumnWidth) - (myStrokeWidth)
						if myRetainFormatting is true then
							set myNewObject to duplicate myObject
							set geometric bounds of myNewObject to {myY1, myX1, myY2, myX2}
							(* else
						tell parent of myObject
							set myNewObject to make rectangle with properties {geometric bounds:{myY1, myX1, myY2, myX2}, content type:myFrameType}
						end tell *)
						end if
					end repeat
				end repeat
				if myDeleteObject is true then
					delete myObject
				end if
			end if
		end tell
	end if
	
	
	if myColumnGutter is equal to 0 and myRowGutter is greater than 0 and myAlign contains "stAC" then
		
		
		tell application "Adobe InDesign CS4"
			set myBounds to geometric bounds of myObject
			--display dialog myBounds as list
			set myWidth to (item 4 of myBounds) - (item 2 of myBounds)
			set myHeight to (item 3 of myBounds) - (item 1 of myBounds) + (myStrokeWidth)
			--Don't bother making the frames if the width/height of the frame is too small
			--to accomodate the row/column gutter values.	
			if ((myRowGutter * (myNumberOfRows - 1) < myHeight) and (myColumnGutter * (myNumberOfColumns - 1) < myWidth)) then
				set myColumnWidth to (myWidth - (myColumnGutter * (myNumberOfColumns - 1))) / myNumberOfColumns
				try
					set myRowHeight to (myHeight - (myRowGutter * (myNumberOfRows - 1))) / myNumberOfRows
				on error
					my theError()
					if errorNumber is equal to 1 then
						return
					end if
				end try
				
				
				repeat with myRowCounter from 0 to myNumberOfRows - 1
					set myY1 to (item 1 of myBounds) + (myRowHeight * myRowCounter) + (myRowGutter * myRowCounter)
					set myY2 to myY1 + (myRowHeight) - (myStrokeWidth)
					repeat with myColumnCounter from 0 to myNumberOfColumns - 1
						set myX1 to (item 2 of myBounds) + (myColumnWidth * myColumnCounter) + (myColumnGutter * myColumnCounter)
						--set myX2 to myX1 + myColumnWidth
						set myX2 to myX1 + (myColumnWidth) -- (myStrokeWidth)
						if myRetainFormatting is true then
							set myNewObject to duplicate myObject
							set geometric bounds of myNewObject to {myY1, myX1, myY2, myX2}
							(* else
						tell parent of myObject
							set myNewObject to make rectangle with properties {geometric bounds:{myY1, myX1, myY2, myX2}, content type:myFrameType}
						end tell *)
						end if
					end repeat
				end repeat
				if myDeleteObject is true then
					delete myObject
				end if
			end if
		end tell
	end if
	
	
	if myColumnGutter is greater than 0 and myRowGutter is greater than 0 and myAlign contains "stAC" then
		
		
		tell application "Adobe InDesign CS4"
			set myBounds to geometric bounds of myObject
			--display dialog myBounds as list
			set myWidth to (item 4 of myBounds) - (item 2 of myBounds) + (myStrokeWidth)
			set myHeight to (item 3 of myBounds) - (item 1 of myBounds) + (myStrokeWidth)
			--Don't bother making the frames if the width/height of the frame is too small
			--to accomodate the row/column gutter values.	
			if ((myRowGutter * (myNumberOfRows - 1) < myHeight) and (myColumnGutter * (myNumberOfColumns - 1) < myWidth)) then
				set myColumnWidth to (myWidth - (myColumnGutter * (myNumberOfColumns - 1))) / myNumberOfColumns
				try
					set myRowHeight to (myHeight - (myRowGutter * (myNumberOfRows - 1))) / myNumberOfRows
				on error
					my theError()
					if errorNumber is equal to 1 then
						return
					end if
				end try
				
				
				repeat with myRowCounter from 0 to myNumberOfRows - 1
					set myY1 to (item 1 of myBounds) + (myRowHeight * myRowCounter) + (myRowGutter * myRowCounter)
					set myY2 to myY1 + (myRowHeight) - (myStrokeWidth)
					repeat with myColumnCounter from 0 to myNumberOfColumns - 1
						set myX1 to (item 2 of myBounds) + (myColumnWidth * myColumnCounter) + (myColumnGutter * myColumnCounter)
						--set myX2 to myX1 + myColumnWidth
						set myX2 to myX1 + (myColumnWidth) - (myStrokeWidth)
						if myRetainFormatting is true then
							set myNewObject to duplicate myObject
							set geometric bounds of myNewObject to {myY1, myX1, myY2, myX2}
							(* else
						tell parent of myObject
							set myNewObject to make rectangle with properties {geometric bounds:{myY1, myX1, myY2, myX2}, content type:myFrameType}
						end tell *)
						end if
					end repeat
				end repeat
				if myDeleteObject is true then
					delete myObject
				end if
			end if
		end tell
	end if
	---------------------
	---------------------
	---------------------
	---------------------end Center
	
	
	---------------------
	---------------------
	---------------------
	---------------------outside
	--
	if myColumnGutter is equal to 0 and myRowGutter is equal to 0 and myAlign contains "stAO" then
		
		
		tell application "Adobe InDesign CS4"
			set myBounds to geometric bounds of myObject
			--display dialog myBounds as list
			set myWidth to (item 4 of myBounds) - (item 2 of myBounds) + myStrokeWidth
			set myHeight to (item 3 of myBounds) - (item 1 of myBounds) + myStrokeWidth
			--Don't bother making the frames if the width/height of the frame is too small
			--to accomodate the row/column gutter values.	
			if ((myRowGutter * (myNumberOfRows - 1) < myHeight) and (myColumnGutter * (myNumberOfColumns - 1) < myWidth)) then
				set myColumnWidth to (myWidth - (myColumnGutter * (myNumberOfColumns - 1))) / myNumberOfColumns
				try
					set myRowHeight to (myHeight - (myRowGutter * (myNumberOfRows - 1))) / myNumberOfRows
				on error
					my theError()
					if errorNumber is equal to 1 then
						return
					end if
				end try
				
				
				repeat with myRowCounter from 0 to myNumberOfRows - 1
					set myY1 to (item 1 of myBounds) + (myRowHeight * myRowCounter) + (myRowGutter * myRowCounter)
					set myY2 to myY1 + (myRowHeight) - myStrokeWidth
					repeat with myColumnCounter from 0 to myNumberOfColumns - 1
						set myX1 to (item 2 of myBounds) + (myColumnWidth * myColumnCounter) + (myColumnGutter * myColumnCounter)
						--set myX2 to myX1 + myColumnWidth
						set myX2 to myX1 + (myColumnWidth) - myStrokeWidth
						if myRetainFormatting is true then
							set myNewObject to duplicate myObject
							set geometric bounds of myNewObject to {myY1, myX1, myY2, myX2}
							(* else
						tell parent of myObject
							set myNewObject to make rectangle with properties {geometric bounds:{myY1, myX1, myY2, myX2}, content type:myFrameType}
						end tell *)
						end if
					end repeat
				end repeat
				if myDeleteObject is true then
					delete myObject
				end if
			end if
		end tell
	end if
	
	
	if myColumnGutter is greater than 0 and myRowGutter is equal to 0 and myAlign contains "stAO" then
		
		
		tell application "Adobe InDesign CS4"
			set myBounds to geometric bounds of myObject
			--display dialog myBounds as list
			set myWidth to (item 4 of myBounds) - (item 2 of myBounds)
			set myHeight to (item 3 of myBounds) - (item 1 of myBounds)
			--Don't bother making the frames if the width/height of the frame is too small
			--to accomodate the row/column gutter values.	
			if ((myRowGutter * (myNumberOfRows - 1) < myHeight) and (myColumnGutter * (myNumberOfColumns - 1) < myWidth)) then
				set myColumnWidth to (myWidth - (myColumnGutter * (myNumberOfColumns - 1))) / myNumberOfColumns
				try
					set myRowHeight to (myHeight - (myRowGutter * (myNumberOfRows - 1))) / myNumberOfRows
				on error
					my theError()
					if errorNumber is equal to 1 then
						return
					end if
				end try
				
				repeat with myRowCounter from 0 to myNumberOfRows - 1
					set myY1 to (item 1 of myBounds) + (myRowHeight * myRowCounter) + (myRowGutter * myRowCounter)
					set myY2 to myY1 + (myRowHeight)
					repeat with myColumnCounter from 0 to myNumberOfColumns - 1
						set myX1 to (item 2 of myBounds) + (myColumnWidth * myColumnCounter) + (myColumnGutter * myColumnCounter)
						--set myX2 to myX1 + myColumnWidth
						set myX2 to myX1 + (myColumnWidth) + (myStrokeWidth)
						if myRetainFormatting is true then
							set myNewObject to duplicate myObject
							set geometric bounds of myNewObject to {myY1, myX1, myY2, myX2}
							(* else
						tell parent of myObject
							set myNewObject to make rectangle with properties {geometric bounds:{myY1, myX1, myY2, myX2}, content type:myFrameType}
						end tell *)
						end if
					end repeat
				end repeat
				if myDeleteObject is true then
					delete myObject
				end if
			end if
		end tell
	end if
	
	
	if myColumnGutter is equal to 0 and myRowGutter is greater than 0 and myAlign contains "stAO" then
		
		
		tell application "Adobe InDesign CS4"
			set myBounds to geometric bounds of myObject
			--display dialog myBounds as list
			set myWidth to (item 4 of myBounds) - (item 2 of myBounds) + (myStrokeWidth)
			set myHeight to (item 3 of myBounds) - (item 1 of myBounds) + (myStrokeWidth * 2)
			--Don't bother making the frames if the width/height of the frame is too small
			--to accomodate the row/column gutter values.	
			if ((myRowGutter * (myNumberOfRows - 1) < myHeight) and (myColumnGutter * (myNumberOfColumns - 1) < myWidth)) then
				set myColumnWidth to (myWidth - (myColumnGutter * (myNumberOfColumns - 1))) / myNumberOfColumns
				try
					set myRowHeight to (myHeight - (myRowGutter * (myNumberOfRows - 1))) / myNumberOfRows
				on error
					my theError()
					if errorNumber is equal to 1 then
						return
					end if
				end try
				
				repeat with myRowCounter from 0 to myNumberOfRows - 1
					set myY1 to (item 1 of myBounds) + (myRowHeight * myRowCounter) + (myRowGutter * myRowCounter)
					set myY2 to myY1 + (myRowHeight) - (myStrokeWidth * 2)
					repeat with myColumnCounter from 0 to myNumberOfColumns - 1
						set myX1 to (item 2 of myBounds) + (myColumnWidth * myColumnCounter) + (myColumnGutter * myColumnCounter)
						--set myX2 to myX1 + myColumnWidth
						set myX2 to myX1 + (myColumnWidth) - (myStrokeWidth)
						if myRetainFormatting is true then
							set myNewObject to duplicate myObject
							set geometric bounds of myNewObject to {myY1, myX1, myY2, myX2}
							(* else
						tell parent of myObject
							set myNewObject to make rectangle with properties {geometric bounds:{myY1, myX1, myY2, myX2}, content type:myFrameType}
						end tell *)
						end if
					end repeat
				end repeat
				if myDeleteObject is true then
					delete myObject
				end if
			end if
		end tell
	end if
	
	
	if myColumnGutter is greater than 0 and myRowGutter is greater than 0 and myAlign contains "stAO" then
		
		
		tell application "Adobe InDesign CS4"
			set myBounds to geometric bounds of myObject
			--display dialog myBounds as list
			set myWidth to (item 4 of myBounds) - (item 2 of myBounds) + (myStrokeWidth * 2)
			set myHeight to (item 3 of myBounds) - (item 1 of myBounds) + (myStrokeWidth * 2)
			--Don't bother making the frames if the width/height of the frame is too small
			--to accomodate the row/column gutter values.	
			if ((myRowGutter * (myNumberOfRows - 1) < myHeight) and (myColumnGutter * (myNumberOfColumns - 1) < myWidth)) then
				set myColumnWidth to (myWidth - (myColumnGutter * (myNumberOfColumns - 1))) / myNumberOfColumns
				try
					set myRowHeight to (myHeight - (myRowGutter * (myNumberOfRows - 1))) / myNumberOfRows
				on error
					my theError()
					if errorNumber is equal to 1 then
						return
					end if
				end try
				
				
				repeat with myRowCounter from 0 to myNumberOfRows - 1
					set myY1 to (item 1 of myBounds) + (myRowHeight * myRowCounter) + (myRowGutter * myRowCounter)
					set myY2 to myY1 + (myRowHeight) - (myStrokeWidth * 2)
					repeat with myColumnCounter from 0 to myNumberOfColumns - 1
						set myX1 to (item 2 of myBounds) + (myColumnWidth * myColumnCounter) + (myColumnGutter * myColumnCounter)
						--set myX2 to myX1 + myColumnWidth
						set myX2 to myX1 + (myColumnWidth) - (myStrokeWidth * 2)
						if myRetainFormatting is true then
							set myNewObject to duplicate myObject
							set geometric bounds of myNewObject to {myY1, myX1, myY2, myX2}
							(* else
						tell parent of myObject
							set myNewObject to make rectangle with properties {geometric bounds:{myY1, myX1, myY2, myX2}, content type:myFrameType}
						end tell *)
						end if
					end repeat
				end repeat
				if myDeleteObject is true then
					delete myObject
				end if
			end if
		end tell
	end if
	---------------------
	---------------------
	---------------------
	---------------------end outside
	
end mySplitFrame

It’s better to go the other way. So:

set myAlign to stroke alignment of selection -- no "as text"
[...]
myAlign is inside alignment