
! script name: v3dinter.d/partlimitpts
! var_topic: limit points for a 3D surface group

!A
!A NAME:
!A
!A	Part Limit Points	VARIATIONAL
!A
!A DESCRIPTION:
!A
!A	This script makes two points from a group of surfaces.
!A	One point is at xmin,ymin,zmin of the surface group
!A	The other  point is at xmax,ymax,zmax of the surface group
!A
!B INSTRUCTIONS:
!B
!B	PICK SURFACE GROUP: Pick the group of surfaces.
!B

stat=ChangeLabelStr("ScriptNameStatus","Function: part limit points ")

DIM Destination$[256]
DIM Answer$[256]
DIM Part_group$[256]
DIM Name1$[256]
DIM Name2$[256]

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

ActivateUndo
Tol=NamedVarVal("3D Part Limits Tol",Ws3DSystemVars,0.040)

Start:!

Pick_loop:!

Stat= SetPickMask(WsPickSurfOnly)
stat= SetInputFormat("n4a1",",N,")
Part_group=PickGroupEnt("PICK SURFACE GROUP  Name ",WsSurfaceGroup,Answer$)
IF (ExitScript(Destination$)) THEN Leave
IF Answer$="N" THEN
	GOSUB Get_named_group
END IF
IF NOT ValidDependency(Part_group) THEN Pick_loop
Stat= EntityNameCheck(Part_group,Part_group$)


Stat= GenerateVarName(WsPointEnt,Name1$)
Stat= GenerateVarName(WsPointEnt,Name2$)
RecordFunctionOn
Stat= RecordDescr("POINT: Part limit points")
Stat= SetRecDelLastExec
Stat= NullReference(Part_group$)
V1= FreeParameter("Tolerance",Tol)
L1=PartMaxMinLimits(Part_group$,V1)
P1= ParameterPt(L1,0.0)
P2= ParameterPt(L1,1.0)
Stat= DeleteEntity(L1)
Stat= NameEntity(P1,Name1$)
Stat= NameEntity(P2,Name2$)
RecordFunctionOff
Curr_record= CurrentVarRecord
CloseVarRecord
IF NOT ValidGeometry(P1) THEN
        DelLastVarRecord
ELSE
ActivateUndo
Stat= AdvanceUndoNumber("part limits")
Stat= AddItemToUndo(WsUBCreateMode,P1)
Stat= AddItemToUndo(WsUBCreateMode,P2)
Stat= AddItemToUndo(WsUBCreateMode,Curr_record)
END IF
GOTO Start


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

Get_named_group:!
Stat=ListGrpNames("SURFACE GROUPS","selected group","",WsSurfaceGroup)
IF Stat=1 THEN Leave_name
Stat=SetInputFormat("a99","")
Stat=GetValue("SURFACE GROUP NAME",Answer$)
IF (ExitScript(Destination$)) THEN Leave
IF Answer$="CANCEL" THEN Leave_name
Part_group=FindNamedGrp(Answer$)
IF NOT ValidGeometry(Part_group) THEN Get_named_group
Grp_type= GroupType(Part_group)
IF Grp_type <> WsSurfaceGroup THEN Get_named_group
LowerSelectBox
Leave_name:!
Stat=SetInputFormat("n4","")
RETURN

END
