
! script name: parasolids.d/pkinterrogate
! topic: general interrogation

!A
!A NAME:
!A
!A 	General
!A
!A DESCRIPTION:
!A
!A 	This script is for parasolid interrogation.  The information
!A 	pertaining to a particular element will be displayed in an
!A 	information box.  Points, Holes, Lines, Circles, Ellipses,
!A 	Cubic Splines, and Nurbs are examples of items that may be
!A 	interrogated. The following are some examples of different
!A 	types of info boxes that will be displayed:
!A
!A 	   LINE INFO			CIRCLE INFO
!A 		LINE ANGLE			CIRCLE RADIUS
!A 		LINE LENGTH			STARTING ANGLE
!A 		START POINT			ANGLE
!A 		END POINT			ARC LENGTH
!A 		LAYER				CIRCLE CENTER
!A 		COLOR				START POINT
!A						END POINT
!A 	   NURB INFO				LAYER
!A 		ARC LENGTH			COLOR
!A 		START POINT
!A 		END POINT
!A 		LAYER
!A 		COLOR
!A
!B INSTRUCTIONS:
!B
!B 	PICK ELEMENT: Pick the element to be interrogated.
!B
!# see also - htdocs/help.d/parasolids.htm

! SUBROUTINES:
! 	SUB FileNumData - Outputs data and a label to the output file.
! 	SUB OutputSolidCtr - Output the XYZ Center of a quadric surface.
! 	SUB OutputEntValue - Same as FileNumData but with the pass value
! 				to the function EntityValue.
! 	SUB OutputPtData - Output XYZ values of a point to the output file.

stat=ChangeLabelStr("ScriptNameStatus","Function: general ")

DIM Destination$[256]
DIM Answer$[256]
DIM File$[256]
DIM A$[32000]
DIM B$[32000]
DIM Title$[256]
DIM Name$[256]
DIM Ent_name$[256]

IF ARGC<2 THEN
        Real_space= 0
ELSE
        Real_space= VAL(ARGV(1))
END IF

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

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

I_loop:!
PlotOn
ActivateUndo
Pkent=WPKPickEntity("PICK ENTITY ")
IF (ExitScript(Destination$)) THEN Leave
IF NOT WPKIsEntity(Pkent) THEN I_loop

PlotOff
Group= WPKConvertEntity(Pkent)
IF NOT ValidGeometry(Group) THEN I_loop
Element= GroupElement(Group,1)
Etype= EntityType(Element)

Title$= "GENERAL INFO"
stat= OutputString(File$,CHR$(10),WsNewFile)

OUTPUT A$ USING "17A,9D";"PARASOLID TAG #: ",WPKEntityTag(Pkent)
stat= OutputString(File$,A$&CHR$(10),WsAppend)

SELECT EType
CASE WsPointEnt
	Title$= "POINT INFO"
CASE WsLineEnt
	Title$= "LINE INFO"
	Angle= LineAngle(Element)
	Length= LineLength(Element)

	Ps= ParameterPt(Element,0.0)
	Pe= ParameterPt(Element,1.0)

	Stat= XYZPointValues(Ps,X1,Y1,Z1)
	Stat= XYZPointValues(Pe,X2,Y2,Z2)

	FileNumData(File$,"16A,6D.6D","LINE ANGLE = : ",Angle)
	FileNumData(File$,"16A,6D.6D","LINE LENGTH = : ",Length)

	OUTPUT A$ USING "3(5A,6D.6D)"; " DX= ",X2-X1," DY= ",Y2-Y1," DZ= ",Z2-Z1
        stat= OutputString(File$,A$&CHR$(10),WsAppend)

	stat= DeleteEntity(Ps)
	stat= DeleteEntity(Pe)

CASE WsCircleEnt
	Title$= "CIRCLE INFO"
	Radius= CircleRadius(Element)
	Pc= CircleCenter(Element)

	OUTPUT A$ USING "16A,6D.5D,16A,6D.5D"; "CIRCLE RADIUS=: ",Radius,"     DIAMETER=: ",2*Radius
	Stat= OutputString(File$,A$&CHR$(10),WsAppend)
	OutputEntVal(File$,Element,"16A,6D.6D","START ANGLE = : ",WsStartAngle)
	OutputEntVal(File$,Element,"16A,6D.6D","ANGLE = : ",WsAngleExtent)
	GOSUB OutputArcLength

	Stat= OutputString(File$,CHR$(10),WsAppend)
	OutputPtData(File$,"CIRCLE CENTER:",Pc)

	Stat= DeleteEntity(Pc)
CASE WsEllipseEnt
	Title$= "ELLIPSE INFO"
	Pc= EllipseCenter(Element)

	OutputEntVal(File$,Element,"16A,6D.6D","MAJOR AXIS = : ",WsEllipseA)
	OutputEntVal(File$,Element,"16A,6D.6D","MINOR AXIS = : ",WsEllipseB)
	OutputEntVal(File$,Element,"16A,6D.6D","START ANGLE = : ",WsStartAngle)
	OutputEntVal(File$,Element,"16A,6D.6D","ANGLE = : ",WsAngleExtent)
	GOSUB OutputArcLength

        Stat= OutputString(File$,CHR$(10),WsAppend)
	OutputPtData(File$,"ELLIPSE CENTER:",Pc)

        Stat= DeleteEntity(Pc)
CASE WsBSplineEnt
	Title$= "NURB INFO"
	Nurb_form= NurbInfo(Element,0)
	Nurb_index= NurbInfo(Element,1)
	Nurb_deg= NurbInfo(Element,2)
	Answer$=""
	SELECT Nurb_form
	CASE 0
		Answer$= "GENERAL NURB CURVE"
	CASE 1
		Answer$= "LINE"
	CASE 2
		Answer$= "CIRCLE"
	CASE 3
		Answer$= "ELLIPSE"
	CASE 4
		Answer$= "PARABOLA"
	CASE 5
		Answer$= "HYPERBOLA"
	CASE 6
		Answer$= "CUBIC"
	CASE 7
		Answer$= "BEZIER"
	CASE 8
		Answer$= "SPECIAL"
	CASE ELSE
		Answer$= "UNKNOWN"
	END SELECT

	OUTPUT A$ USING "16A,20A"; "NURB FORM = : ",Answer$
	stat= OutputString(File$,A$&CHR$(10),WsAppend)
	FileNumData(File$,"16A,6D","NURB INDEX = : ",Nurb_index)
	FileNumData(File$,"16A,6D","NURB DEG = : ",Nurb_deg)
	GOSUB OutputArcLength

CASE WsPtChainEnt
        Title$= "POINTCHAIN INFO"
	GOSUB PtChainData

CASE WsNurbSurfEnt
	Title$= "NURB SURFACE INFO"
	GOSUB Print_trim
	Nurb_form= NurbInfo(Element,0)
        Nurb_uindex= NurbInfo(Element,1)
        Nurb_udeg= NurbInfo(Element,2)
        Nurb_vindex= NurbInfo(Element,3)
        Nurb_vdeg= NurbInfo(Element,4)

	SELECT Nurb_form
        CASE 0
                Answer$= "GENERAL NURB SURFACE"
        CASE 1
                Answer$= "BEZIER SURFACE"
        CASE 2
                Answer$= "SPECIAL NURB SURFACE"
        CASE 3
                Answer$= "NURB PLANE"
        CASE 4
                Answer$= "NURB DISK"
        CASE 5
                Answer$= "NURB CYLINDER"
        CASE 6
                Answer$= "NURB CONE"
        CASE 7
                Answer$= "NURB SPHERE"
        CASE 8
                Answer$= "NURB TORUS"
        CASE 9
                Answer$= "NURB REVOLUTION"
        CASE 10
                Answer$= "NURB TRANSLATION"
        CASE ELSE
                Answer$= "UNKNOWN FORM"
        END SELECT

        OUTPUT A$ USING "16A,20A"; "NURB FORM = : ",Answer$
	stat= OutputString(File$,A$&CHR$(10),WsAppend)

	FileNumData(File$,"16A,6D","NURB U INDEX = : ",Nurb_uindex)
	FileNumData(File$,"16A,6D","NURB V INDEX = : ",Nurb_vindex)
	FileNumData(File$,"16A,6D","NURB U DEG = : ",Nurb_udeg)
	FileNumData(File$,"16A,6D","NURB V DEG = : ",Nurb_vdeg)

CASE WsPlaneSolidEnt
	Title$= "PLANE SOLID INFO"
	GOSUB Print_trim
	XLength= SolidLength(Element,1)
	YLength= SolidLength(Element,2)
	FileNumData(File$,"16A,6D.6D","X LENGTH = : ",XLength)
	FileNumData(File$,"16A,6D.6D","Y LENGTH = : ",YLength)

CASE WsDiskSolidEnt
	Title$= "DISK SOLID INFO"
	GOSUB Print_trim
	Radius= SolidRadius(Element)
	FileNumData(File$,"16A,6D.6D","RADIUS = : ",Radius)
	OutputSolidCtr(File$,Element)

CASE WsCylSolidEnt
	Title$= "CYLINDER SOLID INFO"
	GOSUB Print_trim
	Radius= SolidRadius(Element)
	Length= SolidLength(Element)
	FileNumData(File$,"16A,6D.6D","RADIUS = : ",Radius)
	FileNumData(File$,"16A,6D.6D","LENGTH = : ",Length)
	OutputSolidCtr(File$,Element)

CASE WsConeSolidEnt
	Title$= "CONE SOLID INFO"
	GOSUB Print_trim
	Length= SolidLength(Element)
	Radius1= SolidRadius(Element,1)
	Radius2= SolidRadius(Element,2)
	FileNumData(File$,"16A,6D.6D","START RADIUS = : ",Radius1)
	FileNumData(File$,"16A,6D.6D","END RADIUS = : ",Radius2)
	FileNumData(File$,"16A,6D.6D","LENGTH = : ",Length)

	OutputSolidCtr(File$,Element)

CASE WsSphereSolidEnt
	Title$= "SPHERE SOLID INFO"
	GOSUB Print_trim
	Radius= SolidRadius(Element)
	XLength= SolidLength(Element,1)
        YLength= SolidLength(Element,2)
	FileNumData(File$,"16A,6D.6D","RADIUS = : ",Radius)
	FileNumData(File$,"16A,6D.6D","START LENGTH = : ",XLength)
	FileNumData(File$,"16A,6D.6D","END LENGTH = : ",YLength)
	OutputSolidCtr(File$,Element)

CASE WsTorusSolidEnt
	Title$= "TORUS SOLID INFO"
	GOSUB Print_trim
	R1= SolidRadius(Element,1)
	R2= SolidRadius(Element,2)
	FileNumData(File$,"16A,6D.6D","R1 = : ",R1)
	FileNumData(File$,"16A,6D.6D","R2 = : ",R2)
	OutputSolidCtr(File$,Element)

CASE WsTranslationEnt
	Title$= "TRANSLATION INFO"
	GOSUB Print_trim

CASE WsRevolutionEnt
	Title$= "REVOLUTION INFO"
	GOSUB Print_trim

CASE WsScaledSolidEnt
	Title$= "SCALED SOLID INFO"
	GOSUB Print_trim

CASE WsOffsetSurfEnt
	Title$= "OFFSET SURFACE INFO"
	GOSUB Print_trim
END SELECT


Startpoint_info:!
Ps= ParameterPt(Element,0)
OutputPtData(File$,"STARTPOINT:",Ps)
IF (Etype <> WsPointEnt) AND (Etype <> WsHoleEnt) THEN
        Pe= ParameterPt(Element,1)
        OutputPtData(File$,"ENDPOINT:",Pe)
        Stat= DeleteEntity(Pe)
END IF
Stat= DeleteEntity(Ps)
PlotOff
Stat= DeleteGroup(Group,WsTrue)
PlotOn


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

GOTO I_loop

Print_trim: N1= NumberTrimCurves(Element)
IF N1 > 0 THEN
OUTPUT A$ USING "(10A,8D,15A)"; "TRIMMED:   ",N1," CURVE"&RPT$("S",(N1>1))
stat= OutputString(File$,A$&CHR$(10),WsAppend)
END IF
RETURN

PtChainData: Num_points= PtChainSize(Element)
FileNumData(File$,"16A,6D","NUMBER POINTS = : ",Num_points)
GOSUB OutputArcLength
RETURN

OutputArcLength: Length= EntityLength(Element)
FileNumData(File$,"16A,6D.6D","ARC LENGTH = : ",Length)
RETURN

Leave:!
PlotOn
Stat= DeleteEntity(Ps)
Stat= DeleteGroup(Group,WsTrue)
IF Active_workplane THEN
        Stat=SetWorkplane(Work)
ELSE
        StdWorkplane
END IF
IF (NOT LEN(Destination$)) THEN
	 LOAD "typecontrol"
ELSE
	 LOAD Destination$
END IF
END

SUB FileNumData(File$,Format_$,Label$,Data_)
DIM A$[256]
	OUTPUT A$ USING Format_$; Label$,Data_
	Stat= OutputString(File$,A$&CHR$(10),WsAppend)
SUBEND

SUB OutputSolidCtr(File$,E1)
	L1= SolidAxis(E1)
	Pt= ParameterPt(L1,0.0)
	OutputPtData(File$,"CENTER POINT:",Pt)
	Stat= DeleteEntity(L1)
	Stat= DeleteEntity(pt)
SUBEND

SUB OutputPtData(File$,Label$,Pt)
DIM A$[256]
	Stat= XYZPointValues(Pt,X,Y,Z)
	Stat= OutputString(File$,Label$&CHR$(10),WsAppend)
	OUTPUT A$ USING "3(6A,6D.6D)"; "  X = ",X,"  Y = ",Y,"  Z = ",Z
        Stat= OutputString(File$,A$&CHR$(10),WsAppend)
SUBEND

SUB OutputEntVal(File$,E1,Format_$,Label$,Which)
	Value= EntityValue(E1,Which)
	FileNumData(File$,Format_$,Label$,Value)
SUBEND
