
! script name: vzplanes.d/zplane
! var_topic: define workplane parallel to XY plane at specified Z

!A
!A NAME:
!A
!A 	Z Level
!A
!A DESCRIPTION:
!A
!A 	This script makes a workplane parallel to the XY plane at the
!A 	specified Z level. Use a Z Level to construct 2D geometry at
!A	a Z coordinate other than zero. When a Z Level is established
!A	all absolute Z values input are referenced from that Z Level.
!A
!A
!A~ image location - images/zplane.jpg
!B INSTRUCTIONS:
!B
!B 	Z LEVEL:  Enter the Z coordinate for the Z level to be established at.
!B

stat=ChangeLabelStr("ScriptNameStatus","Function: z level ")

DIM Answer$[256]
DIM Destination$[256]
DIM Name$[256]
DIM Z_var$[256]
DEG

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

DeActivateUndo
StdWorkplane
stat= SetInputFormat("n4","")
Stat=SetPickReturn(WsGeometryZ)

stat= SetInputFormat("n4=","")
Stat= SetEqualsValue(0)
Zlevel=GetValue("Z LEVEL",Answer$)
Stat=SetPickReturn(WsGeometryEnd)
IF (ExitScript(Destination$)) THEN Leave
No_z_var= LastVariableInput(Z_var$)


Stat= GenerateVarName(WsTransformEnt,Name$)
RecordFunctionOn
Stat= RecordDescr("WORKPLANE: Z Plane")
Stat=SetWorkplane
IF No_z_var THEN
	V1= FreeParameter("Z",Zlevel)
	Pt=PointXYZ(0,0,V1)
ELSE
	Pt=PointXYZ(0,0,Z_var$)
END IF
Trans1=AngleTransform(Pt,0,0,0)
Stat=SetWorkplane(Trans1)
Stat= NameEntity(Trans1,Name$)
Stat=DeleteEntity(Pt)
RecordFunctionOff
CloseVarRecord
IF IsRulerOn THEN PlotAll

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

