
! script name: vdatatable.d/tpartvolume
! var_topic: insert the volume of a part into a table

!A
!A NAME:
!A
!A 	Tables: Volume		VARIATIONAL
!A
!A DESCRIPTION:
!A
!A	This script will insert the volume of a part into a table.
!A
!B INSTRUCTIONS:
!B
!B 	PICK SURFACE GROUP: Pick the surface group that will have its
!B 		volume calculated and inserted into the table.
!B
!B 	PICK TABLE LOCATION POINT: Pick the row in the table for the
!B 		volume of the part to be inserted.
!B
!# see also - htdocs/help.d/datatables.htm

stat=ChangeLabelStr("ScriptNameStatus","Function: volume table")

DIM Answer$[256]
DIM Name$[256]
DIM Descr$[256]
DIM Element$[256]
DIM Table$[256]
DIM Destination$[256]
DIM Format$[15]
DIM Group_name$[256]
DIM Center$[256]
DEG

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

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

Entry_color= 22
Entry_text_height= GetDefault(WsTextHeight)
Entry_text_width= GetDefault(WsTextWidth)

Tol=NamedVarVal("3D Volume Tol",Ws3DSystemVars,0.040)

ActivateUndo
Start:!

Pick_loop:Stat=SetInputFormat("n4","")
Stat= SetPickMask(WsPickSurfOnly)
stat= SetInputFormat("n4","")
Group=PickGroupEnt("PICK SURFACE GROUP",WsSurfaceGroup)
IF (ExitScript(Destination$)) THEN Leave
IF NOT ValidDependency(Group) THEN Pick_loop
Stat= GroupName(Group,Group_name$)

Stat= SetPickMask(WsPickAll)
Pick_point:Stat=SetInputFormat("n4","")
E1=PickEntity("PICK TABLE LOCATION POINT")
IF (ExitScript(Destination$)) THEN Leave
IF NOT ValidDependency(E1) THEN Pick_point
Stat= EntityNameCheck(E1,Center$)
T= LastPickPara
Pick_return= CurrPickReturn

Stat= GenerateVarName(WsDataTableEnt,Name$)
RecordFunctionOn
Stat= RecordDescr("TABLE: Part Volume")
SELECT Pick_return
CASE WsGeometryEnd
        Pc= ParameterReturnPt(Center$,T,WsGeometryEnd)
CASE WsGeometryMid
        Pc= ParameterReturnPt(Center$,T,WsGeometryMid)
CASE WsGeomCenter
        Pc= ParameterReturnPt(Center$,T,WsGeomCenter)
END SELECT
V1= FreeParameter("Tolerance",Tol)
Group1= FindNamedGrp(Group_name$)
G1=PartVolume(Group1,V1)
Pt= GroupElement(G1,1)
Center= GroupElement(G1,2)
Table1= CreateBlankTable(Pc,"",5,2,WsUpperLeft,"        ")
Stat= InsertIntoTable(Table1,"Volume",1,1)
Stat= InsertIntoTable(Table1,"Surface Area",2,1)
Stat= InsertIntoTable(Table1,"X centroid",3,1)
Stat= InsertIntoTable(Table1,"Y centroid",4,1)
Stat= InsertIntoTable(Table1,"Z centroid",5,1)
Stat= InsertIntoTable(Table1,XPointValue(Pt),Format$,1,2)
Stat= InsertIntoTable(Table1,YPointValue(Pt),Format$,2,2)
Stat= InsertIntoTable(Table1,XPointValue(Center),Format$,3,2)
Stat= InsertIntoTable(Table1,YPointValue(Center),Format$,4,2)
Stat= InsertIntoTable(Table1,ZPointValue(Center),Format$,5,2)
Stat= TableTextOrigin(Table1,0,2,WsRightCenter)
Stat= TableTextOrigin(Table1,0,1,WsLeftCenter)
V1= FreeParameter("Entry_color",Entry_color)
V2= FreeParameter("Text_height",Entry_text_height)
V3= FreeParameter("Text_width",Entry_text_width)
V4= FreeParameter("Text_slant",0.0)
Stat= SetTableColors(Table1,V1)
Stat= TableTextSizes(Table1,V3,V2,V4)
Stat= DeleteEntity(Pc)
stat= DeleteGroup(G1,WsTrue)
Stat= NameEntity(Table1,Name$)
RecordFunctionOff
Curr_record= CurrentVarRecord
CloseVarRecord
Stat= PlotEntity(Table1)

ActivateUndo
Stat= AdvanceUndoNumber("part volume")
Stat= AddItemToUndo(WsUBCreateMode,Table1)
Stat= AddItemToUndo(WsUBCreateMode,Curr_record)
GOTO Start


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