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

!A
!A NAME:
!A
!A 	Workplane: Normal to the axis line of a 3D solid. VARIATIONAL
!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 function is sensitive to the way in which the revolution or
!C	solid is constructed. The free parameter "Axis direction" will
!C	reverse the direction of the axis line.
!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]
DIM Surface$[256]
DIM Name$[256]
DIM Center$[256]

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

DeActivateUndo
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
IF NOT ValidDependency(Surface) THEN Pick_surface
Stat= EntityNameCheck(Surface,Surface$)
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
	Line_dir= WsReverse
ELSE
	Line_dir= WsForward
END IF
Stat=DeleteEntity(Ps)
Stat=DeleteEntity(Pe)



Stat= GenerateVarName(WsTransformEnt,Name$)
RecordFunctionOn
Stat= RecordDescr("WORKPLANE: normal to solid axis")
Stat=SetWorkplane
Axis_line= SolidAxis(Surface$)
Ps= ParameterPt(Axis_line,0.0)
Pe= ParameterPt(Axis_line,1.0)
V1= FreeParameter("Axis direction",Line_dir)
L1= LineTwoPoints(Ps,Pe,WsTrimmed,V1)
Pc= ParameterPt(L1,1.0)
Trans1=LineToVertTrans(L1,Pc)
Stat=SetWorkplane(Trans1)
Stat= NameEntity(Trans1,Name$)
Stat=DeleteEntityList(Ps,Pe,Pc,L1,Axis_line)
RecordFunctionOff
CloseVarRecord

Stat= PlotEntity(Surface$)
IF IsRulerOn THEN PlotAll


Leave:!
Stat=SetPickMask(WsPickGeometry)
Stat=DeleteEntityList(Ps,Pe,Axis_line)

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

END

