
! script name: interrogate.d/3dfilletcir
! topic: interrogate radius on a 3d fillet surface

!A
!A NAME:
!A
!A 	Interrogate: 3D Fillet Radius
!A
!A DESCRIPTION:
!A
!A 	This script finds the radius of a circle contained in
!A	a 3d fillet surface.
!A
!B INSTRUCTIONS:
!B
!B 	PICK ELEMENT: Pick the surface to be interrogated.
!B

stat=ChangeLabelStr("ScriptNameStatus","Function: interrogate fillet radius ")

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


File$= "tempdata"
Stat= RemoveFile(File$)

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

UVPoint=LastUVSurfPick(Element)
IF NOT ValidGeometry(UVPoint) THEN I_loop
U=XPointValue(UVPoint)
V=YPointValue(UVPoint)

U= XPointValue(UVPoint)
V= YPointValue(UVPoint)
Stat= DeleteEntity(UVPoint)

UorV=1
Circle_type=3
Etype= EntityType(Element)
SELECT Etype
CASE WsRuledSurfEnt,WsTranslationEnt
	UorV=1
	Circle_type=1
CASE WsRevolutionEnt
	UorV=0
	Circle_type=1
CASE WsNurbSurfEnt
Nurb_uindex= NurbInfo(Element,1)
Nurb_vindex= NurbInfo(Element,3)
IF Nurb_uindex=1 THEN
	UorV=0
        Circle_type=1
ELSE
	IF Nurb_vindex=1 THEN
		UorV=1
        	Circle_type=1
	ELSE
		UorV=1
		Circle_type=3
	END IF

END IF
	UorV=1
	Circle_type=3
END SELECT

Cent= SurfFlowCircle(Element,U,V,UorV,Circle_type)
IF NOT ValidGeometry(Cent) THEN 
	IF Circle_type= 3 THEN
		UorV=0
		Circle_type=4
		Cent= SurfFlowCircle(Element,U,V,UorV,Circle_type)
		IF NOT ValidGeometry(Cent) THEN I_loop
	END IF
END IF
IF NOT ValidGeometry(Cent) THEN I_loop

Radius= CircleRadius(Cent)
Pc= CircleCenter(Cent)
Ps= ParameterPt(Cent,0.5)
L1=LineTwoPoints(Pc,Ps,WsTRIMMED)
PlotOff
Stat= DeleteEntity(Cent)
Stat= DeleteEntity(Pc)
Stat= DeleteEntity(Ps)
Stat= DeleteEntity(L1)
PlotOn

Title$= "FILLET SURFACE RADIUS"
stat= OutputString(File$,CHR$(10),WsNewFile)
OUTPUT A$ USING "9A,8D.6D"; "RADIUS = ",ABS(Radius)
stat= OutputString(File$,A$&CHR$(10),WsAppend)

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

GOTO I_loop

Leave:!
Stat=SetPickMask(WsPickAll)
stat= DeleteEntity(Cent)
stat= DeleteEntity(UVPoint)
IF (NOT LEN(Destination$)) THEN
	 LOAD "typecontrol"
ELSE
	 LOAD Destination$
END IF
END
