
! script name: voffsets.d/chmillingtool
! var_topic: change milling tool

!A
!A NAME:
!A
!A 	Change Milling Tool	VARIATIONAL
!A
!A DESCRIPTION:
!A
!A 	This script changes a milling tool.
!A
!B INSTRUCTIONS:
!B
!B 	MILL CLimb OR Conventional:
!B
!B 		C - Conventional mill will generate a path which is
!B 		    clockwise for an interior cut and counterclockwise
!B 		    for an exterior cut.
!B 		CL - Climb mill will generate a path which is clockwise for
!B 		    an exterior cut and counterclockwise for an interior cut.
!B

stat=ChangeLabelStr("ScriptNameStatus","Function: change milling tool")

DIM Destination$[256]
DIM Answer$[256]
DIM Datastr$[1256]
DIM Boundary_name$[256]
DIM Tool_name$[256]
DIM Toolid$[256]
DIM Mach_def$[256]
DIM Contour$[256]
DIM Finish_var$[256]
DIM Depth_var$[256]
DIM Name$[256]


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


DeActivateUndo
Current_pen=CurrentColor

Start:!
Stat=ToolSelectBox("TOOLS","selected tool")
IF Stat THEN 
  Stat= MessageFileBox("/usr/weber/database/messages/notoolsloaded","ATTENTION")
  GOTO Leave
END IF
Tool_ques:!
Stat=SetInputFormat("a99","")
Stat=GetValue("NEW TOOL",Answer$)
IF (ExitScript(Destination$)) THEN Leave
IF Answer$= "CANCEL" THEN
		LowerSelectBox
		GOTO Leave
END IF
Tool_name$= Answer$
Tool=FindUserData(Answer$,WsToolData)

Stat=GetUserString(Tool,"Tool type:",Toolid$)
IF NOT POS(Toolid$, "MILL") THEN Tool_ques
Cutter_dia=GetUserValue(Tool,"Diameter:")
LowerSelectBox

Mill_direction:!
Stat=SetInputFormat("a2=",",CL,C,")
Stat=NamedVarStr("mill direction",WsSystemVars,"CL",Answer$)
Stat=SetEqualsValue(0,Answer$)
Mill_dir=GetValue("MILL CLimb OR Conventional",Answer$)
IF (ExitScript(Destination$)) THEN Leave
IF (Answer$="C") THEN
	Mill_dir=WsConventional
	Pen_color=WsConvCutPen
ELSE
	Mill_dir=WsClimb
	Pen_color=WsClimbCutPen
END IF
Stat=SetCurrentColor(Pen_color)


Pick_loop:!
Stat= SetInputFormat("n4","")
E1=PickEntity("PICK MILLING OPERATION TO BE CHANGED")
IF (ExitScript(Destination$)) THEN Leave
IF NOT ValidGeometry(E1) THEN Ploop


Mach_def= GetAssocMachDef(E1)
IF NOT ValidGeometry(Mach_def) THEN Pick_loop

Pen_color= CurrentColor
Stat=SetCurrentColor(Pen_color)
CALL ChangeMillTool(Mach_def,Tool_name$,Toolid$,Mill_dir)
Stat= ReadEntityName(Mach_def,Name$)

Stat=GeneralListBox(" "," ","  ,   ,   ")
Start_obj= FirstVariableRef(Name$)
Stat=LineNumberIncr(1)
Output_script=0
Stat= OutputAllObjects("tempscript","voffset.d/chmillingtool",Start_obj,Output_script)
IF Stat=1 THEN Leave

LOAD "tempscript"
GOTO Pick_loop

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

SUB ChangeMillTool(ENTITY Mach_def,Name$,Toolid$,REAL Mdir)

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

Tdia=GetUserValue(Tool,"Diameter:")

SELECT Toolid$
CASE "DRILL"
	Cutter_type= WsDrill
CASE "CENTER DRILL"
	Cutter_type= WsCenterDrill
CASE "TWIST DRILL"
	Cutter_type= WsTwistDrill
CASE "TAPERED DRILL"
	Cutter_type= WsTaperedDrill
CASE "COUNTER SINK"
	Cutter_type= WsCounterSink
CASE "COUNTER BORE"
	Cutter_type= WsCounterBore
CASE "TAP"
	Cutter_type= WsTap
CASE "REAMER"
	Cutter_type= WsReamer
CASE "BALLMILL"
	Cutter_type= WsBallCutter
CASE "BULLMILL"
	Cutter_type= WsBullmill
CASE "ENDMILL"
	Cutter_type= WsEndmill
CASE "TAPERMILL"
	Cutter_type= WsTaperedEndmill
CASE "BORING BAR"
	Cutter_type= WsBoringBar
END SELECT


Stat= MillDefCutterInfo(Mach_def,Cutter_type,Mdir,Tdia)
Stat=AssociateTool(Mach_def,Tool)
Group= GrpByMachDef(Mach_def)
IF ValidGeometry(Group) THEN
	Stat=AssociateTool(Group,Tool)
	Stat= DeleteEntity(Group)
END IF

SUBEND
