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

!A
!A NAME:
!A
!A 	3D Surface limit points	VARIATIONAL
!A
!A DESCRIPTION:
!A
!A 	This script makes two points from a  surface.
!A	One point is at xmin,ymin,zmin of the surface 
!A	The other  point is at xmax,ymax,zmax of the surface 
!A
!B INSTRUCTIONS:
!B
!B 	PICK SURFACE : Pick the surface.
!B

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

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

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

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

ActivateUndo
Start:!

Pick_loop:!

Stat= SetPickMask(WsPickSurfOnly)
stat= SetInputFormat("n4","")
Surface=PickEntity("PICK SURFACE ")
IF (ExitScript(Destination$)) THEN Leave
IF NOT ValidDependency(Surface) THEN Pick_loop
Stat= EntityNameCheck(Surface,Surface$)


Stat= GenerateVarName(WsPointEnt,Name1$)
Stat= GenerateVarName(WsPointEnt,Name2$)
RecordFunctionOn
Stat= RecordDescr("POINT: Surface limit points")
Stat= SetRecDelLastExec
Stat= NullReference(Surface$)
V1= FreeParameter("Tolerance",Tol)
L1=PartMaxMinLimits(Surface$,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("limit points")
	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
END
