
! script name: vpoints.d/centerpt
! var_topic: create point at centerpt of an element

!A
!A NAME:
!A
!A 	point at centerpt -- VARIATIONAL
!A
!A DESCRIPTION:
!A
!A 	This script creates a point at the centerpt of an element.
!A
!B INSTRUCTIONS:
!B
!B 	PICK ENTITY: Pick the element that
!B 		is to be used to determine the point location.
!B

stat=ChangeLabelStr("ScriptNameStatus","Function: centerpt ")

DIM Answer$[256]
DIM Destination$[256]
DIM Name1$[256]
DIM Name$[256]


DEG
Var_object= CheckVarObject
IF (ExitScript(Destination$)) THEN Leave


ActivateUndo
Pick_loop:E1=PickEntity("PICK ENTITY")
IF (ExitScript(Destination$)) THEN Leave
IF NOT ValidGeometry(E1) THEN Pick_loop
IF NOT ValidDependency(E1) THEN Pick_loop
Stat= EntityNameCheck(E1,Name1$)

Etype= EntityType(E1)
SELECT Etype
CASE WsCircleEnt
	Stat= GenerateVarName(WsPointEnt,Name$)
	RecordFunctionOn
	Stat= RecordDescr("POINT: Circle center")
	Stat= SetRecDelLastExec
	Pt= CircleCenter(Name1$)
	Stat= NameEntity(Pt,Name$)
	RecordFunctionOff
	Curr_record= CurrentVarRecord
	CloseVarRecord
	Stat=SetLastPoint(Pt,WsXyzInput)

	ActivateUndo
	Stat= AdvanceUndoNumber("point")
	Stat= AddItemToUndo(WsUBCreateMode,Pt)
	Stat= AddItemToUndo(WsUBCreateMode,Curr_record)

CASE WsEllipse
	Stat= GenerateVarName(WsPointEnt,Name$)
	RecordFunctionOn
	Stat= RecordDescr("POINT: Ellipse center")
	Stat= SetRecDelLastExec
        Pt= EllipseCenter(Name1$)
        Stat= NameEntity(Pt,Name$)
        RecordFunctionOff
	Curr_record= CurrentVarRecord
        CloseVarRecord
	Stat=SetLastPoint(Pt,WsXyzInput)

	ActivateUndo
	Stat= AdvanceUndoNumber("point")
	Stat= AddItemToUndo(WsUBCreateMode,Pt)
	Stat= AddItemToUndo(WsUBCreateMode,Curr_record)

CASE ELSE
	Stat= GenerateVarName(WsPointEnt,Name$)
	RecordFunctionOn
	Stat= RecordDescr("POINT: Midpoint")
	Stat= SetRecDelLastExec
	Pt= ParameterPt(Name1$,0.5)
	Stat= NameEntity(Pt,Name$)
	RecordFunctionOff
	Curr_record= CurrentVarRecord
	CloseVarRecord
	Stat=SetLastPoint(Pt,WsXyzInput)

	ActivateUndo
	Stat= AdvanceUndoNumber("point")
	Stat= AddItemToUndo(WsUBCreateMode,Pt)
	Stat= AddItemToUndo(WsUBCreateMode,Curr_record)
END SELECT

Stat= PlotEntity(Name$)
Stat= PlotEntity(Name1$)
GOTO Pick_loop

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


