'**********************************************
'A script to symmetry an Object *without*
'altering the center of the orriginal!
'By Adam Garland
'Thanks to the following:
'Matt Lind ,for the tutorial
'Ludovic Michaud ,his script elped me figure out the interface option.
'**********************************************
symmetryop

Function symmetryop

On Error Resume Next

	'get the selected object for later use
dim selected
set selected = getvalue("selectionlist")

	'checking if the Selection is valid or not
if Selected = "" then
	MsgBox "Nothing selected"
	exit Function
end if

	'set value of Position to the accept the coordinates
dim position, rotation
set position = createObject ("sumatra\scripting\math\sivector3")
set rotation = createObject ("sumatra\scripting\math\sivector3")


	'Retreive the global coordinates of selected for later use
  position.x = getvalue(selected & ".kine.global.pos.posx")
  position.y = getvalue(selected & ".kine.global.pos.posy")
  position.z = getvalue(selected & ".kine.global.pos.posz")
  
	'retreive the local rotation values for pasting back in
  rotation.x = getvalue(selected & ".kine.global.rotx")
  rotation.y = getvalue(selected & ".kine.global.roty")
  rotation.z = getvalue(selected & ".kine.global.rotz")
   
	'Find the Scene_Root object 
set mySceneRoot = EnumElements("Project", TRUE)
set mySceneRoot = SIFilter(mySceneRoot, "Scene", TRUE )(0)
set mySceneRoot = EnumElements( mySceneRoot , TRUE)
set mySceneRoot = SIFilter(mySceneRoot, "SceneObject", TRUE)(0)

	'in case someone as already created a custom parameter named "Symmetry"
  set symmetry_name = AddProp ("Custom_parameter_list",mySceneRoot, , "Symmetry").Value("Value") 

	'adding custom parameters to choose from
  SIAddCustomParameter symmetry_name, "Z axis", siBool, 0.000, 0.000, 1.000, , 0, 0.000, 0.000
  SIAddCustomParameter symmetry_name, "Y axis", siBool, 0.000, 0.000, 1.000, , 0, 0.000, 0.000
  SIAddCustomParameter symmetry_name, "X axis", siBool, 0.000, 0.000, 1.000, , 0, 0.000, 0.000  

	'Opening the CustomParameter for the user to Interact with
  InspectObj mySceneRoot & "." & symmetry_name,,"Effect Symmetry",4

	'Duplicating within the function so that you don't end up with extra objects if you select nothing
		if getvalue(symmetry_name & ".Z_axis.Y_Axis.X_Axis" ) <> 0 then
		duplicate object
		
	'X axis
  		if GetValue(symmetry_name &".X_axis") <> 0 then  		
  		resetTransform selected, sictr, sirot
  		translate selected, -(position.x),position.y,position.z,siabsolute,siglobal,siobj,sixyz
  		scale selected, -1.000, 1.000, 1.000, silocal
  		Rotate selected, rotation.x, -(rotation.y), -(rotation.z), siAbsolute, , siCtr, siXYZ
		end if
  
  	'Y axis
  		if GetValue(symmetry_name &".y_axis") <> 0 then 
  		resetTransform selected, sictr, sirot
  		translate selected, position.x,(-1)*position.y,position.z,siabsolute,siglobal,siobj,sixyz
  		scale selected, 1.000, -1.000, 1.000
  		Rotate selected, -(rotation.x), rotation.y, -(rotation.z), siAbsolute, , siCtr, siXYZ
		end if

  	'Z axis
  		if GetValue(symmetry_name &".z_axis") <> 0 then 
		resetTransform selected, sictr, sirot
  		translate selected, position.x,position.y,(-1)*position.z,siabsolute,siglobal,siobj,sixyz
  		scale selected, 1.000, 1.000, -1.000
  		Rotate selected, -(rotation.x), -(rotation.y), rotation.z, siAbsolute, , siCtr, siXYZ
		end if
	
	end if
	
	'deleting the Custom Parameter
DeleteObj mySceneRoot & "." & symmetry_name

end Function
