'***************************************
'**  		 Cluster Cleaner 		  **
'** Homam Bahnassi - In|Framez - 2003 **
'***************************************

' Locate the scene root.
scn_root = Application.ActiveProject.ActiveScene.Root

set oSelection = Application.Selection  
for i = 0 to (oSelection.Count - 1)  
	ClsCleaner
next

Function ClsCleaner()
set oGeometry = oSelection(i).activeprimitive.geometry
	set oClusters = oGeometry.Clusters
		
	' Add a property to the scene_root - this will hold the tmp data used in the dialog.
	dialog = SIAddProp( "Custom_parameter_list", scn_root, , "Cluster_Clear_for_" & oSelection(i) ).value( "Value" )
		
	' Store location of Custom parameter list in a variable for legibility
	PPG = scn_root & "." & dialog
	for each oCls in oGeometry.Clusters
		if InStr (oCls.FullName, "Sel") <> 0 then check=1 else check=0
		SIAddCustomParameter PPG, oCls.FullName, SiBool, check, 0, 1, siClassifPositioning, siSilent, 0, 1
	next
	
	on error resume next
	
	InspectObj PPG, , "Cluster_Clear v1.0", siModal
	
	'Check if Dialog cancelled
	If ( Err.Number <> 0 ) Then
		' error occurred or user cancelled.  Delete dialog and exit
		DeleteObj PPG
		Exit Function
	end if
	
	' Retrieve settings from the dialog
	redim v(oGeometry.Clusters.Count)
	l = 0
	for each oCls in oGeometry.Clusters
		dotout = replace(oCls.FullName,".","_")
		v(l) = GetValue( PPG & "." & dotout )
		logMessage oCls.FullName & " has " & oCls.Elements.Count & " elements was deleted"
		if v(l) = true then DeleteObj oCls
		l = l + 1
	next
		
	' Delete the dialog, it's no longer needed.
	DeleteObj PPG
end Function