
! script name: v3dtrim.d/trim2surfs
! var_topic: trim two intersecting surfaces to each other

!A
!A NAME:
!A
!A 	Trim Two Surfaces	VARIATIONAL
!A
!A DESCRIPTION:
!A
!A 	This script will trim two intersecting surfaces to each other.  The
!A 	pick location on each surface will determine the part to be saved.
!A
!B INSTRUCTIONS:
!B
!B 	PICK SURFACE #1: Pick one of the surfaces to be trimmed.
!B 		Remember, pick location is important.
!B
!B 	PICK SURFACE #2: Pick the other surface to be trimmed.
!B 		Remember, Pick location is important.
!B
!C NOTES:
!C
!C 	The two surfaces or curves to be trimmed must either intersect in
!C 	a closed curve or start and end on an edge of the surface.
!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: trim two 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

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

ActivateUndo
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)

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=TrimTwoSurfaces(Name1$,UVpoint1,Name2$,UVpoint2,V1)
Stat=DeleteEntityList(UVpoint1,UVpoint2)
RecordFunctionOff
Curr_record= CurrentVarRecord
CloseVarRecord

Stat= AddItemToUndo(WsUBCreateMode,Curr_record)
GOTO Intersect2

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