'//models2nulls vbs //mail2004@grahamdclark.com
'//May 4th 2004
'//rewritten to be faster in large hierarchies
'//turns all models in a hierarchy as well as currently selected, into nulls
'//Directions:
'//select top model above hierarchy to change, run sript
'//options: 
'//TODO:-option for top model effected or not 
'//-copy mixer sources and relations from them to the top model selected



models2nulls selection(0)
'/////////////////////////////////
function models2nulls(inputObject)
'/////////////////////////////////
'models recursive only works thru models children not other objects so need to enumerate

	GetValues oPPGCancelled,RecursiveChildren
	'if nullSelectedModelToo then models2nulls2 inputObject

	if RecursiveChildren then
		set cModel = inputObject.FindChildren(,"#model")
		if inputObject.type = "#model" then 
			ival = 1
		else
			ival = 0
		end if		
	else
		set cModel = inputObject.models(false)
		ival = 0
	end if
	
	for i = ival to cModel.count -1
		set master = GetMaster(cModel.item(i))
		if typename(master) = "Nothing" then
			sname = cModel.item(i).name
			set oNull = cModel.item(i).addnull
			ResetTransform oNull, siObj, siSRT, siXYZ
			ParentObj cModel.item(i).parent, oNull
			for each child in cModel.item(i).children
				'ParentObj oNull, cModel.item(i).children 'noworkie
				ParentObj oNull, child
			next
			deleteObj cModel.item(i)
			oNull.name = sname&"null"
		end if
	next
end function

'//////////////////////////////////
Function GetValues(oPPGCancelled,RecursiveChildren)
'//////////////////////////////////
	set oRoot = application.activeproject.activescene.root
	set oPPG = oRoot.AddProperty("Custom_parameter_list",,"model2nulls options")
	SIAddCustomParameter oPPG, "RecursiveChildren", siBool, True,0,1,0,4,,,, "RecursiveChildren"
	
	On Error Resume Next
	InspectObj oPPG ,,"model2nulls options",SIModal
	'oPPGCancelled = Err.Number
	If Err.Number <> 0 Then
		LogMessage "cancelled", siError
		oPPGCancelled = True
		DeleteObj oPPG
		Exit Function
	End If
	
	RecursiveChildren = oPPG.RecursiveChildren.value

	LogMessage "options selected"
	DeleteObj oPPG
End Function
