
! script name: zplanes.d/fixtureplane
! topic: define fixture workplane by three points.

!A
!A NAME:
!A
!A 	Fixture Workplane: 3 points
!A
!A DESCRIPTION:
!A
!A	This script creates a workplane with a fixturing property attached.
!A
!B INSTRUCTIONS:
!B
!B 	FIRST POINT ABS X,Y,Z: Enter the X,Y,Z coordinates
!B 		for the first point.
!B
!B 	SECOND POINT ABS X,Y,Z: Enter the X,Y,Z coordinates
!B 		for the second point.
!B
!B 	THIRD POINT ABS X,Y,Z: Enter the X,Y,Z coordinates for
!B 		the third point.
!B
!# see also - points.d/xyzinput.hlp
!# see also - htdocs/help.d/fixplanes.htm

stat=ChangeLabelStr("ScriptNameStatus","Function: fixture workplane: 3 points ")

DIM Answer$[256]
DIM Destination$[256]
DIM PlaneInfo$[32000]
DEG

StdWorkplane
stat= SetInputFormat("n4","")
Normal_len=NamedVarVal("3D Normal Length",Ws3DSystemVars,1.0)
Units= CurrentUnits
IF Normal_len<= 0 THEN
	IF Units=WsMetric THEN
		Normal_len= 7
	ELSE
		Normal_len= 0.25
	END IF
ELSE
	Normal_len= 0.25
END IF
	

CALL FixturePlaneInfo(PlaneInfo$,Destination$,Leave_script)
IF Leave_script THEN Leave
PlaneInfo=ReadUserData(WsGeneralString,"Fixture workplane",PlaneInfo$,WsTrue)

Id_number= UserDataType(PlaneInfo)
PRINT Id_number

P1=XyzInput("FIRST POINT",WsXyzInput)
IF (ExitScript(Destination$)) THEN Leave

P2=XyzInput("SECOND POINT",WsXyzInput)
IF (ExitScript(Destination$)) THEN Leave

P3=XyzInput("THIRD POINT",WsXyzInput)
IF (ExitScript(Destination$)) THEN Leave

T1=ThreePtTrans(P1,P2,P3)

Stat=SetWorkplane(T1)
Pc= PointXYZ(0,0,0)
Pe= PointXYZ(0,0,Normal_len)
Name$= UserDataStr(PlaneInfo,"Workplane entity name:")
Stat= NameEntity(Pc,Name$)
stat= PutUserValue(PlaneInfo,"Class id number:",Id_number)
Stat=AssocUserData(Pc,PlaneInfo,Id_number)
E1= TextLine(Pc,CHR$(168))
L1= LineTwoPoints(Pc,Pe)
Stat=AssocUserData(Pc,PlaneInfo,Id_number)
Stat=AssocUserData(L1,PlaneInfo,Id_number)
Stat=AssocUserData(E1,PlaneInfo,Id_number)
Stat= DeleteEntity(Pe)
IF IsRulerOn THEN PlotAll

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



SUB FixturePlaneInfo(PlaneInfo$,Destination$,Leave_script)
DIM A$[512]
DIM Prop_dir$[512]

Leave_script=0
PlaneInfo$=""
Info:!
Stat= NamedVarStr("properties dir",WsSystemVars,"/usr/weber/database/properties/",Prop_dir$)
A$= UniformPathName(FileNameString(Prop_dir$,"FixtureWorkplane/template"))
PlaneInfo= ReadUserData(WsFixtureWorkplane,"Project directory information",A$)
IF NOT ValidGeometry(PlaneInfo) THEN Leave_script

stat= PutUserString(PlaneInfo,"Name:","Fixture_plane")
stat= PutUserValue(PlaneInfo,"Class id number:",WsFixtureWorkplane)

Edit_data:!
Input_stat= MultiEditDataStr(PlaneInfo,":")
IF (ExitScript(Destination$)) THEN Leave_script
IF Input_stat=27 THEN Leave_script
IF Input_stat=1 THEN Edit_data

Stat= UserDataString(PlaneInfo,PlaneInfo$)
Stat= DeleteEntity(PlaneInfo)
GOTO Leave_info

Leave_script: Leave_script=1
Stat= DeleteEntity(PlaneInfo)
Leave_info:!
SUBEND
