
! script name: voffset.d/replacetool
! var_topic: replace variational tool reference

!A
!A NAME:
!A
!A 	Global Change Tool
!A
!A DESCRIPTION:
!A
!A 	This script changes tool references to a given tool
!A 	in all variational records in the current file.
!A
!B INSTRUCTIONS:
!B
!B 	TOOL TO BE REPLACED  Calculate: Select the tool to be
!B 		replaced or have it calculate the changes.
!B
!B 	REPLACEMENT TOOL: Select the replacement tool.
!B
!C NOTES:
!C
!C 	The tool reference is changed immediately when the replacement tool is
!C 	selected.  The changes must be calculated for them to affect the data
!C 	created by the variational program.  CANCEL cancels the script, but
!C 	does not cancel any changes that have been made.
!C
!# see also - htdocs/help.d/vdminfo.htm

Stat=ChangeLabelStr("ScriptNameStatus","Function: replace all tool references")

DIM Destination$[256]
DIM Answer$[256]
DIM Tool_name$[256]
DIM New_tool$[256]
DIM Datastr$[30000]

Stat=LineNumberIncr(1)
Start_obj=0
Highlight_color=2
Generation=1

DeActivateUndo
Start:!
Tool_refs:!
Datastr$= ""
Tool_group= UserDataGroup(WsToolData)
IF NOT ValidGeometry(Tool_group) THEN Leave
Number= GroupCount(Tool_group)
FOR I= 1 TO Number
Tool= GroupElement(Tool_group,I)
Stat=GetUserDataName(Tool,Tool_name$)
Is_used= IsNameReferenced(Tool_name$)
IF Is_used THEN
Datastr$= Datastr$&Tool_name$&","
END IF
NEXT I
Stat= DeleteEntity(Tool_group)


Stat=GeneralListBox("TOOLS IN USE","selected tool",Datastr$)
IF Stat THEN Leave
Tool_ques1:!
Stat=SetInputFormat("a99","")
Stat=GetValue("TOOL TO BE REPLACED,  Calculate ",Tool_name$)
IF ExitScript(Destination$) THEN Leave
IF Tool_name$= "CANCEL" THEN Leave
IF Tool_name$= "C" OR Tool_name$= "c" THEN Calculate
IF POS(Tool_name$,"alculate")>0 THEN Calculate
Tool=FindUserData(Tool_name$,WsToolData)
IF NOT ValidGeometry(Tool) THEN Tool_ques1
Stat=ShowDependency(Tool_name$,Generation,Highlight_color)

Stat=ToolSelectBox("TOOLS","selected tool")
IF Stat THEN 
  Stat= MessageFileBox("/usr/weber/database/messages/notoolsloaded","ATTENTION")
  GOTO Leave
END IF
Tool_ques2:!
Stat=SetInputFormat("a99","")
Stat=GetValue("REPLACEMENT TOOL",New_tool$)
IF ExitScript(Destination$) THEN Leave
IF New_tool$= "CANCEL" THEN Leave
LowerSelectBox
Tool=FindUserData(New_tool$,WsToolData)
IF NOT ValidGeometry(Tool) THEN Tool_ques2


Stat= ChangeVarNameRef(Tool_name$,New_tool$,WsFalse)

Start_obj1=FirstVariableRef(New_tool$)
IF Start_obj>0 THEN
	Start_obj= MIN(Start_obj1,Start_obj)
ELSE
	Start_obj= Start_obj1
END IF
GOTO Start

Calculate:!
LowerSelectBox
Output_script=0
Stat= DisplayMessage("CALCULATING CHANGES")
Stat=OutputAllObjects("tempscript","voffset.d/replacetool",Start_obj,Output_script)
IF Stat=1 THEN Start

LOAD "tempscript"


Leave:!
Stat= DeleteEntity(Tool_group)
LowerSelectBox
IF NOT LEN(Destination$) THEN
	LOAD "typecontrol"
ELSE
	LOAD Destination$
END IF
END
