
! script name: vcontrol.d/moverecord
! var_topic: move VDM record in object.

!A
!A NAME:
!A
!A 	Move VDM Record in Object
!A
!A DESCRIPTION:
!A
!A 	This script will allow a VDM record to be moved.
!A
!B INSTRUCTIONS:
!B
!B 	PICK RECORD TO BE MOVED,   Number: Pick the VDM record to be moved.
!B
!B 		N - Enter N to allow the VDM record number to be entered.
!B
!B 	PICK VARIATIONAL OBJECT: Pick the VDM object, or enter the
!B 		name of the VDM object containing the record to be deleted.
!B 		NOTE: This question is only asked if a record number has been
!B 		entered in response to the previous question.
!B
!B 	RECORD # IN OBJECT:  object_name: Enter the VDM record number of the
!B 		selected VDM object.
!B
!B	PICK RECORD TO BE INSERTED BEFORE: Pick the record that the moved
!B		record is to be inserted before. This record may be specified
!B		by number.

Stat=ChangeLabelStr("ScriptNameStatus","Function: move variational record")

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

DeActivateUndo
Stat=LineNumberIncr(1)
Global_color=3
Local_color=4
Highlight_color=2

Start:!
Pick_record:!
Stat=SetInputFormat("a1",",N,")
E1=PickEntity("PICK RECORD TO BE MOVED,   Number",Answer$)
IF ExitScript(Destination$) THEN Leave
IF Answer$="N" THEN
	GOSUB Pick_object
Record_number1:!
	Stat=SetInputFormat("n0","")
	Rec_number=GetValue("RECORD # IN OBJECT: "&Object_name$&"   ")
	IF ExitScript(Destination$) THEN Leave
	Var_record=VObjectRecord(Var_object,Rec_number)
	IF NOT ValidGeometry(Var_record) THEN Record_number1
ELSE
	IF NOT ValidGeometry(E1) THEN Pick_record
	Var_record=VarRecordParent(E1)
	IF NOT ValidGeometry(Var_record) THEN Pick_record
	Var_object=VarObjectParent(E1)
	IF NOT ValidGeometry(Var_object) THEN Pick_record
END IF
Stat=Highlight(Var_record,Highlight_color,0)
Stat=VarObjectName(Var_object,Object_name$)

Pick_insert:!
Stat=SetInputFormat("a1",",N,")
E1=PickEntity("PICK RECORD TO BE INSERTED BEFORE, Number",Answer$)
IF ExitScript(Destination$) THEN Leave
IF Answer$="N" THEN
Record_number2:!
        Stat=SetInputFormat("n0","")
        Rec_number2=GetValue("RECORD # IN OBJECT: "&Object_name$&"   ")
        IF ExitScript(Destination$) THEN Leave
        Insert_record=VObjectRecord(Var_object,Rec_number2)
        IF NOT ValidGeometry(Insert_record) THEN Record_number2
ELSE
        IF NOT ValidGeometry(E1) THEN Pick_insert
        Insert_record=VarRecordParent(E1)
        IF NOT ValidGeometry(Insert_record) THEN Pick_insert
        Var_object2=VarObjectParent(E1)
        IF NOT ValidGeometry(Var_object2) THEN Pick_insert
	Stat=VarObjectName(Var_object2,Name$)
	IF Name$<> Object_name$ THEN Pick_insert
END IF
Stat=Highlight(Insert_record,Highlight_color,0)

Stat= MoveVarRecord(Var_record,Insert_record)

Stat=VarObjectName(Var_object,Name$)
IF NOT LEN(Name$) THEN Pick_record
Stat= CleanNonVarGrps
Close_object=0
Output_script=0
Stat= DisplayMessage("CALCULATING CHANGES")
Stat=OutputVarObject("tempscript",Name$,"vcontrol.d/moverecord",Close_object,Output_script)
IF Stat=1 THEN Pick_record

LOAD "tempscript"

GOTO Pick_record

Pick_object:!
Nobjects= EntityTypeCount(WsVarObjectEnt)
IF Nobjects=1 THEN
	Var_object= CurrentVarObject
	IF NOT ValidGeometry(Var_object) THEN Leave
ELSE
	Var_object=PickVarObject("PICK VARIATIONAL OBJECT")
	IF ExitScript(Destination$) THEN Leave
	IF NOT ValidGeometry(Var_object) THEN Pick_object
END IF
Stat=VarObjectName(Var_object,Object_name$)
Stat=Highlight(Var_object,Highlight_color,0)
RETURN

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

