
! script name: solids.d/holesolid
! 3dtopic: Make a solid of revolution out of a tool shape at a hole

!A
!A NAME:
!A
!A 	Tool Hole Revolution
!A
!A DESCRIPTION:
!A
!A 	This script will make a solid of revolution out of a tool shape.
!A
!B INSTRUCTIONS:
!B
!B 	TOOL: Select the tool.
!B
!B 	PLACEMENT POINT ABS X,Y,Z: Enter the X,Y,Z
!B 		coordinates of the center point of the cylinder.
!B
!# see also - points.d/xyzinput.hlp

stat=ChangeLabelStr("ScriptNameStatus","Function: hole tool solid")

DIM Destination$[256]
DIM Answer$[256]
DIM Tool_name$[256]
DIM Toolid$[256]
DIM Name$[256]


ActivateUndo
Start:!
Stat=SetPickMask(WsPickHoles)
Stat=SetInputFormat("n0","")
Hs=PickEntity("PICK HOLE")
Stat=SetPickMask(WsPickALL)
IF (ExitScript(Destination$)) THEN Leave

Tool= GetAssocTool(Hs)
IF NOT ValidGeometry(Tool) THEN Start

Stat= GetUserDataName(Tool,Tool_name$)
Stat=GetUserString(Tool,"Tool type:",Toolid$)
Cutter_dia=GetUserValue(Tool,"Diameter:")


CALL DefineTool(Tool_name$,Toolid$)

P1= ParameterPt(Hs,1.0)
P2= ParameterPt(Hs,0.0)
Axis_line= LineTwoPoints(P1,P2)
Smooth= WsTrue
Path1= CutterSolid(Axis_line,Smooth)

Stat= DeleteEntity(P1)
Stat= DeleteEntity(P2)
Stat= DeleteEntity(Axis_line)

ActivateUndo
Stat= AdvanceUndoNumber("revolution")
Stat= AddItemToUndo(WsUBCreateMode,C1)
GOTO Start

Leave:!
Stat=SetPickMask(WsPickALL)
Stat= DeleteEntity(P1)
Stat= DeleteEntity(P2)
Stat= DeleteEntity(Axis_line)
Stat=SetInputFormat("n4","")
IF (NOT LEN(Destination$)) THEN
	  LOAD "typecontrol"
ELSE
	  LOAD Destination$
END IF
END

SUB DefineTool(Name$,Toolid$)

Tool=FindUserData(Name$,WsToolData)
IF NOT ValidGeometry(Tool) THEN 
	Mach_def$= ""
	SUBEXIT
END IF

Tip_angle=0
Taper= 0
Corner_chamfer=0
Crad=0
Shank_dia=0
D3=0
D4=0

Tdia=GetUserValue(Tool,"Diameter:")
Flute_length=GetUserValue(Tool,"Flute length:")
Total_length=GetUserValue(Tool,"Tip to holder:")

SELECT Toolid$
CASE "DRILL"
	Cutter_type= WsDrill
        Tip_angle=GetUserValue(Tool,"Point angle:")
	Shank_dia=GetUserValue(Tool,"Shank diameter:")
CASE "CENTER DRILL"
	Cutter_type= WsCenterDrill
        Tip_angle=GetUserValue(Tool,"Point angle:")
        Shank_dia=GetUserValue(Tool,"Body diameter:")
	Taper= 90- Tip_angle/2
CASE "TWIST DRILL"
	Cutter_type= WsTwistDrill
        Tip_angle=GetUserValue(Tool,"Point angle:")
	Shank_dia=GetUserValue(Tool,"Shank diameter:")
CASE "TAPERED DRILL"
	Cutter_type= WsTaperedDrill
        Tip_angle=GetUserValue(Tool,"Point angle:")
	Shank_dia=GetUserValue(Tool,"Shank diameter:")
	Taper=GetUserValue(Tool,"Taper angle:")
CASE "COUNTER SINK"
	Cutter_type= WsCounterSink
        Tip_angle=GetUserValue(Tool,"Point angle:")
	Overall_len=GetUserValue(Tool,"Overall length:")
        Shank_len=GetUserValue(Tool,"Shank length:")
        Shank_dia=GetUserValue(Tool,"Shank diameter:")
        Flute_length=Overall_len-Shank_len
CASE "COUNTERBORE"
	Cutter_type= WsCounterBore
	Crad=GetUserValue(Tool,"Corner radius:")
	Shank_dia=GetUserValue(Tool,"Shank diameter:")
        Pilot_dia=GetUserValue(Tool,"Pilot diameter:")
        Pilot_len=GetUserValue(Tool,"Pilot length:")
	D3= Pilot_dia
	D4= Pilot_len
CASE "TAP"
	Cutter_type= WsTap
	Thread_len=GetUserValue(Tool,"Thread length:")
        Shank_dia=GetUserValue(Tool,"Shank diameter:")
        Taper=0
	Tip_angle= 10
	Radius= 0.5*Tdia
	Crad= 0.5*Radius
	Flute_length= Thread_len
CASE "REAMER"
	Cutter_type= WsReamer
        Chamfer_length=GetUserValue(Tool,"Corner chamfer:")
        Shank_dia=GetUserValue(Tool,"Shank diameter:")
	Taper=10
	Radius= 0.5*Tdia
	Taper_length= 0.5*Radius
        Chamfer_angle=45
	Crad= Chamfer_length
	Tip_angle= Chamfer_angle
	D3= Taper_length
CASE "BALLMILL"
	Cutter_type= WsBallCutter
	Shank_dia=GetUserValue(Tool,"Shank diameter:")
CASE "BULLMILL"
	Cutter_type= WsBullmill
	Crad=GetUserValue(Tool,"Corner radius:")
	Shank_dia=GetUserValue(Tool,"Shank diameter:")
CASE "ENDMILL"
	Cutter_type= WsEndmill
	Shank_dia=GetUserValue(Tool,"Shank diameter:")
CASE "TAPERMILL"
	Cutter_type= WsTaperedEndmill
	Shank_dia=GetUserValue(Tool,"Shank diameter:")
	Taper=GetUserValue(Tool,"Taper angle:")
	Crad=GetUserValue(Tool,"Corner radius:")
CASE "CHAMFERMILL"
	Cutter_type= WsChamferTool
	Shank_dia=GetUserValue(Tool,"Shank diameter:")
	Radius= 0.5*Tdia
        Tip_radius=GetUserValue(Tool,"Tip diameter:")/2
	Chamfer_angle=GetUserValue(Tool,"Taper angle:")
	Chamfer_length= (Radius- Tip_radius)/TAN(Chamfer_angle)
	Crad= Chamfer_length
	Tip_angle= Chamfer_angle
CASE "THREADER"
	Cutter_type= WsThreadedMill
	Shank_dia=GetUserValue(Tool,"Shank diameter:")
	Flute_length=GetUserValue(Tool,"Thread length:")
CASE "BORING BAR"
	Cutter_type= WsBoringBar
        Crad=GetUserValue(Tool,"Corner radius:")
        Shank_dia=GetUserValue(Tool,"Shank diameter:")
END SELECT


Radius= 0.5*Tdia
Shank_radius= 0.5*Shank_dia
Stat=Setup3dCutter(Cutter_type,Radius,Crad,0.0,0.0,Taper,Flute_length,Tip_angle,Shank_radius,Total_length,D3,D4)


SUBEND
