'-------------------------------------
' CUBE control object script v1.0
' Written by James Rogers
' Contact: jearogers@aol.com
' 16/04/2001
' 
' This script makes a cube for as a
' control object for IK manipulation	
' of a skeleton. It changes both the	
' wireframe colour and makes it
' wireframe only if you are using
' "mixed viewing mode".  These extra
' functions can be commented out if
' you wish.
'
' The sript works with a skeleton chain.
' The users is prompted to click on the
' control cube (created for you) and
' then	the choosen effector.  The scipt
' positions the cube at the effector,
' and the effector is positionally
' constrained to the control cube. 
'
' Please feel free to edit the script
' and send any updates to myself or
' XSInet.
'
' This is my first script -  so I would
' like to know if anybody finds it useful!
'--------------------------------------

application.statusbar = "Do your stuff with XSI"

' Sets Camera view to "mixed viewing mode"
SetValue "Camera.camdisp.mixviewmode", True

' Declares cntrl cube variable
dim cntrl

set cntrl = CreatePrim("Cube", "MeshSurface")
SetValue ".Name", "cube"

SetValue "cube.cube.length", 1.000 'sets the size of the cube
MakeLocal "cube.display, siNodePropagation" 'sets the wire frame colour
SetValue "cube.display.wirecol", 656

' Sets cube as wireframe display for mixed viewing mode (very handy)
MakeLocal "cube.display", siNodePropagation
SetValue "cube.display.staticsel", 0
SetValue "cube.display.intsel", 0
SetValue "cube.display.staticunselnear", 0
SetValue "cube.display.intunselnear", 0
SetValue "cube.display.intunselfar", 0

SelectObj "cube", , True
dim cntrl1
SetValue ".Name", "cntrl1"

dim constraining, constrained, button
PickObject "Select Control Cube", "Select Control Cube", constraining, button 
	
application.statusbar = "Do your stuff with XSI"

if button <> 0 then
	PickObject "Select Effector", "Select Effector", constrained, button

	if button <> 0 then
	
		' Contrains cube to effector (for positioning) and then removes constraint
		dim cns1		' To hold the constraint object
		
		set cns1 = ApplyCns( "Position", constraining, constrained )
		Refresh
		RemoveCns cntrl1    'removes the positional constraint from the cube
		Refresh
		
		' Contrains effector to the cube
		dim cns2
		set cns2 = ApplyCns( "Position", constrained, constraining )
		Refresh

	end if
end if

application.statusbar = "Do your stuff in XSI - (*^.^*) PIKACHU!"

' (*^.^*) PIKACHU!
