
! script name: 3dtrim.d/trimtocurve
! 3dtopic: trim surface to curve

!A
!A NAME:
!A
!A 	To XYZ Curve
!A
!A DESCRIPTION:
!A
!A 	This script allows a XYZ curve to be used as a boundary, and
!A 	either the part of the surface inside the curve, or the part
!A 	of the surface outside the curve may be saved.  This feature
!A 	applies to 3D surfaces only.
!A
!B INSTRUCTIONS:
!B
!B 	PICK SURFACE: Pick the surface to be trimmed to the XYZ curve.
!B
!B 	PICK CONTOUR: Pick the contour to be used as the XYZ trim curve
!B 		for the surface.  The XYZ curve must lie along the surface.
!B
!C NOTES:
!C
!C 	It is important that the XYZ curve lay on the surface to within
!C 	the trimming or intersect tolerance.
!C 	If the XYZ curve extends off the surface or deviates from the
!C 	surface, the routine may or may not be successful in trimming.
!C 	If it is successful, an excessive amount of time may be taken 
!C 	for calculations.
!C
!C 	The "3D Trimming Tol" should be left at its default value unless
!C 	problems occur.  If a problem is encountered, then go to a
!C 	smaller tolerance.  If small parts are the normal, then consider
!C 	changing the default tolerance.  The tolerance may be edited
!C 	temporarily by selecting the Variables option in the Settings menu.
!C 	The default tolerance may be changed permanently by selecting
!C 	the Constants option in the Settings menu.
!C

Stat=ChangeLabelStr("ScriptNameStatus","Function: curve on surface ")

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

ActivateUndo
Tol=NamedVarVal("3D Trimming Tol",Ws3DSystemVars,0.005)

Highlight_color= 4
Stat= SetDefaults(WsSelectedEntPen,Highlight_color)

Start:!
Stat=Setup3dCutter(WsNullTool,0.0,0.0,0.0,0.0,0.0)

Intersect2:StdWorkplane
Stat=SetPickMask(WsPickSurfOnly)
Stat=SetInputFormat("n0","")
Surface=PickEntity("PICK SURFACE",Answer$)
IF ExitScript(Destination$) THEN Leave
IF NOT ValidGeometry(Surface) THEN Intersect2
UVpoint=LastUVSurfPick(Surface)
IF NOT ValidGeometry(UVpoint) THEN Intersect2

Stat=SetPickMask(WsPickNoSurf)

Pick_loop:Stat=SetInputFormat("a1",",P,")
Curve=PickGroupEnt("PICK CONTOUR ",0)
IF ExitScript(Destination$) THEN Leave
IF NOT ValidGeometry(Curve) THEN Pick_loop

Stat=SetPickMask(WsPickGeometry)
Stat= SetSelectedFlag(Curve,WsTrue)
Stat= PlotEntity(Curve)

ActivateUndo
Stat= AdvanceUndoNumber("trim to curve")
Stat= AddItemToUndo(WsUBModifyMode,Surface)

Stat=TrimSurfToCurve(Curve,Surface,Tol,UVpoint)
Stat=DeleteEntity(UVpoint)
Stat= SetSelectedFlag(Curve,WsFalse)
Stat= PlotEntity(Curve)

GOTO Intersect2

Leave:!
Stat=SetInputFormat("n4","")
Stat=DeleteEntity(UVpoint)
Stat=SetPickMask(WsPickGeometry)
IF NOT LEN(Destination$) THEN
	LOAD "typecontrol"
ELSE
	LOAD Destination$
END IF
END
