
! script name: vpoints.d/centroid
! var_topic: create point at centroid of a contour

!A
!A NAME:
!A
!A 	Centroid of a Contour	VARIATIONAL
!A
!A DESCRIPTION:
!A
!A 	This script creates a point at the centroid of a contour.
!A
!A
!B INSTRUCTIONS:
!B
!B 	PICK AN ELEMENT OF CONTOUR: Pick an element on the contour.
!B
!B

stat=ChangeLabelStr("ScriptNameStatus","Function: centroid of contour ")

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

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

ActivateUndo
Pick_contour:!
Stat= SetInputFormat("n4","")
Contour=PickGroupEnt("PICK CONTOUR ")
IF (ExitScript(Destination$)) THEN Leave
IF (NOT ValidDependency(Contour)) THEN Pick_contour
Stat= EntityNameCheck(Contour,Contour$)

Stat=Highlight(Contour,WsPickPen,WsDirArrowOff)


Stat= GenerateVarName(WsPointEnt,Name$)
RecordFunctionOn
Stat= RecordDescr("POINT: centroid of contour")
Stat= SetRecDelLastExec
Pc=Centroid(Contour$)
Stat= NameEntity(Pc,Name$)
RecordFunctionOff
Curr_record= CurrentVarRecord
CloseVarRecord

Stat= PlotEntity(Name$)
Stat= PlotEntity(Contour$)
IF NOT ValidGeometry(Pc) THEN
	DelLastVarRecord
ELSE
ActivateUndo
	Stat= AdvanceUndoNumber("centroid")
	Stat= AddItemToUndo(WsUBCreateMode,L1)
	Stat= AddItemToUndo(WsUBCreateMode,Curr_record)
END IF
GOTO Pick_contour

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

