
! script name: parasolids.d/pkextremedata
! solids: interrogate the extremes of a body

!A
!A NAME:
!A
!A 	Body Extreme Data
!A
!A DESCRIPTION:
!A
!A 	This script finds the extreme data on a parasolid body. 
!A 	It gives the Xmin, Xmax, Ymin,Ymax, Zmin,Zmax for a body
!A 	relative to the current workplane.
!A 	It also gives the Xlength,Ylength,Zlength of the body.
!A
!# see also - htdocs/help.d/parasolids.htm

stat=ChangeLabelStr("ScriptNameStatus","Function: extreme data ")

DIM Destination$[256]
DIM Answer$[256]
DIM File$[256]
DIM A$[32000]
DIM B$[32000]
DIM Title$[256]
DIM Name$[256]
DIM Label$[256]

ActivateUndo
Title$= "EXTREME DATA"
File$= "tempdata"
Stat= RemoveFile(File$)

Start:!
Pkbody= WPKCurrentBody
IF NOT WPKIsEntity(Pkbody) THEN
        Stat=SetInputFormat("n4","")
        E1=WPKPickEntity("PICK BODY")
        IF (ExitScript(Destination$)) THEN Leave
        IF NOT WPKIsEntity(E1) THEN Start
        Pkbody= WPKParentBody(E1)
END IF

P1= WPKExtremePoint(Pkbody,1)
P2= WPKExtremePoint(Pkbody,4)
Xmin= XPointValue(P2)
Xmax= XPointValue(P1)
Stat= DeleteEntityList(P1,P2)

P1= WPKExtremePoint(Pkbody,2)
P2= WPKExtremePoint(Pkbody,5)
Ymin= YPointValue(P2)
Ymax= YPointValue(P1)
Stat= DeleteEntityList(P1,P2)

P1= WPKExtremePoint(Pkbody,3)
P2= WPKExtremePoint(Pkbody,6)
Zmin= ZPointValue(P2)
Zmax= ZPointValue(P1)
Stat= DeleteEntityList(P1,P2)

body_type= WPKBodyType(Pkbody)
SELECT body_type
CASE WsPKSolidBody
	Btype$= "SOLID BODY"
CASE WsPKSheetBody
	Btype$= "SHEET BODY"
CASE WsPKWireBody
	Btype$= "WIRE BODY"
END SELECT

Label$= "BODY EXTREME VALUES"
Stat= OutputString(File$,Label$&CHR$(10),WsNewFile)
stat= OutputString(File$,Btype$&CHR$(10),WsAppend)
OUTPUT A$ USING "17A,9D";"PARASOLID TAG #: ",WPKEntityTag(Pkbody)
stat= OutputString(File$,A$&CHR$(10),WsAppend)

Stat= OutputString(File$,CHR$(10),WsAppend)
OUTPUT A$ USING "3(9A,6D.6D)"; "Xmin = ",Xmin,"  Ymin = ",Ymin,"  Zmin = ",Zmin
Stat= OutputString(File$,A$&CHR$(10),WsAppend)
OUTPUT A$ USING "3(9A,6D.6D)"; "Xmax = ",Xmax,"  Ymax = ",Ymax,"  Zmax = ",Zmax
Stat= OutputString(File$,A$&CHR$(10),WsAppend)
Stat= OutputString(File$,CHR$(10),WsAppend)
OUTPUT A$ USING "3(10A,6D.6D)"; "Xlength = ",Xmax-Xmin,"  Ylength = ",Ymax-Ymin,"  Zlength = ",Zmax-Zmin
Stat= OutputString(File$,A$&CHR$(10),WsAppend)
Stat= OutputString(File$,CHR$(10),WsAppend)
OUTPUT A$ USING "3(10A,6D.6D)"; "Xcenter = ",(Xmax+Xmin)/2,"  Ycenter = ",(Ymax+Ymin)/2,"  Zcenter = ",(Zmax+Zmin)/2
Stat= OutputString(File$,A$&CHR$(10),WsAppend)



Output_data:!
stat= OutputString(File$,CHR$(10),WsAppend)
Stat=MessageFileBox(File$,Title$)

Num1= WPKBodiesCount
IF Num1 > 1 THEN Start

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