
! script name: 3dtrim.d/fasttrimtwo
! 3dtopic: fast trim surfaces

!A
!A NAME:
!A
!A 	Fast Trim Surfaces
!A
!A DESCRIPTION:
!A
!A 	This script trims of two intersecting
!A 	surfaces using a fast algorithm.
!A
!B INSTRUCTIONS:
!B
!B 	PICK SURFACE #1: Pick one of the surfaces to be used for the fillet
!B 		and trim procedure.  The pick location will determine the part
!B 		to be saved.
!B
!B 	PICK SURFACE #2: Pick the other surface to be used for the fillet and
!B 		trim procedure.  The pick location will determine the part to
!B 		be saved.
!B
!C NOTES:
!C
!C 	The fast trim is mathematically the same as the regular trim.
!C
!C 	The fast trim is fast because it uses the pick locations and it
!C 	does not search as exhaustively for all possible intersections.
!C 	The extent of the search is controlled by the patch density
!C 	and the plot density of the surface.
!C
!C 	The fast trim may fail to give the desired trim. This method may
!C 	fail if at least one of the surfaces has many small radii through
!C 	which the trim curve must propagate.
!C
!C 	If this method fails increasing the plot density on one or both
!C 	surfaces forces a more exhaustive search.
!C

stat=ChangeLabelStr("ScriptNameStatus","Function: fast trim surfaces ")

DIM Destination$[256]
DIM Answer$[256]
DIM Surface_dir$[80]


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

Start:!
StdWorkplane

Intersect2:StdWorkplane

Pick_surf1:!
Stat= SetPickMask(WsPickSurfOnly)
stat= SetInputFormat("n0","")
Surface1=PickEntity("PICK SURFACE #1",Answer$)
IF (ExitScript(Destination$)) THEN Leave
IF NOT ValidGeometry(Surface1) THEN Pick_surf1

UVpoint1= LastUVSurfPick(Surface1)
IF NOT ValidGeometry(UVpoint1) THEN Pick_surf1
U= XPointValue(UVpoint1)
V= YPointValue(UVpoint1)


Pick_surf2:!
Stat= SetPickMask(WsPickSurfOnly)
stat= SetInputFormat("n0","")
Surface2=PickEntity("PICK SURFACE #2",Answer$)
IF (ExitScript(Destination$)) THEN Leave
IF NOT ValidGeometry(Surface2) THEN Pick_surf2

UVpoint2= LastUVSurfPick(Surface2)
IF NOT ValidGeometry(UVpoint2) THEN Pick_surf2
U= XPointValue(UVpoint2)
V= YPointValue(UVpoint2)


Stat= SetPickMask(WsPickGeometry)

ActivateUndo
Stat= AdvanceUndoNumber("trim surfs")
Stat= AddItemToUndo(WsUBModifyMode,Surface1)
Stat= AddItemToUndo(WsUBModifyMode,Surface2)
Trim1= 1
Trim2= 1
stat= FastTrimTwoSurfs(Surface1,UVpoint1,Trim1,Surface2,UVpoint2,Trim2,Tol)

stat= DeleteEntity(UVpoint1)
stat= DeleteEntity(UVpoint2)

GOTO Intersect2

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