
! script name: zplanes.d/editworkarea
! TOPIC: Sample:

!A
!A NAME:
!A
!A 	name
!A
!A DESCRIPTION:
!A
!A 	NO HELP AVAILABLE AT THIS TIME
!A
!B INSTRUCTIONS:
!B
!B 	questions with brief description
!B
!C OPTIONS:
!C

stat=ChangeLabelStr("ScriptNameStatus","Function: named workplane")

DIM Destination$[256]
DIM Answer$[256]
DIM Wpname$[256]
DIM File_name$[256]
DIM Dir$[64]
DIM Namelist$[4000]
ENTITY Pt,Ptx,Pty

Pick_direct:!

Use_box=UserSelectBox("Existing Work Areas","Name:",WsWorkArea,WsUserSelect)

Stat=SetInputFormat("a99","")
Stat=GetValue("WORKPLANE TO EDIT ",Wpname$)
IF ExitScript(Destination$) THEN Leave
IF Wpname$= "CANCEL" THEN Leave
LowerSelectBox
WorkArea= FindUserData(Wpname$,WsWorkArea)

IF NOT ValidGeometry(WorkArea) THEN Pick_direct

Start_work= CurrentWorkplane
StdWorkPlane
Px= GetUserValue(WorkArea,"Origin X:")
Py= GetUserValue(WorkArea,"Origin Y:")
Pz= GetUserValue(WorkArea,"Origin Z:")
Ptxx= GetUserValue(WorkArea,"X-axis X:")
Ptxy= GetUserValue(WorkArea,"X-axis Y:")
Ptxz= GetUserValue(WorkArea,"X-axis Z:")
Ptyx= GetUserValue(WorkArea,"Y-axis X:")
Ptyy= GetUserValue(WorkArea,"Y-axis Y:")
Ptyz= GetUserValue(WorkArea,"Y-axis Z:")


	WorkArea=ReadUserData(WsWorkArea,Wpname$,"/usr/weber/userdata/workarea")
	IF NOT ValidGeometry(WorkArea) THEN Pick_direct

	AskWorkplane(Workarea,Pt,Ptx,Pty,Destination$,Do_exit)
	IF Do_exit THEN Leave1

	Component= InputComponent("WORK ZONE NUMBER ")
	IF ExitScript(Destination$) THEN Leave1

	Stat= NamedVarStr("current tool instance",WsSystemVars,"None",Answer$)
	V0=CreateVariable("current tool instance",WsSystemVars,Answer$)
	Stat= PutUserString(WorkArea,"Tool instance:",Answer$)
	Stat= PutUserValue(WorkArea,"Component:",Component)
ELSE
	Stat= GetUserString(WorkArea,"Tool instance:",Answer$)
	V0= CreateVariable("current tool instance",WsSystemVars,Answer$)
	Component= GetUserValue(WorkArea,"Component:")
	IF CheckUserField(WorkArea,"Origin X:",0) THEN

		StdWorkplane
		Pt= PointXYZ(Px,Py,Pz)
		Ptx= PointXYZ(Ptxx,Ptxy,Ptxz)
		Pty= PointXYZ(Ptyx,Ptyy,Ptyz)
	ELSE
		AskWorkplane(Workarea,Pt,Ptx,Pty,Destination$,Do_exit)
		IF Do_exit THEN Leave
	END IF
END IF

T1=ThreePtTrans(Pt,Ptx,Pty)
Stat=SetWorkplane(T1)
Stat=SetCurrComponent(Component)
V0=CreateVariable("current work area",123456,Wpname$)
IF IsRulerOn THEN PlotAll

GOTO Leave

Leave1:!
IF ValidGeometry(WorkArea) THEN Stat= DeleteEntity(WorkArea)
Leave:!
IF ValidGeometry(Pt) THEN Stat= DeleteEntity(Pt)
IF ValidGeometry(Ptx) THEN Stat= DeleteEntity(Ptx)
IF ValidGeometry(Pty) THEN Stat= DeleteEntity(Pty)
LowerSelectBox
Stat=SetInputFormat("n4","")
IF NOT LEN(Destination$) THEN
	LOAD "typecontrol"
ELSE
	LOAD Destination$
END IF
END

SUB AskWorkplane(Workarea,Pt,Ptx,Pty,Destination$,Do_exit)
	Do_exit= 0
	Start_work= CurrentWorkplane
	StdWorkplane
	Stat=SetInputFormat("n4","")
	Pt=XyzInput("WORKPLANE ORIGIN ",WsXYZInput)
	IF ExitScript(Destination$) THEN Leave

	Ptx=XyzInput("X AXIS DEFINING POINT",WsXYZInput)
	IF ExitScript(Destination$) THEN Leave

	Pty=XyzInput("Y AXIS DEFINING POINT",WsXYZInput)
	IF ExitScript(Destination$) THEN Leave

	Stat= PutUserValue(WorkArea,"Origin X:",XPointValue(Pt))
	Stat= PutUserValue(WorkArea,"Origin Y:",YPointValue(Pt))
	Stat= PutUserValue(WorkArea,"Origin Z:",ZPointValue(Pt))
	Stat= PutUserValue(WorkArea,"X-axis X:",XPointValue(Ptx))
	Stat= PutUserValue(WorkArea,"X-axis Y:",YPointValue(Ptx))
	Stat= PutUserValue(WorkArea,"X-axis Z:",ZPointValue(Ptx))
	Stat= PutUserValue(WorkArea,"Y-axis X:",XPointValue(Pty))
	Stat= PutUserValue(WorkArea,"Y-axis Y:",YPointValue(Pty))
	Stat= PutUserValue(WorkArea,"Y-axis Z:",ZPointValue(Pty))
	SUBEXIT
Leave:!
	Do_exit=1
	IF ValidGeometry(Start_work) THEN Stat=SetWorkplane(Start_work)
SUBEND
