
! script name: vtools.d/toolfeedspeed
! topic: edit tool feed and speed.

!A
!A NAME:
!A
!A 	Edit tool feed and speed.
!A
!A DESCRIPTION:
!A	The script will set the feed and speed for a tool and override
!A	the calculation done from the material data.
!A
!B INSTRUCTIONS:
!B
!B

stat=ChangeLabelStr("ScriptNameStatus","Function: tool feed and speed ")

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

ActivateUndo
Start:!
Units= CurrentUnits

Tool_question:!
No_tools=ToolSelectBox("TOOLS","selected tool")

IF Not_tools THEN Leave
Stat=SetInputFormat("a99","")
Stat=GetValue("CHOOSE TOOL",Answer$)
IF (ExitScript(Destination$)) THEN Leave
IF Answer$="CANCEL" THEN Leave
Name$=Answer$
LowerSelectBox

Tool=FindUserData(Name$,WsToolData)
IF NOT ValidGeometry(Tool) THEN Tool_question

IF Units= WsMetric THEN
	Toolstring$="Feed(mmpm):"
ELSE
	Toolstring$="Feed(ipm):"
END IF
Feed=GetUserValue(Tool,Toolstring$)
Stat=SetEqualsValue(Feed)

Stat=SetInputFormat("n5=","")
Feed=GetValue("FEED RATE",Answer$)
IF (ExitScript(Destination$)) THEN Leave

Toolstring$="Speed(rpm):"
Speed=GetUserValue(Tool,Toolstring$)
Stat=SetEqualsValue(Speed)

Stat=SetInputFormat("n0=","")
Speed=GetValue("SPINDLE SPEED",Answer$)
IF (ExitScript(Destination$)) THEN Leave

ActivateUndo
Stat= AdvanceUndoNumber("feed speed:"&Name$)
Stat= AddItemToUndo(WsUBModifyMode,Tool)

RecordFunctionOn
Stat= RecordDescr("Feed and Sspeed:"&Name$)
Tool=FindUserData(Name$,WsToolData)
RecordFunctionOff
IF Units= WsMetric THEN
RecordFunctionOn
V1= FreeParameter("Feed rate",Feed)
Stat=PutUserValue(Tool,"Feed(mmpm):",V1)
RecordFunctionOff
ELSE
RecordFunctionOn
V1= FreeParameter("Feed rate",Feed)
Stat=PutUserValue(Tool,"Feed(ipm):",V1)
RecordFunctionOff
END IF
RecordFunctionOn
V2= FreeParameter("Spindle speed",Speed)
Stat=PutUserValue(Tool,"Speed(rpm):",V2)
RecordFunctionOff
Curr_record= CurrentVarRecord
CloseVarRecord

Stat= AddItemToUndo(WsUBCreateMode,Curr_record)
GOTO Tool_question

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