
! script name: v3dtrim.d/fasttrimtwo
! var_topic: fast trim surfaces

!A
!A NAME:
!A
!A 	Fast Trim Surfaces	VARIATIONAL
!A
!A DESCRIPTION:
!A
!A 	This script trims of two intersecting 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

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

DIM Destination$[256]
DIM Answer$[256]
DIM Surface_dir$[80]
DIM Name1$[256]
DIM Name2$[256]
DIM Name$[256]

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


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

Intersect2:!

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

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

Stat=SetPickMask(WsPickGeometry)
Uvalue1=XPointValue(UVpoint1)
Vvalue1=YPointValue(UVpoint1)
Uvalue2=XPointValue(UVpoint2)
Vvalue2=YPointValue(UVpoint2)
Stat=DeleteEntity(UVpoint1)
Stat=DeleteEntity(UVpoint2)

Trim1= 1
Trim2= 1


ActivateUndo
Stat= AdvanceUndoNumber("trim surfaces")
Stat= AddItemToUndo(WsUBModifyMode,Name1$)
Stat= AddItemToUndo(WsUBModifyMode,Name2$)

RecordFunctionOn
Stat= RecordDescr("TRIM: Two Surfaces")
UVpoint1= PointXYZ(Uvalue1,Vvalue1,0)
UVpoint2= PointXYZ(Uvalue2,Vvalue2,0)
V1= FreeParameter("Tolerance",Tol)
stat= FastTrimTwoSurfs(Name1$,UVpoint1,Trim1,Name2$,UVpoint2,Trim2,V1)
Stat=DeleteEntityList(UVpoint1,UVpoint2)
RecordFunctionOff
Curr_record= CurrentVarRecord
CloseVarRecord

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