Showing results for 
Search instead for 
Do you mean 
Reply
Solved! Go to solution

NXOpen get body geometry

Hello! 

I am looking for a way how to export triangulated model geometry.
I do not need any object model. I just want to obtain the current triangulation in terms of list of vertices and faces. How can I get a list of vertices and faces?

I'm using NX9 and VS 2012 C# or C ++.

In other words, I would like to have the following geometry for the simple box (values obtained from my plugin for Inventor):

Vertices={
0, 0.0154793810844421, -0.0254450464248657;
0, 0.0154793810844421, 0.0257058310508728;
0.01, 0.0154793810844421, 0.0257058310508728;
0.01, 0.0154793810844421, -0.0254450464248657;
0, -0.0168205547332764, -0.0254450464248657;
0, 0.0154793810844421, -0.0254450464248657;
0.01, 0.0154793810844421, -0.0254450464248657;
0.01, -0.0168205547332764, -0.0254450464248657;
0, -0.0168205547332764, 0.0257058310508728;
0, -0.0168205547332764, -0.0254450464248657;
0.01, -0.0168205547332764, -0.0254450464248657;
0.01, -0.0168205547332764, 0.0257058310508728;
0, 0.0154793810844421, 0.0257058310508728;
0, -0.0168205547332764, 0.0257058310508728;
0.01, -0.0168205547332764, 0.0257058310508728;
0.01, 0.0154793810844421, 0.0257058310508728;
0.01, 0.0154793810844421, 0.0257058310508728;
0.01, -0.0168205547332764, 0.0257058310508728;
0.01, -0.0168205547332764, -0.0254450464248657;
0.01, 0.0154793810844421, -0.0254450464248657;
0, -0.0168205547332764, 0.0257058310508728;
0, 0.0154793810844421, 0.0257058310508728;
0, 0.0154793810844421, -0.0254450464248657;
0, -0.0168205547332764, -0.0254450464248657;
};
Faces={
1,2,4;
4,2,3;
5,6,8;
8,6,7;
9,10,12;
12,10,11;
13,14,16;
16,14,15;
18,19,17;
17,19,20;
22,23,21;
21,23,24;
};
6 REPLIES

Re: NXOpen get body geometry

A couple of different approaches ...

 

(1) Export an STL file. It has triangle data in roughly the form you described.

 

(2) Create a facetted body in NX, and then read its facet data. Use NXOpen.UF.UFFacet.CycleFacets to cycle through the facets and NXOpen.UF.UFFacet.AskVerticesOfFacet to get the vertices of each facet. The old NX/Open docs describe these functions quite well, and there are even some example programs.

山田
yamada
Solution
Solution
Accepted by topic author VivO
‎02-10-2016 10:30 AM

Re: NXOpen get body geometry

The second approach (use NXOpen.UF.UFFacet.CycleFacets) is appriciable.

I've found an example of receiving edges (EX_Facet.cs):

    static int example3(Tag model)
    {
        int num_facets_in_model;
        int max_vertices_in_facet;
        int vertex_array_size;

        double[] plane_normal = new double[3];
        double d_coefficient;
        int facet_id;
        int facet_no = 0;
        int i;


        theUfSession.Facet.AskNFacetsInModel(model, out num_facets_in_model);
        theUfSession.Facet.AskMaxFacetVerts(model, out max_vertices_in_facet);

        double doubleVariable = 0.0;
        vertex_array_size = 3 * max_vertices_in_facet * Marshal.SizeOf(doubleVariable);
        double[,] facet_vertices = new double[vertex_array_size, 3];
        double[,] facet_normals = new double[vertex_array_size, 3];

        w.WriteLine("Model contains {0} facets\n", num_facets_in_model);
        w.WriteLine("Maxmium vertices in any facet is {0}\n",
            max_vertices_in_facet);
        facet_id = UF_FACET_NULL_FACET_ID;

        theUfSession.Facet.CycleFacets(model, ref facet_id);
        while (facet_id != UF_FACET_NULL_FACET_ID)
        {
            int num_vertices_in_facet;
            int verts_in_facet;
            bool facet_convexity;
            theUfSession.Facet.AskNumVertsInFacet(model, facet_id,
                out num_vertices_in_facet);

            w.WriteLine("UFFacet {0} has {1} vertices\n",
                facet_no++, num_vertices_in_facet);
            theUfSession.Facet.AskPlaneEquation(model,
                facet_id,
                plane_normal,
                out d_coefficient
                );
            w.WriteLine(" UFFacet normal ({0}, {1}, {2}) d_coeff {3}\n",
                plane_normal[0], plane_normal[1],
                plane_normal[2], d_coefficient);
            theUfSession.Facet.IsFacetConvex(model,
                facet_id,
                out facet_convexity);
            w.WriteLine(" UFFacet {0} convex\n",
                (facet_convexity) ? "IS" : "IS NOT");
            theUfSession.Facet.AskVerticesOfFacet(model,
                facet_id,
                out verts_in_facet,
                facet_vertices
                );
            theUfSession.Facet.AskNormalsOfFacet(model,
                facet_id,
                out verts_in_facet,
                facet_normals
                );
            for (i = 0; i < num_vertices_in_facet; i++)
            {
                int vertex_convexity;
                w.WriteLine("  Vertex {0}: ({1}, {2}, {3})\n",
                    i, facet_vertices[i, 0],
                    facet_vertices[i, 1],
                    facet_vertices[i, 2]);
                w.WriteLine("    Normal ({0}, {1}, {2})\n",
                    facet_normals[i, 0],
                    facet_normals[i, 1],
                    facet_normals[i, 2]);
                theUfSession.Facet.AskVertexConvexity(model,
                    facet_id,
                    i,
                    out vertex_convexity);
                w.WriteLine("    Vertex convexity = {0}\n",
                    (vertex_convexity == UF_FACET_IS_CONVEX) ?
                    "IS CONVEX" :
                    (vertex_convexity == UF_FACET_IS_CONCAVE) ?
                    "IS CONCAVE" :
                    "CONVEXITY IS NOT DETERMINED"
                    );
            }
            theUfSession.Facet.CycleFacets(model, ref facet_id);
        }
        return 0;
    }

The code succesfully works with the model generated internally (in Samples), but when I try to apply the procedure to my own models the error message is generated in Log:  

 

*** EXCEPTION: Error code  1165001 in line 1744 of o:\ugnx100\ip24\src\ufunx\no\ind\ufx_facet.c 
+++ Invalid model

It look like that my models must be generated in a special way, or preprocessed before convertion.

I've tried two variants (see below) but without success: 

 

faceted_model = theUfSession.Part.AskDisplayPart();
faceted_model = theUfSession.Assem.AskWorkPart();
example3(faceted_model);

Could you advise me the correct approach to convert the already existed model? 

Solution
Solution
Accepted by topic author VivO
‎02-10-2016 10:30 AM

Re: NXOpen get body geometry

There are two types of facetted bodies in NX (unfortunately) -- ones that use the older "NX" facets, and ones that use the newer "JT" facets. Some NX/Open functions work on both types, and some work on one type but not the other.

 

In general, the NXOpen.UF.UFFacet functions were originally intended for use with NX-facet bodies, but, in many cases, they have been enhanced to work with JT-facet bodies, too. Conversely, the NXOpen.Facet functions work almost exclusively with JT-facet bodies.

 

You can convert between types by using the NXOpen.Facet.FacetedBodyCollection.Convert function.

山田
yamada

Re: NXOpen get body geometry

Thank you very much for your help. Now I can get cooredinates of vertices. For the simple cube I got 24 vertices. However, I cannot understand how to get faces. In other words, I cannot get the order how vertices form every face. Could you please give me a hint how to get faces for the example from the first message.

Re: NXOpen get body geometry

[ Edited ]

In Python, what would you use for model <tag> and "facetid"?

NXOpen.UF.UFFacet.CycleFacets(model, facetid)

I referred to this documentation but did not find an example

https://docs.plm.automation.siemens.com/data_services/resources/nx/10/nx_api/en_US/custom/nxopen_pyt...

 

https://docs.plm.automation.siemens.com/data_services/resources/nx/10/nx_api/en_US/custom/ugopen_doc...

 

as a workaround, I recorded (in python) the "Fill hole" command and obtained the Entity name and then used that to obtain the tag. See code below. How could I do this without knowing the entity name before hand?

 

self.theLw.WriteLine(str(NXOpen.UF.Tag("ENTITY 139 1 1")))

 

Re: NXOpen get body geometry

[ Edited ]

> what would you use for model <tag> and "facetid"?

 

"model" is the tag of the facetted body whose facets you want to cycle through.

 

"facetid" is an integer that identifies a particular facet within the facetted body. It is automatically incremented by each call to CycleFacets, as shown in the code above.

山田
yamada