 
! script name: amo.d/vautoamo
! var_topic: automate task list creation in AMO

!A
!A NAME:
!A
!A 	Auto		VARIATIONAL
!A
!A DESCRIPTION:
!A
!A 	Automated Add to Task List.
!A
!A	The selection order is controled by the Info Packet
!A		C:/usr/weber/database/TaskTemplates/autotasks.
!A	
!A~ image location - images/tasktable1.jpg
!A	If the tasks are not sorted the Amo Execute script will sort the
!A	tasks using the file listed in the amo_variables file of the
!A	post processor. By default it is the same as above.
!A

stat=ChangeLabelStr("ScriptNameStatus","Function: automated add to task list")

DIM Answer$[256],Destination$[256]
DIM Name$[256],Prop_dir$[512]

Task_ent= FindUserData("AMO OPERATIONS",WsTaskPacket)
IF ValidGeometry(Task_ent) THEN
	Stat= MessageStringBox("CANNOT CREATE A LIST USING THIS FUNCTION"&CHR$(10)&" A VARIATIONALLY SORTED TASK LIST ALREADY EXISTS.","INCORRECT USAGE ERROR")
	GOTO Leave
END IF

DeActivateUndo
G1= FindNamedGrp("AMO OPERATIONS")
IF ValidGeometry(G1) THEN
	IF ValidDependency(G1) THEN
		Stat= MessageFileBox("/usr/weber/database/messages/previousrun","ERROR")
		GOTO Leave
	ELSE
		Stat= MessageFileBox("/usr/weber/database/messages/run_in_non_VDM","ERROR")
		Stat= SetInputFormat("a1=",",Y,L,")
		Stat= SetEqualsValue(0,"Y")
		Stat= GetValue("Delete previous group  Yes or Leave ",Answer$)
		IF ExitScript(Destination$) THEN Leave
		IF Answer$= "Y" THEN Stat= DeleteEntity(G1)
		IF Answer$= "L" THEN Leave
	END IF
END IF

Var_object=CheckVarObject
IF ExitScript(Destination$) THEN Leave

Stat= NamedVarStr("properties dir",WsSystemVars,"/usr/weber/database/properties/",Prop_dir$)

Make_prop_record:!
RecordFunctionOn
Stat=RecordDescr("AMO: Auto sort mill tasks")
Stat=RemoveDupTools
V1= StringConstant(Prop_dir$)
V2= StringConstant("TaskTemplates")
V3= StringConstant("autotasks")
V4= StringConstant(FileNameString(V1,V2,V3))
V5= StringConstant("AMO OPERATIONS")
Group= AutoSortMillTasks(V4)
Stat= ChangeGrpName(Group,V5)
RecordFunctionOff
CloseVarRecord

IF NOT ValidGeometry(Group) THEN DelLastVarRecord

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

END
