
! script name: vpksheets.d/vpkplane3pts
! var_solids: construct plane sheet body defined by three unique points

!A
!A NAME:
!A
!A 	Sheet: 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

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
Stat= GLPlotOn
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)


WPKClearErrorFlag
Stat= GenerateVarName("Body",Name$)
RecordFunctionOn
Stat= RecordDescr("SHEET: Three Point Plane")
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)
RecordFunctionOff
IF ValidGeometry(Plane1) THEN
        Make_record= WsTrue
        RecordFunctionOn
        Pkbody=WPKBasicSolid(Plane1)
        Stat= WPKNameBody(Pkbody,Name$)
        Stat= WPKSetBodyParent(Pkbody)
        Stat= DeleteEntity(Plane1,WsTrue)
        RecordFunctionOff
ELSE
        Make_record= WsFalse
END IF
RecordFunctionOn
Stat= DeleteEntityList(P1,P2,P3)
RecordFunctionOff
Curr_record= CurrentVarRecord
CloseVarRecord
IF Make_record= WsFalse THEN
	DelLastVarRecord
ELSE
	Stat= WPKSolidRecordOn(Curr_record)
	ActivateUndo
	Stat= AdvanceUndoNumber("plane")
	Stat= AddItemToUndo(WsUBPKSessionMark)
	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
