
! script name: edit.d/editcurrmaterial
! topic: edit current material entity

!A
!A NAME:
!A
!A 	Edit Current Material Entity
!A
!A DESCRIPTION:
!A
!A	This script allows the user to edit the contents of 
!A	the current material entity.
!A
!# see also - htdocs/help.d/vdminfo.htm

Stat=ChangeLabelStr("ScriptNameStatus","Function: edit material entity")

DIM Destination$[256],Answer$[256]
DIM Data$[32000],Name$[256]
DIM Descr$[512],File$[512]
DIM Editor$[256]

File$= "tempdata"
Stat= NamedVarStr("file editor",WsSystemVars,"notepad.exe",Editor$)
Flip_file= NamedVarVal("flip crlf",WsSystemVars,0)

ActivateUndo
Start:!
Material=FindUserData("MATERIAL",WsMaterial)
IF NOT ValidGeometry(Material) THEN Leave

Stat= UserDataString(Material,Data$)

Stat= OutputString(File$,Data$,WsNewFile)
Stat=EditFile(Editor$,File$,Flip_file)

LowerSelectBox
Stat=SetInputFormat("a1",",R,C,")
Stat=GetValue("MATERIAL DATA: Replace, Cancel",Answer$)
IF ExitScript(Destination$) THEN Leave
IF Answer$= "R" THEN
	ActivateUndo
	Stat= AdvanceUndoNumber("edit material data")
	Stat= AddItemToUndo(WsUBModifyMode,Material)

	New_material= ReadUserData(WsMaterial,Name$,File$)
	Stat= UserDataString(New_material,Data$)
        Stat= ReplaceUserData(Material,Data$)
	Stat= DeleteEntity(New_material)
END IF
GOTO Leave

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