'FitonCv_0
'
'javier@internarte.com
'info: fits multiple curves with similar point densities
'and curve types. Work in progress. more to come
'
'use	1. select curves:
'a. first select template curve (for your convenience)
'b. then select all other curves to refit 
'	2. run routine
'-------------------------------------------------------------

	SetValue "Views.View*.*.camvis.compobjselvert", True
	set fitcollection = CreateObject("XSI.Collection")
	fitcollection.additems selection  
	count = fitcollection.count	
	set newfitcollection = CreateObject("XSI.Collection")
	
	set oRoot = ActiveProject.ActiveScene.Root
	set oNul = oRoot.Addnull("FitCrv_Parent")
	for i =0 to count - 1
		logmessage fitcollection(i)
		set oldcv = fitcollection(i)
		if oldcv.type = "crvlist" then
			set cvgeo = oldcv.ActivePrimitive.Geometry.Curves(0)
			cvlen = cvgeo.length
			ApplyOp "CrvFit", oldcv, 3, siPersistentOperation, newcv 
			Parentobj oNul,newcv
			if i = 0 then
				On Error Resume Next
				InspectObj newcv&".crvlist.fitcrv.points",,"SELECT Default POINT DENSITY TO PROPAGATE",4
					if Err.Number <> 0 then
						Deleteobj newcrv
						exit for
					end if
				Err.Clear
				npts = Getvalue (newcv&".crvlist.fitcrv.points")
				degree = Getvalue (newcv&".crvlist.fitcrv.cont")
				pdist = cvlen/npts		
			else	
				newpts = cvlen/pdist
				if newpts < 4 then
					newpts = 4
				end if
				SetValue newcv&".crvlist.fitcrv.points", newpts
			end if
			FreezeObj newcv&".crvlist.fitcrv"
			DeleteObj oldcv
			'newfitcollection.add newcv
		end if	
		selectobj oNul, "Branch"
	next
'---------------

