
! script name: interrogate.d/partmaxmin
! topic: calculate max min limits for a 3D part relative to workplane.

!A
!A NAME:
!A
!A 	3D PART MAX MIN
!A
!A DESCRIPTION:
!A
!A 	This script calculates the maximum and minimum limits of a 3D part.
!A
!B INSTRUCTIONS:
!B
!B 	PICK SURFACE GROUP: Pick the surface group defining the part.
!B
!C NOTES:
!C
!C 	The tolerance used is the tolerance of the approximation
!C 	to the surfaces used to calculate the limits.
!C

stat=ChangeLabelStr("ScriptNameStatus","Function: 3D part max min ")

DIM Destination$[256]
DIM Answer$[256]
DIM A$[256]
DIM Title$[256]
DIM File$[256]
DIM Name$[256]


File$= "tempdata"
Stat= RemoveFile(File$)
Tol=NamedVarVal("3D Part Limits Tol",Ws3DSystemVars,0.040)

Start:!

Pick_loop:!
ActivateUndo

Stat= SetPickMask(WsPickSurfOnly)
stat= SetInputFormat("n4","")
Part_group=PickGroupEnt("PICK SURFACE GROUP",WsSurfaceGroup)
IF (ExitScript(Destination$)) THEN Leave
IF NOT ValidGeometry(Part_group) THEN Pick_loop

L1=PartMaxMinLimits(Part_group,Tol)
IF NOT ValidGeometry(L1) THEN Pick_loop

Stat= ParameterPtXYZ(L1,Xmin,Ymin,Zmin,0)
Stat= ParameterPtXYZ(L1,Xmax,Ymax,Zmax,1)

Stat= DeleteEntity(L1)


Title$= "PART LIMITS"
stat= OutputString(File$,CHR$(10),WsNewFile)

stat= OutputString(File$,"PART MINIMUM:"&CHR$(10),WsAppend)
OUTPUT A$ USING "3(5A,8D.6D)"; " Xmin = ",Xmin," Ymin = ",Ymin," Zmin = ",Zmin
stat= OutputString(File$,A$&CHR$(10),WsAppend)

stat= OutputString(File$,"PART MAXIMUM:"&CHR$(10),WsAppend)
OUTPUT A$ USING "3(5A,8D.6D)"; " Xmax = ",Xmax," Ymax = ",Ymax," Zmax = ",Zmax
stat= OutputString(File$,A$&CHR$(10),WsAppend)

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


GOTO Start

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