(
global islRoll
try(destroydialog islRoll) catch() 
rollout islRoll " Line With Parallel Axis"
(
	fn filterLine s = classof s == splineshape and classof s == line and numSplines s == 1 and numKnots spl == 2
	fn setPivotDir spl state: = 
	(
		with redraw off
		local rotValInv = inverse ((matrixFromNormal (pathTangent spl 1 0.0)).rotationpart)
		if not cb_pivot.checked then spl.pivot = spl.center else spl.pivot = (getKnotPoint spl 1 1)
		ResetTransform spl ; animate off in coordsys spl spl.rotation *= RotValInv
		spl.objectoffsetrot *= RotValInv ; spl.objectoffsetpos *= RotValInv
		local curTM = spl.transform ; for i = 1 to 3 do spl[3][2][i].track.value = 0
		resetXform spl ; collapseStack spl ; 	spl.transform = curTM
		if state != 3 do
		(
			rot = case state of (
				1: (inverse ((EulerAngles -90 -90 0) as quat))
				2: ((EulerAngles -90 180 0) as quat)
			)
			animate off in coordsys local spl.rotation *= rot
			spl.objectoffsetrot *= rot ; spl.objectoffsetpos *= rot
		)
	)
	
	/*tool create2KS
	(
		local spl
		on mousePoint clickno do
		(
			spl = splineShape isSelected:on
					
			addNewSpline spl
			if clickno == 1 do
			(	
				addKnot spl 1 #corner #line gridpoint
				addKnot spl 1 #corner #line gridpoint
			)	
			if clickno == 3 do
			(	
				addKnot spl 1 #corner #line gridpoint
				--addKnot spl 1 #corner #line gridpoint
				updateshape spl
				#stop
			)
		)
		on stop do if spl != undefined do (setPivotDir spl state:rb.state)
	)*/
	groupbox gb_lbl "Axis Parallel With Spline:" pos:[2,5] width:156 height:34
	radiobuttons rb "" pos:[8,20] width:77 height:50 labels:#("X          ", "Y", "Z") columns:3
	checkbox cb_pivot "Pivot At First Knot" pos:[3,42] width:150 height:15 checked:true
	button align "Align Axis With Selection" pos:[2,60] width:156 height:20 highlightColor:[28,28,28]
	button start "Start Tool" pos:[2,82] width:156 height:20 highlightColor:[28,28,28]

	
	on align pressed do
	(
		if selection.count == 1 and filterLine selection[1] then (setPivotDir selection[1] state:rb.state) else
		(messageBox "Works on single splne with 2 knots." title:"Warning" beep:false)
	)
	on start pressed do
	(
		--starttool create2KS
	)
)
createDialog islRoll 160 105 10 110 style:#(#style_titlebar, #style_sysmenu, #style_toolwindow)
)