get data from Inquire Element

Creator
Creator

Hi all ,

 

I wondering whether there is a class which could read the data from 'Inquire Element' result .

For example ,if program detected a cylinder was selected ,and it could read and show its Radius,Diameter,Cone Height.

I will be very grateful if you have any experience to show me .

Cat HappyCat HappyCat Happy

 

图像 1.jpg

1 REPLY

Re: get data from Inquire Element

Genius
Genius

Hello MileyZhu,

 

I'll show you how I would do it without using mouse selection. If you want to use mouse selection, use the SolidEdgeFramework.Command and SolidEdgeFramework.Mouse objects.

In this example code, I will show how select by code and filter by type face. I'm not use the Inquire Element Command.

 

 

class Program
    {
        [STAThread]
        static void Main(string[] args)
        {
            // Declare your main variables
            SolidEdgeFramework.Application application = null;
            SolidEdgePart.PartDocument partDocument = null;

            // Geometry variables
            SolidEdgePart.Models models = null;
            SolidEdgePart.Model model = null;
            SolidEdgeGeometry.Body body = null;
            SolidEdgeGeometry.Faces faces = null;
            SolidEdgeGeometry.Face face = null;
            object faceGeometry = null;
            string topologyGeometry = null;

            // Types of faces
            SolidEdgeGeometry.Plane plane = null;
            SolidEdgeGeometry.Cylinder cylinder = null;
            SolidEdgeGeometry.Sphere sphere = null;
            SolidEdgeGeometry.Cone cone = null;
            SolidEdgeGeometry.Torus torus = null;

            // Dimensions to get by geometry, you use it for your tasks
            double area = 0.0;
            double radius = 0.0;
            double halfAngle = 0.0;
            double majorRadius = 0.0;
            double minorRadius = 0.0;
            Array axisVector = new double[3];
            Array basePoint = new double[3];
            Array centerPoint = new double[3];
            Array rootPoint = new double[3];
            Array normalVector = new double[3];
            bool expanding = false;
            try
            {
                // Register
                OleMessageFilter.Register();

                // Connect your Solid Edge
                application = SolidEdgeUtils.Connect(true);

                // Get active document
                partDocument = (PartDocument)application.ActiveDocument;

                // Get model
                models = partDocument.Models;
                model = models.Item(1);

                // Get faces
                body = (Body)model.Body;
                faces = (Faces)body.Faces[SolidEdgeGeometry.FeatureTopologyQueryTypeConstants.igQueryAll];
                face = (Face)faces.Item(1); // Get your face here

                // Get Area
                area = face.Area;

                // Get geometry face type
                faceGeometry = face.Geometry;
                topologyGeometry = SolidEdgeCommunity.Runtime.InteropServices.ComObject.GetType(faceGeometry).ToString();

                // Get dimensions, verify face type
                switch (topologyGeometry)
                {
                    case "SolidEdgeGeometry.Plane":
                        plane = (Plane)face.Geometry;
                        // Get plane dimensions
                        plane.GetPlaneData( 
                            ref rootPoint,
                            ref normalVector
                            );
                        break;

                    case "SolidEdgeGeometry.Cylinder":
                        cylinder = (Cylinder)face.Geometry;
                        // Get cylinder dimensions
                        cylinder.GetCylinderData(
                            ref basePoint,
                            ref axisVector,
                            out radius
                            );
                        break;

                    case "SolidEdgeGeometry.Sphere":
                        sphere = (Sphere)face.Geometry;
                        // Get sphere dimensions
                        sphere.GetSphereData(
                            ref centerPoint,
                            out radius
                            );
                        break;

                    case "SolidEdgeGeometry.Cone":
                        cone = (Cone)face.Geometry;
                        // Get cone dimensions
                        cone.GetConeData(
                            ref basePoint,
                            ref axisVector,
                            out radius,
                            out halfAngle,
                            out expanding
                            );
                        break;

                    case "SolidEdgeGeometry.Torus":
                        torus = (Torus)face.Geometry;
                        // Get torus dimensions
                        torus.GetTorusData(
                            ref centerPoint,
                            ref axisVector,
                            out majorRadius,
                            out minorRadius
                            );
                        break;

                    default:
                        break;
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
                throw;
            }
            finally
            {
                // Ungister
                OleMessageFilter.Unregister();
            }
        }
    }

 

If you want more dimensions, you can use the edges of faces and calculate the distance between them.

You can get edge as below:

 

                Edges edges = (Edges)face.Edges;
                Edge edge = (Edge)edges.Item(1);

... and use edge methods. I hope it helps you.

 

 

 



==========================
Kabir Costa
Industrial Designer
kabircosta@gmail.com