
! script name: 3dtrim.d/trim2surfs
! 3dtopic: trim two intersecting surfaces to each other

!A
!A NAME:
!A
!A 	Trim Two Surfaces
!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]

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

ActivateUndo
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

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

Stat=SetPickMask(WsPickGeometry)

ActivateUndo
Stat= AdvanceUndoNumber("trim surfs")
Stat= AddItemToUndo(WsUBModifyMode,Surface1)
Stat= AddItemToUndo(WsUBModifyMode,Surface2)

Stat=TrimTwoSurfaces(Surface1,UVpoint1,Surface2,UVpoint2,Tol)
Stat=DeleteEntity(UVpoint1)
Stat=DeleteEntity(UVpoint2)
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
