
! script name: zplanes.d/normalxpoint
! var_topic: define workplane normal to a line orienting the x axis direction.

!A
!A NAME:
!A
!A 	Workplane: Normal Line Orient X Axis Direction.
!A
!A DESCRIPTION:
!A
!A 	This script makes a workplane normal to a line with the orientation
!A	of the positive x axis determined by a point.
!A
!B INSTRUCTIONS:
!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 	PICK LINE NORMAL TO WORKPLANE: Pick the line
!B 		that will be perpendicular to the new workplane.
!B
!B	PICK X AXIS ORIENT POINT: Pick a point which will
!B 		orient the x-axis.
!B
!# see also - points.d/xyzinput.hlp

stat=ChangeLabelStr("ScriptNameStatus","Function: workplane: pt: normal line ")

DIM Answer$[256]
DIM Destination$[256]
DIM Element$[256]
DIM Name$[256]
DIM Center$[256]
DIM Point$[256]

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

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

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

Stat=SetPickMask(WsPickNoSurf)
Pick_line:L1=PickSpecificEnt("PICK LINE NORMAL TO WORKPLANE",WsPickLines)
IF (ExitScript(Destination$)) THEN Leave
IF NOT ValidDependency(L1) THEN Pick_line
Stat= EntityNameCheck(L1,Element$)

Stat=SetPickMask(WsPickNoSurf)
Orient_point: E2=PickEntity("PICK X AXIS ORIENT POINT")
IF (ExitScript(Destination$)) THEN Leave
IF NOT ValidDependency(E2) THEN Orient_point
Pick_para2= LastPickPara
Pick_return2= CurrPickReturn
Stat= EntityNameCheck(E2,Point$)

Stat= GenerateVarName(WsTransformEnt,Name$)
RecordFunctionOn
Stat= RecordDescr("WORKPLANE: point, normal to line orient x axis")
Stat=SetWorkplane
SELECT Pick_return1
CASE WsGeometryEnd
        Pc= ParameterReturnPt(Center$,Pick_para1,WsGeometryEnd)
CASE WsGeometryMid
        Pc= ParameterReturnPt(Center$,Pick_para1,WsGeometryMid)
CASE WsGeomCenter
        Pc= ParameterReturnPt(Center$,Pick_para1,WsGeomCenter)
END SELECT
SELECT Pick_return2
CASE WsGeometryEnd
        Pt= ParameterReturnPt(Point$,Pick_para2,WsGeometryEnd)
CASE WsGeometryMid
        Pt= ParameterReturnPt(Point$,Pick_para2,WsGeometryMid)
CASE WsGeomCenter
        Pt= ParameterReturnPt(Point$,Pick_para2,WsGeomCenter)
END SELECT
Trans1=NormalLineXPtTrans(Element$,Pc,Pt)
Stat=SetWorkplane(Trans1)
Stat= NameEntity(Trans1,Name$)
Stat=DeleteEntity(Pc)
Stat=DeleteEntity(Pt)
RecordFunctionOff
CloseVarRecord

Stat= PlotEntity(Center$)
Stat= PlotEntity(Point$)
IF IsRulerOn THEN PlotAll

Leave:!
Stat=SetPickMask(WsPickAll)
stat= SetInputFormat("n4","")

IF (NOT LEN(Destination$)) THEN
	 LOAD "typecontrol"
ELSE
	 LOAD Destination$
END IF
END

