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

!A
!A NAME:
!A
!A 	To XYZ Curves
!A
!A DESCRIPTION:
!A
!A 	This script allows a group of XYZ curves to be used as a trim boundary.
!A	The Curves are automatically linked into a connected curves internally.
!A 	Then either the part of the surface inside the resultant curves, 
!A	or the part of the surface outside the curve may be saved.  
!A	This feature 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 contours to be used as the XYZ trim curve
!B 		for the surface.  The XYZ curve must lie on the surface.
!B		If the curve deviates from the surface by more than the
!B		tolerance, the calculation time is drastically increased.
!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]

Tol=NamedVarVal("3D Trimming Tol",Ws3DSystemVars,0.005)
Highlight_color= 4
Stat= SetDefaults(WsSelectedEntPen,Highlight_color)

ActivateUndo
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

Curve_group=CreateGroup("TEMPGROUP")

Pick_loop:Stat=SetInputFormat("a1",",P,")
Stat=SetPickMask(WsPickNoSurf)
Count1=GroupCount(Curve_group)+1
Curve=PickGroupEnt("PICK CONTOUR #"&VAL$(Count1)&" , Proceed ",0,Answer$)
IF ExitScript(Destination$) THEN Leave
IF Answer$="P" THEN Trim_surf
IF NOT ValidGeometry(Curve) THEN Pick_loop
Stat=AddToGroup(Curve_group,Curve)
Stat= SetSelectedFlag(Curve,WsTrue)
Stat= PlotEntity(Curve)
GOTO Pick_loop

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

Trim_surf:Stat=SetPickMask(WsPickGeometry)
Stat=TrimToCurveGrp(Curve_group,Surface,Tol,UVpoint)
Stat= SetSelectedFlag(Curve_group,WsFalse)
Stat= PlotEntity(Curve_group)
Stat=DeleteEntity(UVpoint)
Stat=DeleteEntity(Curve_group)

GOTO Intersect2

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