
! script name: interrogate.d/pickpoint
! topic: interrogate pick point on entity

!A
!A NAME:
!A
!A 	Interrogate: Pick point
!A
!A DESCRIPTION:
!A
!A 	This script interrogates an element and will display the
!A 	coordinates of the pick point in the PICK POINT info box for viewing.
!A	Coordinates are displayed in Real XYZ Space.
!A
!B INSTRUCTIONS:
!B
!B 	PICK ELEMENT: Pick the element to be interrogated.
!B

stat=ChangeLabelStr("ScriptNameStatus","Function: interrogate pick point ")

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


File$= "tempdata"

Active_workplane=0
Work=CurrentWorkplane
IF ValidGeometry(Work) THEN Active_workplane=1
StdWorkplane

I_loop:!
ActivateUndo
Element=PickEntity("PICK ELEMENT")
IF (ExitScript(Destination$)) THEN Leave
IF (NOT ValidGeometry(Element)) THEN I_loop

Etype= EntityType(Element)
SELECT Etype
CASE WsLineEnt,WsPointEnt,WsHoleEnt,WsCircleEnt,WsEllipseEnt,WsCSplineEnt
	T= LastPickPara
	Ps= ParameterPt(Element,T)
CASE WsBSplineEnt,WsCSplineCurveEnt
	T= LastPickPara
	Ps= ParameterPt(Element,T)
CASE WsPtChainEnt,WsVectorChainEnt,WsBiVectorChainEnt
	T= LastPickPara
	Ps= ParameterPt(Element,T)
CASE WsRuledSurfEnt,WsCubicSurfEnt,WsNurbSurfEnt
	UVPoint=LastUVSurfPick(Element)
	IF NOT ValidGeometry(UVPoint) THEN I_loop
	U=XPointValue(UVPoint)
	V=YPointValue(UVPoint)
	Ps= SurfParameterPt(Element,U,V)
	Stat= DeleteEntity(UVPoint)
CASE WsPlaneSolidEnt,WsDiskSolidEnt,WsCylSolidEnt,WsConeSolidEnt,WsSphereSolidEnt,WsTorusSolidEnt
	UVPoint=LastUVSurfPick(Element)
	IF NOT ValidGeometry(UVPoint) THEN I_loop
	U=XPointValue(UVPoint)
	V=YPointValue(UVPoint)
	Ps= SurfParameterPt(Element,U,V)
	Stat= DeleteEntity(UVPoint)
CASE WsTranslationEnt,WsScaledSolidEnt,WsRevolutionEnt,WsOffsetSurfEnt
	UVPoint=LastUVSurfPick(Element)
	IF NOT ValidGeometry(UVPoint) THEN I_loop
	U=XPointValue(UVPoint)
	V=YPointValue(UVPoint)
	Ps= SurfParameterPt(Element,U,V)
	Stat= DeleteEntity(UVPoint)
CASE ELSE
	GOTO I_loop
END SELECT

Title$= "PICK POINT"
stat= OutputString(File$,CHR$(10),WsNewFile)
X= XPointValue(Ps)
Y= YPointValue(Ps)
Z= ZPointValue(Ps)
stat= OutputString(File$,"POINT:"&CHR$(10),WsAppend)
OUTPUT A$ USING "3(5A,6D.6D)"; "X = ",X,"Y = ",Y,"Z = ",Z
stat= OutputString(File$,A$&CHR$(10),WsAppend)
PlotOff
stat= DeleteEntity(Ps)
PlotOn

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

GOTO I_loop

Leave:!
stat= DeleteEntity(Ps)
stat= DeleteEntity(UVPoint)
IF Active_workplane THEN
        Stat=SetWorkplane(Work)
ELSE
        StdWorkplane
END IF
IF (NOT LEN(Destination$)) THEN
	 LOAD "typecontrol"
ELSE
	 LOAD Destination$
END IF
END
