Cancel
Showing results for 
Search instead for 
Did you mean: 
Highlighted

Get facet faces coordiates

Pioneer
Pioneer

Hello,
I`m trying to find a way how to get coordinates for each triangular facet face.
I think i able to get quantity and type of faces in facetbody by this below:

For Each facet As NXOpen.Facet.FacetedBody In workPart.FacetedBodies
Dim fACETLIST As NXOpen.Facet.FacetedFace()
Try
fACETLIST=facet.GetFaces()
For i As Integer=0 To fACETLIST.Length-1
lw.WriteLine(fACETLIST(i).FaceType.ToString)
Next
lw.WriteLine(fACETLIST.Length)
Catch ex As Exception
End Try
Next

that gives me output like 30 facet and type of each one.
But how to get vertex values??

I need these outputs for creation new surfaces (it`s also question how) instead facet triangulars in order to make sew for solid body instead unselectable facetbody.

 

thanks in advance!

15 REPLIES 15

Re: Get facet faces coordiates

You should be able to use .GetEdges() on the FacetedFace to get the FacetedEdges, and then .GetVertices() on the FacetedEdge to get the Vertices.

 

However, if you want to be able to use the faceted body for NX features, you could try to convert it to a 'convergent' type facet body using the "Convert Facet Body" feature. That might give you what you need.

 

 

Nikolas Losse | Developer | Siemens PG PR R&D TEC
NX12 | CentOS7 | Python

Re: Get facet faces coordiates

Siemens Experimenter Siemens Experimenter
Siemens Experimenter

 Hi,

 

 

 

UF_FACET_ask_vertices_of_facet(nxFacetBody->Tag(), im, &num_vertices, vertices);

 

Re: Get facet faces coordiates

Pioneer
Pioneer

Hello,

Thanks for proposals to Both.

But firstly I`m using nx10 where convergentbody isn`t work as i know, and this nxopen class is written for nx11. (or am i wrong?). Also I starting to think that what I got by GetFaces() method is not what i intend to find: it seems that it just faces of the facetbody and it`s not triangular facets. Because when I got output of type of the faces there were:

conical

cilyndrical

planar and so on.

My idea to collect all data from facetfaces and build new surfaces for sew in order to get usable solid/sheet body,

but now i don`t understand where to find facetfaces for rebuilding new solid instead.

Do you have any general idea?

Is these faces what i got from Getfaces() is rigth approach?

Re: Get facet faces coordiates

Ok, NX10 might not have convergent type facet bodies yet - shame.

 

If you just need the facet coordinates, the function @ParamveerPatil mentioned should help you out.

 

NX10 should already have NX type and JT type facet bodies, I think the UF.Facet functions only work on NX type.

 

If you need more - e.g. face normals at the facets, you can also get that using UF.Facet. Here's some code in Python that I use - should put you on the right track even if you use a different language.

 

def getNxFacetBodyFacetIds(body):
    """Get the facet IDs for a given NX type facet body.

    Note that there are three types of facet body (NX, Jt, Convergent) and this method only works for NX type.

    Args:
        body (NXOpen.Facet.FacetedBody)

    Returns:
        list: list of facet IDs (int)
    """
    theUfSession = NXOpen.UF.UFSession.GetUFSession()
    facet_id = NXOpen.UF.UFConstants.UF_FACET_NULL_FACET_ID
    tag = body.Tag
    facet_id_list = list()

    for i_facet in range(theUfSession.Facet.AskNFacetsInModel(tag)):
        facet_id = theUfSession.Facet.CycleFacets(tag, facet_id)
        facet_id_list.append(facet_id)

    return facet_id_list


def getNxFacetBodyVertices(body):
    """Get a list of all unique vertices in a NX type facet body, along with lists of the normal of those vertices
    plus lists of the facet_id and vertex_id of the vertex.

    Note that there are three types of facet body (NX, Jt, Convergent) and this method only works for NX type.

    Args:
        body (NXOpen.Facet.FacetedBody)

    Returns:
        list: list of dict with keys vertex, normal, facet_id, vertex_id
    """
    theUfSession = NXOpen.UF.UFSession.GetUFSession()
    facet_id_list = getNxFacetBodyFacetIds(body)

    vertex_dict_list = []
    vertex_list = []

    for facet_id in facet_id_list:
        _, vertices = theUfSession.Facet.AskVerticesOfFacet(body.Tag, facet_id)
        _, normals = theUfSession.Facet.AskNormalsOfFacet(body.Tag, facet_id)
        for vertex_id, (vertex, normal) in enumerate(zip(vertices, normals)):
            if vertex not in vertex_list:
                d = dict()
                d['vertex'] = vertex
                d['normal'] = normal
                d['facet_id'] = facet_id
                d['vertex_id'] = vertex_id
                vertex_dict_list.append(d)
                vertex_list.append(vertex)

    return vertex_dict_list
Nikolas Losse | Developer | Siemens PG PR R&D TEC
NX12 | CentOS7 | Python

Re: Get facet faces coordiates

Siemens Phenom Siemens Phenom
Siemens Phenom
I’ve seen several programs that build solid bodies with thousands of tiny triangular faces, as you describe. In fact, I even wrote one myself, long ago. So, before you write too much code, it would be wise to see if you can find a program that does what you want.

Also, think about how you’re going to use the output body. These bodies tend to be huge, and some NX operations don’t work very well on them.

Also, you should bear in mind that your approach is very different from the direction in which NX is going. With Convergent Technology, a face can consist of an entire collection of facets, not just one.
山田
yamada

Re: Get facet faces coordiates

Pioneer
Pioneer
Thanks for quide, it was helpful to understand how to get vertices this way, here is below:
/////////////////////////////////////////////////////////////
For Each facettag As Tag In Facetface
Dim facetID As Integer = UFConstants.UF_FACET_NULL_FACET_ID
Dim vertcount As Integer = Nothing
ufsession.Facet.AskMaxFacetVerts(facettag,vertcount)
Dim Vertices (vertcount,2) As Double
ufsession.Facet.CycleFacets(facettag,facetID)
While facetID<>UFConstants.UF_FACET_NULL_FACET_ID
ufsession.Facet.AskNumVertsInFacet(facettag,facetID,vertcount)
ufsession.Facet.AskVerticesOfFacet(facettag,facetID,vertcount,Vertices)
ufsession.Facet.CycleFacets(facettag,facetID)
End While
lw.WriteLine("verticescount: " & vertcount)
Next
/////////////////////////////////////////////////////////////////////////////
But now Im not quite sure how to use these vertices for building line for example?
vertices is two dimensional array of double (count_of_points, 3dPoint) as I understand.
Could you advise me how to get 3dpoint data of each vertice for creation lines between each vertice?
is it possible maybe to redim this array to dictionary where the key would be count and value 3dpoint?

thanks
e

Re: Get facet faces coordiates

I think what @Yamada said is absolutely correct - you are about to put a lot of work into something. Maybe try to find an existing solution first.

 

Does you NX version have the "fit surface" feature? That can create a body from a facet body. The result can be rather less pretty than one would hope for, but it might be a good start.

 

 

Nikolas Losse | Developer | Siemens PG PR R&D TEC
NX12 | CentOS7 | Python

Re: Get facet faces coordiates

Pioneer
Pioneer

I shart to think as well after I counted all vercites in small simple facet body. Its huge amount of data, and would be too long compare to desired result and needs. Moreover, after that cycle of verticies NX close after running. I raised an issue with that by the way.

Yes in nx10 fit surface on board. Also I saw NXOpen.Facet.ConvertFacetBodyBuilder created in NX10.

Do you know its possible to get convergent body from NXfacet?

 

thanks

e

 

Re: Get facet faces coordiates

Yes, the "convert facet body" feature does exactly that! It allows you to convert any facet body type into any other (NX, JT, convergent)

Nikolas Losse | Developer | Siemens PG PR R&D TEC
NX12 | CentOS7 | Python