
! script name: 3dcpath.d/smoothcpath
! 3dtopic: smooths a cutter path

!A
!A NAME:
!A
!A 	Smooth 3D Cutterpath
!A
!A DESCRIPTION:
!A
!A 	This script wil smooth a 3D Cutterpath.
!A
!B INSTRUCTIONS:
!B
!B 	PICK CUTTERPATH TO BE CHANGED: Pick the cutter path to be changed.
!B
!B
!C NOTES:
!C
!C	The smoothed curve will deviate from the original cutterpath.
!C	The deviation may be enough to cause gouging. There is no
!C	check for this in this function.
!C
!C	A value of Smooth=1 will use a cubic nurb curve. A value of
!C	Smooth=2 will use a bezier curve.
!C
!C	A small distance will
!C	cause more points to be generated thus causing the smoothed
!C	curve to be closer to the contour.
!C
!C	Output circles will cause the curve to
!C	be generated with circle and line segments.
!C

Stat=ChangeLabelStr("ScriptNameStatus","Function: smooth 3d cutterpath")

DIM Destination$[256]
DIM Answer$[256]


DeActivateUndo
Tol=NamedVarVal("3D Cutting Tol",Ws3DSystemVars,0.005)
Dist=NamedVarVal("smoothing distance",WsSystemVars,100*Tol)
Circle_sw=1
Smooth= 1


Pick_loop:Cpath=PickEntity("PICK CUTTERPATH")
IF ExitScript(Destination$) THEN Leave
IF NOT ValidGeometry(Cpath) THEN Pick_loop
Etype=EntityType(Cpath)
IF Etype<>WsCPathFileEnt THEN Pick_loop


Stat=EraseEntity(Cpath)
Stat=SmoothCpath(Cpath,Dist,Tol,Smooth,Circle_sw)
Stat=PlotEntity(Cpath)

GOTO Pick_loop

Leave:!
V1=CreateVariable("smoothing distance",WsSystemVars,Dist)
Stat=SetInputFormat("n4","")
IF NOT LEN(Destination$) THEN
	LOAD "typecontrol"
ELSE
	LOAD Destination$
END IF
END

