
! script name: tableinsert.d/tcentroid
! topic: insert the centroid of a contour into a table

!A
!A NAME:
!A
!A 	Table: Info: Centroid
!A
!A DESCRIPTION:
!A
!A	Insert the centroid of a contour into a table
!A
!B INSTRUCTIONS:
!B
!B 	PICK CONTOUR: Pick the contour to have its centroid calculated
!B 		and entered in the selected position in the table.
!B
!B 	PICK ENTRY POSITION: Pick the position in the table for the
!B 		centroid of the contour to be entered.
!B
!B NOTES:
!B
!B 	This script is not variational. The table will not update
!B 	when the entity in changed.
!B

stat=ChangeLabelStr("ScriptNameStatus","Function: centroid into table")

DIM Answer$[256]
DIM Descr$[256]
DIM Destination$[256]
DIM Format$[15]
DEG

A= GetDefault(WsPlacesAfter)
Format$= "decimal "&VAL$(A)

Start:!
ActivateUndo
Stat= SetPickMask(WsPickNoSurf)
stat= SetInputFormat("n4","")
Pick_point:E1=PickEntity("PICK CONTOUR")
IF (ExitScript(Destination$)) THEN Leave
IF NOT ValidGeometry(E1) THEN Pick_start

Stat=Highlight(E1,WsPickPen,WsDirArrowOff)
Group= ParentGroup(E1,0)
IF NOT ValidGeometry(Group) THEN Pick_loop


Pick_entry:!
stat= SetInputFormat("n4","")
Table1=PickEntity("PICK ENTRY POSITION")
IF (ExitScript(Destination$)) THEN Leave
IF NOT ValidGeometry(Table1) THEN Pick_entry
T1= LastPickPara
R1=TableParaRow(Table1,T1)
C1=TableParaColumn(Table1,T1)
C2= C1+1
C3= C1+2

ActivateUndo
Stat= AdvanceUndoNumber("centroid entry")
Stat= AddItemToUndo(WsUBModifyMode,Table1)


Stat= EraseEntity(Table1)
Pt=Centroid(E1)
Stat= InsertIntoTable(Table1,XPointValue(Pt),Format$,R1,C1)
Stat= InsertIntoTable(Table1,YPointValue(Pt),Format$,R1,C2)
Stat= InsertIntoTable(Table1,ZPointValue(Pt),Format$,R1,C3)
Stat= TableTextOrigin(Table1,R1,C1,R1,C3,WsRightCenter)
Stat= DeleteEntity(Pt)
Stat= PlotEntity(Table1)

GOTO Start


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