
! script name: vsolids.d/plane3pts
! var_topic: construct plane defined by three unique points

!A
!A NAME:
!A
!A 	Plane: Three Points	VARIATIONAL
!A
!A DESCRIPTION:
!A
!A 	This script allows a plane to be defined by three unique points.
!A
!B INSTRUCTIONS:
!B
!B 	PICK FIRST POINT: Pick the first unique point to be used to define
!B 		the plane.
!B
!B 	PICK SECOND POINT: Pick the second unique point to be used to define
!B 		the plane.
!B
!B 	PICK THIRD POINT: Pick the third unique point to be used to define
!B 		the plane.
!B
!C NOTES:
!C
!C 	The U contours of a plane are the lines parallel to the length of
!C 	the plane ( parallel to X axis in an unoriented plane ) and the V
!C 	contours are the lines parallel to the width of the plane ( parallel
!C 	to Y axis in an unoriented plane ).
!C

Stat=ChangeLabelStr("ScriptNameStatus","Function: plane defined by 3 points ")

DIM Answer$[256]
DIM Destination$[256]
DIM Point1$[256]
DIM Point2$[256]
DIM Point3$[256]
DIM Name$[256]
DEG


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

ActivateUndo
Plane_loop:!
Stat= SetInputFormat("n4","")
First_point: E1=PickEntity("PICK FIRST POINT")
IF (ExitScript(Destination$)) THEN Leave
IF NOT ValidGeometry(E1) THEN First_point
IF NOT ValidDependency(E1) THEN First_point
T1= LastPickPara
Pick_return1= CurrPickReturn
Stat= EntityNameCheck(E1,Point1$)
P1= ParameterReturnPt(E1,T1,Pick_return1)

Second_point: E2=PickEntity("PICK SECOND POINT")
IF (ExitScript(Destination$)) THEN Leave
IF NOT ValidGeometry(E2) THEN Second_point
IF NOT ValidDependency(E2) THEN Second_point
T2= LastPickPara
Pick_return2= CurrPickReturn
Stat= EntityNameCheck(E2,Point2$)
P2= ParameterReturnPt(E2,T2,Pick_return2)

Third_point: E3=PickEntity("PICK THIRD POINT")
IF (ExitScript(Destination$)) THEN Leave
IF NOT ValidGeometry(E3) THEN Third_point
IF NOT ValidDependency(E3) THEN Third_point
T3= LastPickPara
Pick_return3= CurrPickReturn
Stat= EntityNameCheck(E3,Point3$)
P3= ParameterReturnPt(E3,T3,Pick_return3)
Stat=DeleteEntity(P1)
Stat=DeleteEntity(P2)
Stat=DeleteEntity(P3)


Stat= GenerateVarName(WsPlaneSolidEnt,Name$)
RecordFunctionOn
Stat= RecordDescr("PLANE: Three Point Plane")
Stat= SetRecDelLastExec
SELECT Pick_return1
CASE WsGeometryEnd
        P1= ParameterReturnPt(Point1$,T1,WsGeometryEnd)
CASE WsGeometryMid
        P1= ParameterReturnPt(Point1$,T1,WsGeometryMid)
CASE WsGeomCenter
        P1= ParameterReturnPt(Point1$,T1,WsGeomCenter)
END SELECT
SELECT Pick_return2
CASE WsGeometryEnd
        P2= ParameterReturnPt(Point2$,T2,WsGeometryEnd)
CASE WsGeometryMid
        P2= ParameterReturnPt(Point2$,T2,WsGeometryMid)
CASE WsGeomCenter
        P2= ParameterReturnPt(Point2$,T2,WsGeomCenter)
END SELECT
SELECT Pick_return3
CASE WsGeometryEnd
        P3= ParameterReturnPt(Point3$,T3,WsGeometryEnd)
CASE WsGeometryMid
        P3= ParameterReturnPt(Point3$,T3,WsGeometryMid)
CASE WsGeomCenter
        P3= ParameterReturnPt(Point3$,T3,WsGeomCenter)
END SELECT
Plane1=ThreePointPlane(P1,P2,P3)
Stat= NameEntity(Plane1,Name$)
Stat= DeleteEntityList(P1,P2,P3)
RecordFunctionOff
Curr_record= CurrentVarRecord
CloseVarRecord
IF NOT ValidGeometry(Plane1) THEN
	DelLastVarRecord
ELSE
	ActivateUndo
	Stat= AdvanceUndoNumber("plane")
	Stat= AddItemToUndo(WsUBCreateMode,Plane1)
	Stat= AddItemToUndo(WsUBCreateMode,Curr_record)
END IF
GOTO Plane_loop

Leave:!
Stat=DeleteEntity(P1)
Stat=DeleteEntity(P2)
Stat=DeleteEntity(P3)
IF NOT LEN(Destination$) THEN
	LOAD "typecontrol"
ELSE
	LOAD Destination$
END IF
END
