
! script name: zplanes.d/settooriginpt
! topic: set workplane to zone origin point

!A
!A NAME:
!A
!A 	Set Workplane to Zone Origin Point
!A
!A DESCRIPTION:
!A
!A 	Sets current workplane and workzone to the origin point of
!A	the specified work zone.
!A
!C OPTIONS:
!C

Stat=ChangeLabelStr("ScriptNameStatus","Function: set workplane to zone origin ")

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

DeActivateUndo
CALL Convert_old_origins
WsNamedComponent= 7041776
WsPplane= 7746279
Dir$="/usr/weber/userdata/"

Stat=UserSelectBox("NAMED ZONES","selected zone",WsNamedComponent,WsUserSelect)
Stat= SetInputFormat("a99","")
E1= PickEntity("WORK ZONE NUMBER ",Answer$)
IF ExitScript(Destination$) THEN Leave
IF ValidGeometry(E1) THEN
	Wzone=GetComponent(E1)
	Answer$=""
ELSE
	IF IsStringNumeric(Answer$) THEN
		Wzone= VAL(Answer$)
		Answer$=""
	END IF
END IF
IF LEN(Answer$) THEN
	IF Answer$="CANCEL" THEN Leave
	E1= FindUserData(Answer$,WsNamedComponent)
	IF NOT ValidGeometry(E1) THEN Start_ques
	Wzone= GetUserValue(E1,"Component:")
END IF
LowerSelectBox

Pick_direct:!
Pplane= FindUserData(VAL$(Wzone),WsPplane)
IF NOT ValidGeometry(Pplane) THEN Leave

Group1= GrpByProp(Pplane,WsPplane)
IF NOT ValidGeometry(Group1) THEN Leave
IF NOT GroupCount(Group1) THEN Leave

Hle= GroupElement(Group1,1)
Stat=SetWorkplane(Hle)
Stat=SetCurrComponent(Wzone)

Stat= DeleteEntity(Group1)
IF IsRulerOn THEN PlotAll

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

SUB Convert_old_origins
DIM Answer$[256]
DIM Zone_name$[256]

G1= UserDataGroup(WsWorkZoneOrigin)
IF NOT ValidGeometry(G1) THEN SUBEXIT
Num_origins= GroupCount(G1)

FOR I= 1 TO Num_origins
        E1= GroupElement(G1,I)
        IF CheckUserField(E1,"Class id number:",1) THEN Next_i
        Group1= GrpByProp(E1,WsWorkZoneOrigin)
        IF NOT ValidGeometry(Group1) THEN Next_i
        IF NOT GroupCount(Group1) THEN Next_i
	GOTO End_it
Next_i: NEXT I
Stat=DeleteEntity(G1)
SUBEXIT
End_it:	Answer$="/usr/weber/database/messages/convert_old_zones"
	Stat=MessageFileBox(Answer$,"INFORMATION")
	Stat=DeleteEntity(G1)
	Stat=DeleteEntity(Group1)
SUBEND
