
! script name: vzplanes.d/fixtureplane
! var_topic: define fixture workplane by three points.

!A
!A NAME:
!A
!A 	Fixture Workplane: 3 points  VARIATIONAL
!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
!B 		coordinates for the first point.
!B 		NOTE: See XYZ INPUT OPTIONS.
!B
!B 	SECOND POINT ABS X,Y,Z: Enter the X,Y,Z
!B 		coordinates for the second point.
!B
!B 	THIRD POINT ABS X,Y,Z: Enter the X,Y,Z
!B 		coordinates for the third point.
!B
!# see also - htdocs/help.d/fixplanes.htm

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

DIM Answer$[256]
DIM Destination$[256]
DIM PlaneInfo$[32000]
DIM Namelist$[32000]
DIM Point1$[256]
DIM Point2$[256]
DIM Point3$[256]
DIM Name$[256]
DIM Dname$[256]
DIM Gname$[256]
DIM Prop_dir$[512]
DIM Prop_name$[256]
DIM A$[512]
DIM B$[512]
DEG

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

Stat= NamedVarStr("properties dir",WsSystemVars,"/usr/weber/database/properties/",Prop_dir$)

DeActivateUndo
Start:!
StdWorkplane
stat= SetInputFormat("n4","")
Units= CurrentUnits
IF Units=WsMetric THEN
	Normal_len= 7
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)
Prop_name$= UserDataStr(PlaneInfo,"Name:")

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$)
Stat= GenerateVarName(WsDataStrEnt,Dname$)
Stat= GenerateVarName(WsGroupEnt,Gname$)
RecordFunctionOn
Stat= RecordDescr("WORKPLANE: Fixture Workplane")
Stat=SetWorkplane
V1= StringConstant(Prop_dir$)
V2= StringConstant("FixtureWorkplane")
V3= StringConstant("template")
V4= StringConstant(UniformPathName(JoinStrings(V1,"/",V2,"/",V3)))
V5= StringConstant(Prop_name$)
Prop_ent= ReadUserData(WsFixtureWorkplane,V5,V4)
RecordFunctionOff
Namelist$= DataFieldListStr(PlaneInfo,":",",",NoOrder,WsFalse)
Nfields= StringFieldCount(Namelist$,",")
FOR I= 1 TO Nfields
	A$= DataFieldStr(Namelist$,",",I)
	IF LEN(A$) THEN
		IF NOT (A$= "Class name" OR A$= "Class id number") THEN
		A$= A$&":"
		B$= UserDataStr(PlaneInfo,A$)
		RecordFunctionOn
		V7= StringConstant(A$)
		V8= StringConstant(B$)
		Stat= PutUserString(Prop_ent,V7,V8)
		RecordFunctionOff
		END IF
	END IF
NEXT I
RecordFunctionOn
Stat= NameEntity(Prop_ent,Dname$)
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$)

Pc= PointXYZ(0,0,0)
G1= DatumPointMarker(Pc,WsFixtureWorkplane,Normal_len,CHR$(168))
Stat= AssocUserData(G1,Prop_ent,WsFixtureWorkplane)
Stat= AutoNameGroup(G1,Gname$)

V1= StringConstant("Workplane entity name:")
V2= StringConstant("Class id number:")
Stat= NameEntity(Pc,UserDataStr(Prop_ent,V1))
stat= PutUserValue(Prop_ent,V2,WsFixtureWorkplane)
Stat=AssocUserData(Pc,Prop_ent,WsFixtureWorkplane)

Stat= DeleteEntity(P1)
Stat= DeleteEntity(P2)
Stat= DeleteEntity(P3)
Stat= DeleteEntity(G1)
RecordFunctionOff
CloseVarRecord

Stat= DeleteEntity(PlaneInfo)
IF IsRulerOn THEN PlotAll

GOTO Start


Leave:!
Stat= DeleteEntity(PlaneInfo)
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= DeleteUserField(PlaneInfo,"Class name:")
Stat= DeleteUserField(PlaneInfo,"Class id number:")

stat= PutUserString(PlaneInfo,"Name:","Fixture_plane")

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= PutUserValue(PlaneInfo,"Class id number:",WsFixtureWorkplane)
Stat= UserDataString(PlaneInfo,PlaneInfo$)
Stat= DeleteEntity(PlaneInfo)
GOTO Leave_info

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