
! script name: v3dinter.d/int3surfs
! var_topic: intersect three surfaces

!A
!A NAME:
!A
!A 	Intersect Three Surfaces	VARIATIONAL
!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]
DIM Name1$[256]
DIM Name2$[256]
DIM Name3$[256]
DIM Name$[256]

Tol=NamedVarVal("3D Intersect Tol",Ws3DSystemVars,0.005)
Var_object= CheckVarObject
IF (ExitScript(Destination$)) THEN Leave

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

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

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


Stat= GenerateVarName(WsPointEnt,Name$)
RecordFunctionOn
Stat= RecordDescr("POINT: Three Surface intersect")
Stat= SetRecDelLastExec
stat= Set3dInterOffset(0.0)
V1= FreeParameter("Tolerance",Tol)
UVpoint1= PointXYZ(Uvalue1,Vvalue1,0)
UVpoint2= PointXYZ(Uvalue2,Vvalue2,0)
UVpoint3= PointXYZ(Uvalue3,Vvalue3,0)
P1=IntThreeSurfs(Name1$,UVpoint1,Name2$,UVpoint2,Name3$,UVpoint3,V1)
Stat= NameEntity(P1,Name$)
stat= DeleteEntityList(UVpoint1,UVpoint2,UVpoint3)
RecordFunctionOff
Curr_record= CurrentVarRecord
CloseVarRecord
IF NOT ValidGeometry(P1) THEN
        DelLastVarRecord
ELSE
	ActivateUndo
	Stat= AdvanceUndoNumber("intersect pt")
	Stat= AddItemToUndo(WsUBCreateMode,P1)
	Stat= AddItemToUndo(WsUBCreateMode,Curr_record)
END IF
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
