Terminology conflict with InDesign, how do I solve ?

Hi,

There is a keyword “inches” native to Applescript, and there is also the measurement unit “inches” in InDesign. How do I explicitely specify which one I want to use ?

I don’t remember what the exact syntax is but you wrap your coding in a

using terms of application
end using

Hi Dante

If your using a tell block like:

tell application "indesign cs2"
tell document 1
---do some measuring here in inches 
end tell
end tell

then everything inside that tell block should be pointing towards that application any way.

this is part of my script. for example horUnit resolves to “inches”, then it’s passed to getOffsetToUse, but then it doesn’t go into the “if unitMeasure is inches then” clause, and returns the “else” result.



tell application "Adobe InDesign CS2"
	
	tell document 1
		
		tell view preferences
			set horUnit to horizontal measurement units
			set horOffset to getOffsetToUse(horUnit) of me
			set verUnit to vertical measurement units
			set verOffset to getOffsetToUse(verUnit) of me
		end tell
				
	end tell
	
end tell

end run

on getOffsetToUse(unitMeasure)
	
	tell application "Adobe InDesign CS2"
		if unitMeasure is inches then
			return 0.5
		else if unitMeasure is inches decimal then
			return 0.5
		else if unitMeasure is points then
			return 36
		else if unitMeasure is picas then
			return 3
		else if unitMeasure is millimeters then
			return 15
		else if unitMeasure is centimeters then
			return 0.15
		else if unitMeasure is ciceros then
			return 3
		else
			return 0
		end if
	end tell
	
end getOffsetToUse


any ideas ?

Hello

May you try :



tell application "Adobe InDesign CS2"
	
	tell document 1
		
		tell view preferences
			set horOffset to getOffsetToUse(horizontal measurement units) of me
			set verOffset to getOffsetToUse(vertical measurement units) of me
		end tell
				
	end tell
	
end tell

end run

on getOffsetToUse(unitMeasure)
	
	tell application "Adobe InDesign CS2" to tell document 1 (* ADDED "to tell document 1" *)
		if unitMeasure is in {inches, inches decimal} then
			return 0.5
		else if unitMeasure is points then
			return 36
		else if unitMeasure is in {picas, ciceros} then
			return 3
		else if unitMeasure is millimeters then
			return 15
		else if unitMeasure is centimeters then
			return 0.15
		else
			return 0
		end if
	end tell
	
end getOffsetToUse


I can’t test because since inDesign is not available on my machine. But if I remember well, the unitMeasure is a property of a document not one of the application.

Yvan KOENIG (from FRANCE vendredi 8 décembre 2006 18:57:34)

unitMeasure is a variable defined by me…

I tried changing me getOffsetToUse function to


on getOffsetToUse(unitMeasure)
	
	tell application "Adobe InDesign CS2"
		tell document 1
			tell view preferences
				
				if unitMeasure is inches then
					return 0.5
				else if unitMeasure is inches decimal then
					return 0.5
				else if unitMeasure is points then
					return 36
				else if unitMeasure is picas then
					return 3
				else if unitMeasure is millimeters then
					return 15
				else if unitMeasure is centimeters then
					return 0.15
				else if unitMeasure is ciceros then
					return 3
				else
					return 0
				end if
			end tell
		end tell
	end tell
	
end getOffsetToUse

but it still always returns through the “else” part…

anyone else ?

try coercing the unitMeasure to a string and then testing the variable using a string:

tell application "Adobe InDesign CS2"
	tell document 1
		tell view preferences
			set unitMeasure to horizontal measurement units as string
			if unitMeasure is "points" then display dialog 36
		end tell
	end tell
end tell

that’s actually the first thing I tried… it works when debugging, but randomly fails when run normally…

Hi Dante

Try This:

tell application "Adobe InDesign CS2"
	tell document 1
		tell view preferences
			set horUnit to horizontal measurement units
			set horOffset to getOffsetToUse(horUnit) of me
			set verUnit to vertical measurement units
			set verOffset to getOffsetToUse(verUnit) of me
		end tell
	end tell
end tell


on getOffsetToUse(unitMeasure)
	tell application "Adobe InDesign CS2"
		set unitMeasure to unitMeasure as string
		if unitMeasure is "inches" then
			display dialog 0.5
		else if unitMeasure is "inches decimal" then
			display dialog 0.5
		else if unitMeasure is "points" then
			display dialog 36
		else if unitMeasure is "picas" then
			display dialog 3
		else if unitMeasure is "millimeters" then
			display dialog 15
		else if unitMeasure is "centimeters" then
			display dialog 0.15
		else if unitMeasure is "ciceros" then
			display dialog 3
		else
			display dialog 0
		end if
	end tell
end getOffsetToUse

What about this…


tell application "Adobe InDesign CS2"
	tell document 1
		tell view preferences
			set origHMeasurements to horizontal measurement units
			set origVMeasurements to vertical measurement units
			set horizontal measurement units to inches
			set vertical measurement units to inches
		end tell
		
		-- do your stuff here in inches
		
		tell view preferences
			set horizontal measurement units to origHMeasurements -- set back to original units
			set vertical measurement units to origVMeasurements -- set back to original units
		end tell
	end tell
end tell

CarbonQuark