'/// RoundPar: ver 1.0 for XSI 3.5+
'/// By Homam Bahnassi - In|Framez 2003
'--------------------------------------

set oSelection = Application.Selection

RoundParam ,oSelection,0.5

function RoundParam(aParams,oObjCollection,dFactor)

RoundParam = false

'--- Checking oObjCollection...
if oObjCollection.count = 0 then
	logmessage "RoundPar: Objects required..."
	exit function
end if

if typename(dFactor) <> "Double" then
	logmessage "RoundPar: Invaled round factor..."
	exit function
end if

'--- Checking aParams...
if typename(aParams) <> "Error" then
	on error resume next
	for each oObj in oObjectsCollection
		for iParam = lbound(aParams) to ubound(aParams)
			dParamValue = GetValue (oObj & "." & aParams(iParam))
			if err.number = 5 then
				logmessage "RoundPar: " & aParams(iParam) & " is not a valid parameter"
				exit function
			else
				RoundVal dParamValue,dFactor
				SetValue oObj & "." & aParams(iParam), dParamValue
			end if
		next
	next
	on error goto 0
else
	for each oObj in oObjCollection
		for each oParameter in oObj.Parameters
			if oParameter.Marked = true then
				dParamValue = GetValue(oParameter)
				SetValue oParameter, dRoundVal(dParamValue,dFactor)
			end if
		next
	next
end if

RoundParam = true

end function

function dRoundVal(dValue,dFactor)
	dRoundVal=round(dValue/dFactor)*dFactor
end function

