GetRange and GetExactRange not giving accurate results

Valued Contributor
Valued Contributor

I am developing a macro where I used GetRange first, and later GetExactRange to know the dimensions of a part but It´s not giving the real dimensions. I guess the problem is with parts with Face Move features since all parts with these features are not giving an accurate result.

 

I also tried GetExtremePoint with same results.

 

Any advice to make a subroutine for extracting real dimensions?

 

Best wishes

Ramon del Aguila

5 REPLIES

Re: GetRange and GetExactRange not giving accurate results

Genius
Genius

Did you use it?


SolidEdgeGeometry.Body.GetExactRange

 

Can you show a picture of the problem?



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

Re: GetRange and GetExactRange not giving accurate results

Valued Contributor
Valued Contributor

That´s what I used

 

 

10-01.jpg

The length of the part is 77,5 mm. Body.ExactRange() is giving 137,7mm , 

Re: GetRange and GetExactRange not giving accurate results

Genius
Genius

Hello Ramon,

I did a fast study and verify that the GetExactRange get the points relative from Origin (XYZ Coordinate System).

 

GetExactRange.PNG

 

For solve your problem:

  • The coordinate system is far from the part?
  • Is there a surface outside in your part?

For get total dimensions of my part, I sum:

  • Max[x] - Min[x] = total X
  • Max[y] - Min[y] = total Y
  • Max[z] - Min[z] = total Z

 

My code is below:

class Program
    {
        [STAThread]                         // Use this in all programs
        static void Main(string[] args)
        {
            // Declare your main variables
            SolidEdgeFramework.Application application = null;
            SolidEdgeFramework.Documents documents = null;

            // Declare your document variables
            SolidEdgePart.PartDocument partDocument = null;

            // Declare models variables
            SolidEdgePart.Models models = null;
            SolidEdgePart.Model model = null;

            // Declare Body variable
            SolidEdgeGeometry.Body body = null;

            // Points to Get
            Array minRangePoint = new double[] { 0, 0.0, 0.0 };
            Array maxRangePoint = new double[] { 0.0, 0.0, 0.0 };

            try
            {
                // Register
                OleMessageFilter.Register();

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

                // Get your Document Collection
                documents = application.Documents;

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

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

                // Get body
                body = (SolidEdgeGeometry.Body)model.Body;

                // Get Range
                body.GetExactRange(
                    MinRangePoint: ref minRangePoint,
                    MaxRangePoint: ref maxRangePoint
                    );

                Console.WriteLine("Min X: " + minRangePoint.GetValue(0) + " m");
                Console.WriteLine("Min Y: " + minRangePoint.GetValue(1) + " m");
                Console.WriteLine("Min Z: " + minRangePoint.GetValue(2) + " m");
                Console.WriteLine("Max X: " + maxRangePoint.GetValue(0) + " m");
                Console.WriteLine("Max Y: " + maxRangePoint.GetValue(1) + " m");
                Console.WriteLine("Max Z: " + maxRangePoint.GetValue(2) + " m");
                Console.ReadKey();

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

 



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

Re: GetRange and GetExactRange not giving accurate results

Valued Contributor
Valued Contributor
Friend Shared Function BodyRange() As Object

        Dim models As SolidEdgePart.Models = Nothing
        Dim model As SolidEdgePart.Model = Nothing
        Dim body As SolidEdgeGeometry.Body = Nothing
        Dim Dimension() As Double = {0.0, 0.0, 0.0}

        models = Mainform.document.models

        If models.Count = 0 Then
            '  Throw New System.Exception("No hay geometría en el modelo.")
            MsgBox("No hay geometría en el archivo", MsgBoxStyle.Critical)
            Return Dimension
        End If

        For Each model In models
            If model.Name = "Design Model" Then
                body = DirectCast(model.Body, SolidEdgeGeometry.Body)
            End If
        Next

        Dim Min As Array = Array.CreateInstance(GetType(Double), 0)
        Dim Max As Array = Array.CreateInstance(GetType(Double), 0)
        body.GetExactRange(Min, Max)
      
        Dimension(0) = Math.Round(Math.Abs(Min(0) * 1000) + Math.Abs(Max(0) * 1000), 1)
        Dimension(1) = Math.Round(Math.Abs(Min(1) * 1000) + Math.Abs(Max(1) * 1000), 1)
        Dimension(2) = Math.Round(Math.Abs(Min(2) * 1000) + Math.Abs(Max(2) * 1000), 1)

        Return Dimension
    End Function

That´s my function code.

 

and yes I found the origin is outside the model so obviously the code is wrong. I´ll take a look on yours.

Re: GetRange and GetExactRange not giving accurate results

Genius
Genius

Try this:

 

(...)
Dimension(0) = Math.Round(  (Max(0) * 1000) - (Min(0) * 1000) )
(...)

 



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