
! script name: zplanes.d/sldaxiswkpln
! topic: define workplane normal to a 3d solid axis.

!A
!A NAME:
!A
!A 	Workplane: Normal to the axis line of a 3D solid.
!A
!A DESCRIPTION:
!A
!A 	This script makes a workplane normal the axis line of a 3D solid.
!A
!B INSTRUCTIONS:
!B
!B 	PICK SOLID: pick the surface to determine the axis.
!B
!B	PICK AXIS ZERO: Pick the point on the axis to determine the zero.
!B	
!B
!C NOTE:
!C
!C	This script will establish a workplane which is normal
!C	to a to the axis line of a solid.
!C
!C	This can be a helpful feature for machining a 3d model with
!C	a rotary or five axis machine tool when the model uses 
!C	surfaces of revolution to represent holes.
!C

stat=ChangeLabelStr("ScriptNameStatus","Function: workplane: normal to solid axis ")

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

Normal_len=NamedVarVal("3D Normal Length",Ws3DSystemVars,1.0)
Tol=NamedVarVal("3D Fillet Tol",Ws3DSystemVars,0.005)
Forward_color=3
Reverse_color=4

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

Pick_surface:!
Stat=SetPickMask(WsPickSurfOnly)
Surface=PickEntity("PICK SOLID")
IF (ExitScript(Destination$)) THEN Leave
Stat=SetPickMask(WsPickGeometry)

Orient_line:!
Stat=SetPickMask(WsPickNoSurf)
Axis_line= SolidAxis(Surface)
Ps= ParameterPt(Axis_line,0.0)
Pe= ParameterPt(Axis_line,1.0)
Stat= SetColor(Ps,Reverse_color,WsTrue)
Stat= SetColor(Pe,Forward_color,WsTrue)
Stat= SetColor(Axis_line,Forward_color,WsTrue)
Pt=PickSpecificEnt("PICK AXIS ZERO",WsPickPoints)
IF (ExitScript(Destination$)) THEN Leave
Stat=SetPickMask(WsPickGeometry)

Stat=DeleteEntity(Axis_line)
D1= DistTwoPts(Pt,Ps)
D2= DistTwoPts(Pt,Pe)
IF D1< D2 THEN
	Axis_line= LineTwoPoints(Pe,Ps)
	Pzero= ParameterPt(Ps,0.0)
ELSE
	Axis_line= LineTwoPoints(Ps,Pe)
	Pzero= ParameterPt(Pe,0.0)
END IF
Stat=DeleteEntity(Ps)
Stat=DeleteEntity(Pe)


T1=LineToVertTrans(Axis_line,Pzero)
Stat=SetWorkplane(T1)
Stat=DeleteEntity(Axis_line)
Stat=DeleteEntity(Pzero)
IF IsRulerOn THEN PlotAll

WplaneEnt= FindNamedVar("current work area",123456)
IF ValidGeometry(WplaneEnt) THEN Stat= DeleteEntity(WplaneEnt)


Leave:!
Stat=SetPickMask(WsPickGeometry)
Stat=DeleteEntity(Ps)
Stat=DeleteEntity(Pe)
Stat=DeleteEntity(Axis_line)
Stat=DeleteEntity(Pzero)

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

END

