
! script name: vzplanes.d/ptparatilt
! var_topic: parallel workplane through point with tilt angles.

!A
!A NAME:
!A
!A 	Parallel Workplane Through a Point with Tilt Angles	VARIATIONAL
!A
!A DESCRIPTION:
!A
!A      This script allows a workplane to be made parallel to an existing
!A      workplane through a defined point with tilt angles relative to
!A      the existing workplane axis.
!A
!A
!B INSTRUCTIONS:
!B
!B 	PICK ENTITY FOR EXISTING WORKPLANE: Pick
!N 		an entity on the existing workplane.
!B
!B 	WORKPLANE ZERO ABS X,Y,Z: Enter the X,Y,Z
!B 		coordinates of the point to be used as the
!B 		reference point for making the new workplane.
!B 		NOTE: See XYZ INPUT OPTIONS.
!B
!B      X TILT ANGLE: Give the tilt angle about the relative x axis.
!B
!B      Y TILT ANGLE: Give the tilt angle about the relative y axis.
!B
!B      Z ROTATION ANGLE: Give the rotation angle about
!B 		the relative z axis.
!B
!# see also - points.d/xyzinput.hlp

stat=ChangeLabelStr("ScriptNameStatus","Function: parallel pt workplane with xyz angles")

DIM Answer$[256]
DIM Destination$[256]
DIM Element$[256]
DIM XAngle_var$[256]
DIM YAngle_var$[256]
DIM ZAngle_var$[256]
DIM Name$[256]
DIM Center$[256]

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

DeActivateUndo
stat= SetInputFormat("n4","")

Pick_entity:E1=PickEntity("PICK ENTITY FOR EXISTING WORKPLANE")
IF (ExitScript(Destination$)) THEN Leave
IF NOT ValidDependency(E1) THEN Pick_entity
Stat= EntityNameCheck(E1,Element$)

Trans1= GetTransform(E1)


Center_point: E1=PickEntity("PICK WORKPLANE ZERO")
IF (ExitScript(Destination$)) THEN Leave
IF NOT ValidDependency(E1) THEN Center_point
T= LastPickPara
Pick_return= CurrPickReturn
Stat= EntityNameCheck(E1,Center$)

XAngle_ques:XAngle=InputAngle("X TILT ANGLE")
IF (ExitScript(Destination$)) THEN Leave
No_xangle_var= LastVariableInput(XAngle_var$)
IF ValidGeometry(L1) THEN
        IF NOT ValidDependency(L1) THEN XAngle_ques
        Stat= EntityNameCheck(L1,XAngle_var$)
        No_xangle_var=0
END IF


YAngle_ques:YAngle=InputAngle("Y TILT ANGLE")
IF (ExitScript(Destination$)) THEN Leave
No_yangle_var= LastVariableInput(YAngle_var$)
IF ValidGeometry(L1) THEN
        IF NOT ValidDependency(L1) THEN YAngle_ques
        Stat= EntityNameCheck(L1,YAngle_var$)
        No_yangle_var=0
END IF


ZAngle_ques:ZAngle=InputAngle("Z ROTATION ANGLE")
IF (ExitScript(Destination$)) THEN Leave
No_zangle_var= LastVariableInput(Zangle_var$)
L1= LastPickEnt
IF ValidGeometry(L1) THEN
        IF NOT ValidDependency(L1) THEN ZAngle_ques
        Stat= EntityNameCheck(L1,ZAngle_var$)
        No_zangle_var=0
END IF


Stat= GenerateVarName(WsTransformEnt,Name$)
RecordFunctionOn
Stat= RecordDescr("WORKPLANE: Parallel thru point with tilt angles")
Stat=SetWorkplane(Element$)
Trans1= CurrentWorkplane
SELECT Pick_return
CASE WsGeometryEnd
        Pc= ParameterReturnPt(Center$,T,WsGeometryEnd)
CASE WsGeometryMid
        Pc= ParameterReturnPt(Center$,T,WsGeometryMid)
CASE WsGeomCenter
        Pc= ParameterReturnPt(Center$,T,WsGeomCenter)
END SELECT
IF No_xangle_var THEN
        V1= FreeParameter("X Angle",Xangle)
ELSE
        V1= FreeParameter("X Angle",XAngle_var$)
END IF
IF No_yangle_var THEN
        V2= FreeParameter("Y Angle",Yangle)
ELSE
        V2= FreeParameter("Y Angle",YAngle_var$)
END IF
IF No_zangle_var THEN
        V3= FreeParameter("Z Angle",Zangle)
ELSE
        V3= FreeParameter("Z Angle",ZAngle_var$)
END IF
Trans2= ParallelPointTrans(Trans1,Pc,V1,V2,V3)
Stat=SetWorkplane(Trans2)
Stat= NameEntity(Trans2,Name$)
Stat=DeleteEntity(Pc)
RecordFunctionOff
CloseVarRecord

Stat= PlotEntity(Center$)
IF IsRulerOn THEN PlotAll

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