
! script name: 3dtrim.d/resolvetrim
! var_topic: 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]
DIM Surface$[256]

Var_object= CheckVarObject
IF (ExitScript(Destination$)) THEN Leave

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

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


Uvalue=XPointValue(UVpoint)
Vvalue=YPointValue(UVpoint)
Stat=DeleteEntity(UVpoint)


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

RecordFunctionOn
Stat= RecordDescr("TRIM: Resolve Trim Curves")
UVpoint= PointXYZ(Uvalue,Vvalue,0)
V1= FreeParameter("Tolerance",Tol)
Stat=ResolveTrimCurves(Surface$,V1,UVpoint)
Stat=DeleteEntity(UVpoint)
RecordFunctionOff
Curr_record= CurrentVarRecord
CloseVarRecord

Stat= AddItemToUndo(WsUBCreateMode,Curr_record)
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
