/*
10 minute clamp function for you
copy this (straigten out the SiAddCustomparam lines, my mail chopped thiem in pieces)
into a function called Clamp.js
put that function in Plugins for user or wrokgroupd, restart xsi or update plugins
and then you got your clamp
to see an example run the following lines, you will notice that i
actually put a custom param for min and max so you can interactively
modify it
NewScene()
CreatePrim("Cube", "MeshSurface", null, null);
posy = "cube.kine.local.posy"
minn = 0
maxx = 10
Clamp (0,10,posy)
*/
function XSILoadPlugin( in_reg )
{
in_reg.Author = "Javier";
in_reg.Name = "Clamp";
in_reg.Email = "";
in_reg.URL = "">
in_reg.Major = 1;
in_reg.Minor = 0;
in_reg.RegisterCommand("Clamp","Clamp");
return true;
}
function XSIUnloadPlugin( in_reg )
{
strPluginName = in_reg.Name;
return true;
}
function Clamp_Init( ctxt )
{
var oCmd;
oCmd = ctxt.Source;
oCmd.Description = "";
oCmd.ReturnValue = true;
var oArgs;
oArgs = oCmd.Arguments;
oArgs.Add("minval",siArgumentInput);
oArgs.Add("maxval",siArgumentInput);
oArgs.Add("param",siArgumentInput);
return true;
}
function Clamp_Execute(minval,maxval,param)
{
var sOp = ClampOp_Update.toString();
var posy = Dictionary.GetObject(param);
if (!param){logmessage
("parameter "+param+" is not a valid parameter ,exiting",siError);}
if (!minval){minval = 0;}
if (!maxval){maxval = 0;}
var c_out = XSIFactory.CreateActiveXObject("XSI.Collection");
c_out.add(param);
var c_in = XSIFactory.CreateActiveXObject("XSI.Collection");
c_in.add(param)
var opClamp = AddScriptedOp (c_out, sOp ,c_in, "ClampOp", "Jscript",null);
SIAddCustomParameter(opClamp , "Clamp_Min", siDouble, minval, -1000000,
1000000, null, 5, Math.abs(10*minval)*-1, maxval, null, null);
SIAddCustomParameter(opClamp , "Clamp_Max",
siDouble, maxval, -1000000, 1000000, null, 5, minval,
Math.abs(10*maxval), null, null);
return opClamp;
}
function ClampOp_Update(ctx,Out,In){
var val = In.value;
var max = ctx.Clamp_Max.value;
var min = ctx.Clamp_Min.value;
if (min > max){ctx.Clamp_Min.value = max;}
if (val > max){val = max;}
if (val < min){val = min;}
Out.Value = val;
}