
! script name: vzplanes.d/plane3pts
! var_topic: define workplane by three unique points

!A
!A NAME:
!A
!A 	Workplane: 3 Points	VARIATIONAL
!A
!A DESCRIPTION:
!A
!A 	This script allows a workplane to be defined by three unique points.
!A
!A~ image location - images/zplane3pts.jpg
!B INSTRUCTIONS:
!B
!B 	FIRST POINT ABS X,Y,Z: Enter the X,Y,Z coordinates for
!B 		the first point.  NOTE: See XYZ INPUT OPTIONS.
!B
!B 	SECOND POINT ABS X,Y,Z: Enter the X,Y,Z coordinates for
!B 		the second point.
!B
!B 	THIRD POINT ABS X,Y,Z: Enter the X,Y,Z coordinates
!B 		for the third point.
!B
!# see also - points.d/xyzinput.hlp

stat=ChangeLabelStr("ScriptNameStatus","Function: workplane: 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
DeActivateUndo
StdWorkplane
stat= SetInputFormat("n4","")

First_point: E1=PickEntity("PICK FIRST POINT")
IF (ExitScript(Destination$)) THEN Leave
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 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 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(WsTransformEnt,Name$)
RecordFunctionOn
Stat= RecordDescr("WORKPLANE: Three Point Workplane")
Stat=SetWorkplane
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
Trans1=ThreePtTrans(P1,P2,P3)
Stat=SetWorkplane(Trans1)
Stat= NameEntity(Trans1,Name$)
Stat= DeleteEntity(P1)
Stat= DeleteEntity(P2)
Stat= DeleteEntity(P3)
RecordFunctionOff
CloseVarRecord

Stat= PlotEntity(Point1$)
Stat= PlotEntity(Point2$)
Stat= PlotEntity(Point3$)
IF IsRulerOn THEN PlotAll

Leave:!
stat= SetInputFormat("n4","")
IF (NOT LEN(Destination$)) THEN
	 LOAD "typecontrol"
ELSE
	 LOAD Destination$
END IF
END

