Global mName = "Table"; Global mTshape = 1; Global mTthickness = 5; Global mTchamfer = 2; Global mTwidth = 80
Global mTlength = 125; Global mTelevation = 75; Global mTwidth = 80; Global mTprofile = true
Global mTprofile1thickness = 3; Global mTprofile1indent = 2; Global mLone = false; Global mLshape = 1
Global mLwidth = 6; Global mLindent = 3

rollout M01 "General"
	(
		Group "Object Definition" (
		edittext mNameS "Name:" text:mName
		dropdownlist mDef "Default Tables:" items:#("Custom", "Breakfast Table", "Coffe Table", "Office Table", "Dinner for 4", "Dinner for 6", "Dinner for 10")
		)
		Group "Preferences" (
		checkbox mOptimizeS "Optimize surfaces"
		)		
		Group "Script Execution" (
		button mCreate "Create" width:200 height:40
		)
			on mNameS entered text do mName = text
			on mDef selected mDefs do
			( 
			if mDefs == 2 then (
				mTshape = 2; mTthickness = 6; mTchamfer = 4; mTwidth = 90; mTlength = 90; mTelevation = 70
				mTprofile = true; mTprofile1thickness = 2; mTprofile1indent = 4; mLone = false
				mLshape = 1; mLwidth = 5; mLindent = 4
			)
			if mDefs == 3 then (
				mTshape = 2; mTthickness = 4; mTchamfer = 0; mTwidth = 70; mTlength = 70; mTelevation = 60
				mTprofile = true; mTprofile1thickness = 2; mTprofile1indent = 2; mLone = true
				mLshape = 2; mLwidth = 8; mLindent = 0
			)
			if mDefs == 4 then (
				mTshape = 1; mTthickness = 6; mTchamfer = 0; mTwidth = 80; mTlength = 110; mTelevation = 80
				mTprofile = false; mTprofile1thickness = 0; mTprofile1indent = 0; mLone = false
				mLshape = 2; mLwidth = 5; mLindent = 3
			)
			if mDefs == 5 then (
				mTshape = 1; mTthickness = 5; mTchamfer = 3; mTwidth = 85; mTlength = 85; mTelevation = 75
				mTprofile = true; mTprofile1thickness = 2; mTprofile1indent = 2; mLone = false
				mLshape = 1; mLwidth = 5; mLindent = 6
			)
			if mDefs == 6 then (
				mTshape = 1; mTthickness = 5; mTchamfer = 3; mTwidth = 80; mTlength = 145; mTelevation = 75
				mTprofile = true; mTprofile1thickness = 2; mTprofile1indent = 2; mLone = false
				mLshape = 1; mLwidth = 7; mLindent = 8
			)
			if mDefs == 7 then (
				mTshape = 1; mTthickness = 5; mTchamfer = 3; mTwidth = 80; mTlength = 270; mTelevation = 75
				mTprofile = true; mTprofile1thickness = 2; mTprofile1indent = 2; mLone = false
				mLshape = 1; mLwidth = 8; mLindent = 10
			)
				M02.mTshapeS.state = mTshape
				M02.mTthicknessS.value = mTthickness
				M02.mTchamferS.value = mTchamfer
				M02.mTwidthS.value = mTwidth
				M02.mTlengthS.value = mTlength
				M02.mTelevationS.value = mTelevation
				M02.mTprofileCheckS.checked == mTprofile
				M02.mTprofile1thicknessS.value = mTprofile1thickness
				M02.mTprofile1indentS.value = mTprofile1indent
				M03.mLoneS.state = mLone
				M03.mLshapeS.state = mLshape
				M03.mLwidthS.value = mLwidth
				M03.mLindentS.value = mLindent
			)
			on mCreate pressed do
			(
			if mTshape == 1 then 
				(
				masa = box(); masa.name = mName; masa.width = mTwidth; masa.length = mTlength; masa.heightsegs = 1
					if mTprofile1thickness > 0 then 
					(
					masa.height = mTprofile1thickness; masa.pos = [0,0,mTelevation-mTprofile1thickness]
					)
					else 
					(
					masa.height = mTthickness; masa.pos = [0,0,mTelevation-mTthickness]
					)
					convertToPoly(masa)
					if mTchamfer > 0 then
					(
					polyop.setEdgeSelection masa #{9,10,11,12}
					masa.chamferEdges mTchamfer
					)
					if mTprofile1indent > 0 then
					(
					polyop.setFaceSelection masa #{1}
					masa.slice [0,1,0] [0,((float(mTlength) / 2)) - float(mTprofile1indent),0]
					masa.slice [0,1,0] [0,-(((float(mTlength) / 2))- float(mTprofile1indent)),0]
					masa.slice [1,0,0] [((float(mTwidth) / 2)) - float(mTprofile1indent),0,0]
					masa.slice [1,0,0] [-(((float(mTwidth) / 2)) - float(mTprofile1indent)),0,0]
						if mTchamfer > 0 then
						(					
						if mTchamfer < mTprofile1indent do polyop.setFaceSelection masa #{31}
						if mTchamfer == mTprofile1indent do polyop.setFaceSelection masa #{24}
						if mTchamfer > mTprofile1indent and mTchamfer <= (mTprofile1indent * 2) do polyop.setFaceSelection masa #{32}
						if mTchamfer > (mTprofile1indent * 2) do polyop.setFaceSelection masa #{15}
						)
						else polyop.setFaceSelection masa #{27}
					masa.extrudeFaces (mTthickness - mTprofile1thickness)
					)
				)				
					if mTshape == 1 and mLshape == 1 and mLone == false then
					(
					ayak = box()
					ayak1 = instance ayak; ayak2 = instance ayak; ayak3 = instance ayak
					ayak.width = mLwidth; ayak.length = mLwidth; ayak.height = mTelevation - mTthickness
					ayak.pos = [((float(mTwidth) / 2.0) - (float(mLindent) + float(mLwidth) / 2.0)),((float(mTlength) / 2.0) - (float(mLindent) + float(mLwidth) / 2.0)),0]
					ayak1.pos = [-((float(mTwidth) / 2.0) - (float(mLindent) + float(mLwidth) / 2.0)),((float(mTlength) / 2.0) - (float(mLindent) + float(mLwidth) / 2.0)),0]
					ayak2.pos = [-((float(mTwidth) / 2.0) - (float(mLindent) + float(mLwidth) / 2.0)),-((float(mTlength) / 2.0) - (float(mLindent) + float(mLwidth) / 2.0)),0]
					ayak3.pos = [((float(mTwidth) / 2.0) - (float(mLindent) + float(mLwidth) / 2.0)),-((float(mTlength) / 2.0) - (float(mLindent) + float(mLwidth) / 2.0)),0]
					)
					if mTshape == 1 and mLshape == 2 and mLone == false then
					(
					ayak = cylinder()
					ayak1 = instance ayak; ayak2 = instance ayak; ayak3 = instance ayak
					ayak.radius = float(mLwidth) / 2; ayak.height = mTelevation - mTthickness
					ayak.pos = [((float(mTwidth) / 2.0) - (float(mLindent) + float(mLwidth) / 2.0)),((float(mTlength) / 2.0) - (float(mLindent) + float(mLwidth) / 2.0)),0]
					ayak1.pos = [-((float(mTwidth) / 2.0) - (float(mLindent) + float(mLwidth) / 2.0)),((float(mTlength) / 2.0) - (float(mLindent) + float(mLwidth) / 2.0)),0]
					ayak2.pos = [-((float(mTwidth) / 2.0) - (float(mLindent) + float(mLwidth) / 2.0)),-((float(mTlength) / 2.0) - (float(mLindent) + float(mLwidth) / 2.0)),0]
					ayak3.pos = [((float(mTwidth) / 2.0) - (float(mLindent) + float(mLwidth) / 2.0)),-((float(mTlength) / 2.0) - (float(mLindent) + float(mLwidth) / 2.0)),0]
					)
					if mLone == true then
					(		
						if mTshape == 1 and mLshape == 1 then 
						(
						ayak = box()
						ayak.width = mLwidth; ayak.length = mLwidth; ayak.height = mTelevation - mTthickness
						)
						if mTshape == 1 and mLshape == 2 then
						(
						ayak = cylinder()
						ayak.radius = float(mLwidth) / 2; ayak.height = mTelevation - mTthickness
						)
					)
			if mTshape == 2 then
					(
					masa = ellipse()
					masa.steps = 18
					masa.name = mName
					masa.wirecolor = (color 250 250 250)
					masa.length = mTwidth - mTprofile1indent
					masa.width = mTlength - mTprofile1indent
					addModifier masa (Extrude())
					masa.pos = [0,0,mTelevation-mTthickness]
					if mTprofile1thickness > 0 then
					(
					masa.pos = [0,0,mTelevation-mTprofile1thickness]
					masa.extrude.amount = mTprofile1thickness
					convertToPoly(masa)
					polyop.setFaceSelection masa #{1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,64,65,66,67,68,69,70,71,72,73,74,75,76}
					masa.extrusionType = 1
					masa.extrudeFaces (mTprofile1indent)
					polyop.setFaceSelection masa #{77}
					masa.extrudeFaces (mTthickness - mTprofile1thickness)
					)
					else masa.extrude.amount = mTthickness
					if mTshape == 2 and mLshape == 1 and mLone == false then
					(
					ayak = box()
					ayak1 = instance ayak; ayak2 = instance ayak; ayak3 = instance ayak
					ayak.width = mLwidth; ayak.length = mLwidth; ayak.height = mTelevation - mTthickness
					ayak.pos = [((float(mTlength) / 2.0) - (float(mLindent) + float(mLwidth) / 2.0)),0,0]
					ayak1.pos = [-((float(mTlength) / 2.0) - (float(mLindent) + float(mLwidth) / 2.0)),0,0]
					ayak2.pos = [0,-((float(mTwidth) / 2.0) - (float(mLindent) + float(mLwidth) / 2.0)),0]
					ayak3.pos = [0,((float(mTwidth) / 2.0) - (float(mLindent) + float(mLwidth) / 2.0)),0]
					)
					if mTshape == 2 and mLshape == 2 and mLone == false then
					(
					ayak = cylinder()
					ayak1 = instance ayak; ayak2 = instance ayak; ayak3 = instance ayak
					ayak.radius = float(mLwidth) / 2; ayak.height = mTelevation - mTthickness
					ayak.pos = [((float(mTlength) / 2.0) - (float(mLindent) + float(mLwidth) / 2.0)),0,0]
					ayak1.pos = [-((float(mTlength) / 2.0) - (float(mLindent) + float(mLwidth) / 2.0)),0,0]
					ayak2.pos = [0,-((float(mTwidth) / 2.0) - (float(mLindent) + float(mLwidth) / 2.0)),0]
					ayak3.pos = [0,((float(mTwidth) / 2.0) - (float(mLindent) + float(mLwidth) / 2.0)),0]
					)
					if mLone == true then
					(		
						if mTshape == 2 and mLshape == 1 then 
						(
						ayak = box()
						ayak.width = mLwidth; ayak.length = mLwidth; ayak.height = mTelevation - mTthickness
						)
						if mTshape == 2 and mLshape == 2 then
						(
						ayak = cylinder()
						ayak.radius = float(mLwidth) / 2; ayak.height = mTelevation - mTthickness
						)
					
					)
				)
				masa.attach ayak masa
				if mLone == false then
				(
				masa.attach ayak1 masa
				masa.attach ayak2 masa
				masa.attach ayak3 masa
				)
				if mOptimizeS.checked == true do addModifier masa (Optimize())
				convertToPoly(masa)
				masa.wirecolor = (color 255 237 210)
				print "Simple Table script finished."
			)
	)
	rollout M02 "Table top" (
		Group "Shape and Dimensions" (
		radiobuttons mTshapeS labels:#("Rectangular shape","Circular shape") default:1 columns:1 align:#left
		spinner mTwidthS "Width:" range:[30,400,80] type:#integer
		spinner mTlengthS "Length:" range:[30,400,125] type:#integer
		spinner mTelevationS "Total height:" range:[20,120,mTelevation] type:#integer
		)
		Group "Details" (
		spinner mTthicknessS "Tabletop thickness:" range:[2,30,mTthickness] type:#integer	
		spinner mTchamferS "Chamfer distance:" range:[0,50,mTchamfer] type:#integer	
		)
		Group "Profile" (
		checkbox mTprofileCheckS "Create profile" checked:mTprofile align:#center
		spinner mTprofile1thicknessS "Profile thickness:" range:[0,20,mTprofile1thickness] type:#integer enabled:true
		spinner mTprofile1indentS "Profile indent:" range:[0,20,mTprofile1indent] type:#integer enabled:true
		)
		on mTprofileCheckS changed state do 
		(
		M01.mDef.selection = 1
		mTprofile1indentS.enabled = state; mTprofile1thicknessS.enabled = state
		if state == off then mTprofile1thicknessS.value = 0; mTprofile1indent = 0; mTprofile1indentS.value = 0; mTprofile1thickness = 0
		) 
		on mTprofile1thicknessS changed value do 
		(
		M01.mDef.selection = 1
		if value  > mTthickness then value = mTthickness
		mTprofile1thicknessS.value = value
		mTprofile1thickness = value
		)
		on mTprofile1indentS changed value do 
		(
		M01.mDef.selection = 1
		if value  > mLindent then value = mLindent
		mTprofile1indentS.value = value
		mTprofile1indent = value
		)
		on mTprofile1indentS changed value do
		(
		mTprofile1indent = value
		M01.mDef.selection = 1
		)
		on mTshapeS changed state do
		(
		M01.mDef.selection = 1
		if mTshapeS.state == 1 then
		(
		mTshape = 1
		mTchamferS.enabled = true
		)
		if mTshapeS.state == 2 then
		(
		mTshape = 2
		mTchamferS.enabled = false; mTchamferS.value = 0; mTchamfer = 0
		)
		)
 		on mTchamferS changed value do 
		(
		M01.mDef.selection = 1
	    if value > (mTwidth / 2) - 1 then value = (mTwidth / 2) - 1
		if value > (mTlength / 2) - 1 then value = (mTlength / 2) - 1
		mTchamfer = value; mTchamferS.value = value
		)
		on mTwidthS changed value do
		(
		mTwidth = value
		M01.mDef.selection = 1
		)
		on mTlengthS changed value do
		(
		mTlength = value
		M01.mDef.selection = 1
		)
		on mTelevationS changed value do
		(
		mTelevation = value
		M01.mDef.selection = 1
		)
		on mTthicknessS changed value do
		(
		M01.mDef.selection = 1
		mTthickness = value
		if mTprofile1thickness > mTthickness then
		(
		mTprofile1thickness = mTthickness
		mTprofile1thicknessS.value = mTthickness
		)
		)
	)
	rollout M03 "Legs" (
	Group "Shape and dimension" (
	radiobuttons mLshapeS labels:#("Square","Circular") default:1 columns:1 align:#left
	spinner mLwidthS "Thickness" range:[5,40,6] type:#integer
	spinner mLindentS "Leg indent" range:[0,20,2] type:#integer
	checkbox mLoneS "One middle leg" default:off align:#center
	)
	on mLshapeS changed state do
	(
	mLshape = state
	M01.mDef.selection = 1
	)
	on mLwidthS changed value do
	(
	mLwidth = value
	M01.mDef.selection = 1
	)
	on mLindentS changed value do
	(
	mLindent = value
	M01.mDef.selection = 1
	)
	on mLoneS changed value do
	(
	mLone = value
	M01.mDef.selection = 1
	)
	)
	rollout M04 "About" (
	Label LabelVersion "Version: 2.1 (2005)" align:#center
	Label LabelAuthor "Tugrul Yazar" align:#center
	Label LabelContact "www.designcoding.net" align:#center
	)
MFL = NewRolloutFloater "Simple Tables" 250 400
AddRollout M01 MFL rolledUp:off
AddRollout M02 MFL rolledUp:on
AddRollout M03 MFL rolledUp:on
AddRollout M04 MFL rolledUp:on