'¤º°`°º¤ø,¸¸,ø¤º°`°º¤ø,¸¸,ø¤º°`°º¤ø,¸¸,ø¤º°`°º¤ø,¸¸,ø¤º°`°º¤ø,¸¸,ø¤º°`°º¤ø,¸¸,ø
'¤º                                                                          ,ø
'¤º  Pill v1.0    This script creates a nurbs rounded primitive.             ,ø
'¤º                                                                          ,ø
'¤º     by    Eric Poirier                                                   ,ø
'¤º           http://www.xsistation.com                                      ,ø
'¤º                                                                          ,ø
'¤º     special Thanx to: Olivier Amrein <o@skol.ch>                         ,ø
'¤º                       Kim Aldis <Kim@Aldis.co.uk>                        ,ø
'¤º                       Marc-André Carbonneau <macarbon@softimage.com>     ,ø
'¤º                       Charles Meyer <cmeyer@nad.qc.ca>                   ,ø
'¤º                       Frank Hellmann <hellmann@vcc.de>                   ,ø
'¤º                                                                          ,ø
'¤º   To install:                                                            ,ø
'¤º   Drag and Drop on Toolbar. To make it nice:                             ,ø
'¤º   Command Name = "Pill"                                                  ,ø
'¤º   Command Name for Scripting = "Pill"                                    ,ø
'¤º                                                                          ,ø
'¤º                                                                          ,ø
'¤º°`°º¤ø,¸¸,ø¤º°`°º¤ø,¸¸,ø¤º°`°º¤ø,¸¸,ø¤º°`°º¤ø,¸¸,ø¤º°`°º¤ø,¸¸,ø¤º°`°º¤ø,¸¸,ø


createPill

sub createPill
	dim x, y, z, i, Radius, pillConstructionArc, pillConstructionArc2, pillConstructionCurve
	dim pillTop, pillMid, pillBot, subdivU, subdivV
		
	'//In case somethings goes wrong, just continue
	On Error Resume Next

	'//In case the user Change the name of the Scene Root
	'//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 put a custom parameter named "Pill"
	set pill_name = AddProp ("Custom_parameter_list",mySceneRoot, , "Pill").Value("Value")

	'//Adding the Parameters in the Custom parameter
	SIAddCustomParameter pill_name, "ObjectName", siString, 0, 0, 0, 0, 0, 0.000, 0.000
	SIAddCustomParameter pill_name, "Radius", siDouble, 1.000, 0.001, 30.000, , 0, 0.000, 0.000
	SIAddCustomParameter pill_name, "Height", siDouble, 5.000, 0.001, 100.000, , 0, 0.000, 0.000
	SIAddCustomParameter pill_name, "subdivU", siInt4, 8.000, 6.000, 30.000, , 0, 0.000, 0.000
	SIAddCustomParameter pill_name, "subdivV", siInt4, 3.000, 3.000, 30.000, , 0, 0.000, 0.000	
	
	'//Preset the object name to Pill
	setValue pill_name & ".ObjectName", "pill"

	'//Opening the CustomParameter for the user to Interact with it
	InspectObj mySceneRoot & "." & pill_name,,"Create Pill",4

	myName 		= GetValue(pill_name &".ObjectName")
	myRadius 	= GetValue(pill_name &".Radius")
	myHeight 	= GetValue(pill_name &".Height")
	mysubdivU 	= GetValue(pill_name &".subdivU")
	mysubdivV 	= GetValue(pill_name &".subdivV")

	

	'//At the end we do a simple cleanup of the Custom Parameter
	DeleteObj mySceneRoot & "." & pill_name
	
	if Err.Number = 0 then
	
	   if myName = "" then
			
		LogMessage "No Name given.", siWarning
	
	   else 		
	
		DeselectAll
		
		SetValue "crvlist.Name", "crvlist_old"
		SetValue "surfmsh.Name", "surfmsh_old"
		SetValue "surfmsh1.Name", "surfmsh1_old"
		SetValue "surfmsh2.Name", "surfmsh2_old"
		SetValue "surfmsh3.Name", "surfmsh3_old"

		set pillConstructionArc = CreatePrim ("Arc", "NurbsCurve")

		SetValue pillConstructionArc &".arc.radius", myRadius

		set pillConstructionArc2 = Duplicate (, , 2, 1, 1, 0, 0, 1, 0, 1)
		Rotate , 180.000, 0.000, 0.000, siAbsolute, siView, siObj, siX

		DeselectAll
		SelectObj pillConstructionArc2, , True
		Translate , 0.000, -myHeight, 0.000, siRelative, siView, siObj, siXYZ
		Translate , 0.000, -myHeight, 0.000, siAbsolute, siView, siObj, siY

		ApplyOp "CrvInverse", pillConstructionArc2, 3
		SelectObj pillConstructionArc, , True

		set pillConstructionCurve = ApplyOp ("BlendCrv", pillConstructionArc & ";" & pillConstructionArc2, 3)

		set pillTop = ApplyOp ("Revolution", pillConstructionArc, 3)
		SetValue pillTop &".subdivu", mysubdivU
		SetValue pillTop &".subdivv", mysubdivV
		
		
		set pillMid = ApplyOp ("Revolution", "crvlist;", 3)
		SetValue pillMid &".subdivu", mysubdivU
		SetValue pillMid &".subdivv", mysubdivV
		
		set pillBot = ApplyOp ("Revolution", pillConstructionArc2, 3)
		SetValue pillBot &".subdivu", mysubdivU
		SetValue pillBot &".subdivv", mysubdivV
		
		ApplyOp "SrfInverse", "surfmsh", 3
		ApplyOp "SrfInverse", "surfmsh1", 3
		ApplyOp "SrfInverse", "surfmsh2", 3

		
		SelectObj "surfmsh,surfmsh1,surfmsh2", , True

		AssembleNurbsMesh

		ApplyOp "SCMFixer", "surfmsh3", 3

		SetValue "surfmsh3.surfmsh.scmfixerop.Continuity", 0.000
		DeselectAll

		SelectObj "surfmsh3"
		FreezeObj
		SelectObj "surfmsh2"
		ToggleSelection "surfmsh1,surfmsh,crvlist,arc1,arc"
		DeleteObj
		
		
		SetValue "surfmsh3.Name", "pill"
		SetValue "surfmsh3_old.Name", "surfmsh3"
		SetValue "surfmsh2_old.Name", "surfmsh2"
		SetValue "surfmsh1_old.Name", "surfmsh1"
		SetValue "surfmsh_old.Name", "surfmsh"
		SetValue "crvlist_old.Name", "crvlist"
				
		SelectObj "pill", , True
		
           end if

	end if

end sub
		
		
		
		