
! script name: vpkintersect.d/vpkzextreme
! var_solids: find the z axis extreme pts on a solid body

!A
!A NAME:
!A
!A 	Z Axis Extreme Points  VARIATIONAL
!A
!A DESCRIPTION:
!A
!A 	This script finds the Z axis extreme points on a parasolid body
!A 	This is two points on the body which are at the Zmax and Zmin
!A 	positions on the body.	
!A
!# see also - htdocs/help.d/parasolids.htm

stat=ChangeLabelStr("ScriptNameStatus","Function: z axis extreme points ")

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

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

Start:!
Stat=SetInputFormat("a1",",G,E,")
E1=WPKPickEntity("PICK BODY,  Group, Entity ",WsPKPickAll,Answer$)
IF (ExitScript(Destination$)) THEN Leave
IF Answer$="G" THEN
Pick_group:!
	Stat=SetInputFormat("a1",",B,")
	E1=WPKPickEntity("PICK GROUP,  Body ",WsPKPickAll,Answer$)
	IF (ExitScript(Destination$)) THEN Leave
	IF Answer$="B" THEN Start
	IF NOT WPKIsEntity(E1) THEN Pick_loop

	Pkgroup= WPKContainingGroup(E1,1)
	IF NOT WPKIsEntity(Pkgroup) THEN Pick_group

	Stat= EntityNameCheck(Pkgroup,Body$)

	GOTO Make_record
END IF
IF Answer$="E" THEN
Pick_entity:!
        Stat=SetInputFormat("a1",",B,")
        E1=WPKPickEntity("PICK ENTITY,  Body ",WsPKPickAll,Answer$)
        IF (ExitScript(Destination$)) THEN Leave
        IF Answer$="B" THEN Start
        IF NOT WPKIsEntity(E1) THEN Pick_loop

        Stat= EntityNameCheck(E1,Body$)

        GOTO Make_record
END IF
IF NOT WPKIsEntity(E1) THEN Pick_loop
Pkbody= WPKParentBody(E1)
Stat= EntityNameCheck(Pkbody,Body$)


Make_record:!

WPKClearErrorFlag
Stat= GenerateVarName(WsPointEnt,Name1$)
Stat= GenerateVarName(WsPointEnt,Name2$)
RecordFunctionOn
Stat= RecordDescr("POINT: z axis extreme pts")
P1= WPKExtremePoint(Body$,3)
P2= WPKExtremePoint(Body$,6)
Stat= NameEntity(P1,Name1$)
Stat= NameEntity(P2,Name2$)
RecordFunctionOff
Curr_record= CurrentVarRecord
CloseVarRecord

IF ValidGeometry(P1) THEN
        Stat= WPKSolidRecordOn(Curr_record)
        ActivateUndo
        Stat= AdvanceUndoNumber("x axis extreme pts")
        Stat= AddItemToUndo(WsUBCreateMode,P1)
        Stat= AddItemToUndo(WsUBCreateMode,P2)
        Stat= AddItemToUndo(WsUBPKSessionMark)
        Stat= AddItemToUndo(WsUBCreateMode,Curr_record)
ELSE
        DelLastVarRecord
END IF
WPKErrorCheck
GOTO Start


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