
! script name: wsccommon.d/deleteentity
! var_topic: delete a single entity. 

!A
!A NAME: 
!A
!A 	Delete Entity. VARIATIONAL
!A
!A DESCRIPTION:
!A
!A 	This script allows a single element to be deleted.
!A
!B INSTRUCTIONS:
!B
!B 	PICK ELEMENT TO BE DELETED: Pick the element to be deleted.
!B
!B NOTES:
!B
!B 	This is a variational delete function. The delete operation becomes
!B 	part of the variational object. This function should only be used when
!B 	entities which are created variationally are no longer needed and there
!B 	presence in the variational program is not desireable. Normally extra
!B 	elements should just be hidden.
!B

stat=ChangeLabelStr("ScriptNameStatus","Function: delete entity ")

DIM Destination$[256]
DIM Answer$[256]
DIM Element$[256]

Var_object= CurrentVarObject
IF NOT ValidGeometry(Var_object) THEN
	Var_object=OpenVarObject("Program")
END IF
! Var_object= CheckVarObject
! IF (ExitScript(Destination$)) THEN Leave

ActivateUndo
Pick_entity:!

Element=PickEntity("PICK ELEMENT TO BE DELETED ")
IF (ExitScript(Destination$)) THEN Leave
IF NOT ValidGeometry(Element) THEN Pick_entity

Var_record=VarRecordParent(Element)
IF NOT ValidGeometry(Var_record) THEN 
	IF IsEntReferenced(Element) THEN Pick_entity
	ActivateUndo
	Stat= AdvanceUndoNumber("delete")
	Stat= AddItemToUndo(WsUBDeleteMode,Element)

	Stat=UnLink(Element)
	Stat=DeleteEntity(Element)
	GOTO Pick_entity
END IF
IF NOT ValidDependency(Element) THEN Pick_entity
Stat=EntityNameCheck(Element,Element$)

ActivateUndo
Stat= AdvanceUndoNumber("delete entity")
Stat= AddItemToUndo(WsUBDeleteMode,Element$)

RecordFunctionOn
Stat=RecordDescr("DELETE: Entity")
Stat=DeleteEntity(Element$)
RecordFunctionOff
Curr_record= CurrentVarRecord
CloseVarRecord

Stat= AddItemToUndo(WsUBCreateMode,Curr_record)
GOTO Pick_entity

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