
! script name: 3dtrim.d/resolvetrim
! 3dtopic: resolve trim curves

!A
!A NAME:
!A
!A 	Resolve Trim Curves
!A
!A DESCRIPTION:
!A
!A 	This script resolves intersecting trim curves.  The trim curves
!A 	are trimmed to each other and joined into closed trim curves.
!A
!B INSTRUCTIONS:
!B
!B 	PICK SURFACE: Pick the surface to be trimmed .
!B
!C NOTES:
!C
!C 	Normally, when a surface is trimmed, the trim curve created is
!C 	created without regard to other trim curves that are applied to
!C 	the surface.  
!C 	The Resolve Trim Curves will take all trim curves applied to a
!C 	surface and find the region valid with regard to all trim curves.
!C 	It will then remove redundant trim curves and extraneous
!C 	information and resolve the resulting trim curves into the
!C 	minimum number of curves required.
!C

Stat=ChangeLabelStr("ScriptNameStatus","Function: resolve trim curves ")

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

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

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

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

Trim_surf:Stat=SetPickMask(WsPickGeometry)
Stat=ResolveTrimCurves(Surface,Tol,UVpoint)
Stat=DeleteEntity(UVpoint)

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
