
! script name: 3dintersect.d/int3surfs
! 3dtopic: intersect three surfaces

!A
!A NAME:
!A
!A 	Intersect Three Surfaces
!A
!A DESCRIPTION:
!A
!A 	This script will generate a point at the intersection of three surfaces.
!A 	The pick location on each surface will determine which intersection is
!A 	to be generated.
!A
!B INSTRUCTIONS:
!B
!B 	PICK SURFACE #1: Pick the first surface.  Note: The pick location is
!B 		important.
!B
!B 	PICK SURFACE #2: Pick the the second surface.  Note: The pick location
!B 		is important.
!B
!B 	PICK SURFACE #3: Pick the third surface.  Note: The pick location is
!B 		important.
!B
!C NOTES:
!C
!C 	The pick location should be near the desired intersection, failure
!C 	to do this may result in no point generated.
!C

Stat=ChangeLabelStr("ScriptNameStatus","Function: intersect 3 surfaces ")

DIM Destination$[256]
DIM Answer$[256]

ActivateUndo
Tol=NamedVarVal("3D Intersect Tol",Ws3DSystemVars,0.005)
Start:!
StdWorkplane
Stat=Setup3dCutter(WsNullTool,0.0,0.0,0.0,0.0,0.0)

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:!
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

Pick_surf3:!
Surface3=PickEntity("PICK SURFACE #3",Answer$)
IF ExitScript(Destination$) THEN Leave
IF NOT ValidGeometry(Surface3) THEN Pick_surf3
UVpoint3=LastUVSurfPick(Surface3)
IF NOT ValidGeometry(UVpoint3) THEN Pick_surf3

Stat=SetPickMask(WsPickGeometry)

p1=IntThreeSurfs(Surface1,UVpoint1,Surface2,UVpoint2,Surface3,UVpoint3,Tol)

Stat=DeleteEntity(UVpoint1)
Stat=DeleteEntity(UVpoint2)
Stat=DeleteEntity(UVpoint3)

ActivateUndo
Stat= AdvanceUndoNumber("point")
Stat= AddItemToUndo(WsUBCreateMode,P1)
GOTO Intersect2

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