cancel
Showing results for 
Search instead for 
Did you mean: 

NXOpen - How to tell if a curve/edge is on a face

Creator
Creator

I'm writing an application that creates a cylinder then a series of fins on the cylinder. I need to select the edges between the cylinder and the fins programmatically so I can edge blend them. I had thought there was a simple way to see if a curve or edge was on a face, but I can't find anything right now. Brain fart, maybe? Any help would be appreciated.

6 REPLIES

Re: NXOpen - How to tell if a curve/edge is on a face

Phenom
Phenom

If you have a reference to the face, you can use the .GetEdges method to query all the edges that belong to the face.

Re: NXOpen - How to tell if a curve/edge is on a face

Creator
Creator

I am aware of .GetEdges. The problem is that this will also return the boundry edges of the face and not just the edges created by the fins on it. The edges of the cylinder can't be blended. I suppose I could go a GetEdges on the face and then loop through every one of the fins and get the edges from those and compare, but I'm not sure if that will work, and if it does, it seems a rather circuitous and inefficient way of doing it.

 

It would be much easier if I could loop through all the fin edges and ask "Is Fin on face". I could swear there was a way to do that. Is it one of the UF wrapped fucntions maybe?

Re: NXOpen - How to tell if a curve/edge is on a face

Legend
Legend

Several methods are possible.  Here is one.

 

1) Get the edges of a fin face

2) For each edge get a point on it and determine the distance to the cylinder face.  If the distance is less than the modeling tolerance then the edge lies on the cylinder face.

 

Frank Swinkels

 

Re: NXOpen - How to tell if a curve/edge is on a face

Legend
Legend

Here is a journal to do it using a different approach.  This example assumes the ribs are shorter then the cylinder.  If the ribs are the same length as the cylinder a little more work needs to be done.

 

Option Strict Off
Imports System
Imports NXOpen
Imports NXOpenUI
Imports NXOpen.UF
Imports NXOpen.Utilities
Imports NXOpen.Features

Module GetEdgeOnCylinder
    Dim s As Session = Session.GetSession()
    Dim ui As UI = ui.GetUI()
    Dim ufs As UFSession = UFSession.GetUFSession()
    Dim wp As Part = s.Parts.Work()
    Sub Main()
        Dim response1 As Selection.Response = Selection.Response.Cancel
        Dim body1 As Body = Nothing
        response1 = select_a_body1("Select the body", body1)
        ' get the body features
        Dim bodyfeats() As Feature = body1.GetFeatures()
        For Each f1 As Feature In bodyfeats
            If f1.FeatureType.ToString.Contains("CYLINDER") Then
                'get cylinder data featurebody
                Dim bodyfeature1 As BodyFeature = DirectCast(f1, BodyFeature)
                Dim cylinderfaces() As Face = bodyfeature1.GetFaces
                For Each face1 As Face In cylinderfaces
                    Dim faceedges1() As Edge = face1.GetEdges
                    For Each e1 As Edge In faceedges1
                        Dim v1 As Point3d = New Point3d(0, 0, 0)
                        Dim v2 As Point3d = New Point3d(0, 0, 0)
                        e1.GetVertices(v1, v2)
                        If v1.X = v2.X And v1.Y = v2.Y And v1.Z = v2.Z Then
                            ' cylinder end face
                        Else
                            ufs.Disp.SetHighlight(e1.Tag, 1)
                        End If
                    Next
                Next


            End If
        Next
    End Sub

    Function select_a_body1(ByVal title As String, ByRef body As Body) As Selection.Response
        Dim message As String = Nothing
        Dim scope As Integer = UFConstants.UF_UI_SEL_SCOPE_ANY_IN_ASSEMBLY
        Dim cursor As Point3d = Nothing
        Dim selectionMask_array(1) As Selection.MaskTriple
        With selectionMask_array(0)
            .Type = UFConstants.UF_solid_type
            .Subtype = UFConstants.UF_solid_body_subtype
            .SolidBodySubtype = UFConstants.UF_UI_SEL_FEATURE_BODY
        End With
        Dim resp As Selection.Response = _
    ui.SelectionManager.SelectTaggedObject("Body Selection", title, _
        Selection.SelectionScope.AnyInAssembly, _
        Selection.SelectionAction.ClearAndEnableSpecific, _
        False, False, selectionMask_array, body, cursor)
        If resp = Selection.Response.ObjectSelected Or _
           resp = Selection.Response.ObjectSelectedByName Then
            Return Selection.Response.Ok
        ElseIf resp = Selection.Response.Back Then
            Return Selection.Response.Cancel
        ElseIf resp = Selection.Response.Cancel Then
            Return Selection.Response.Cancel
        End If
        Return Selection.Response.Ok
    End Function

    Public Function GetUnloadOption(ByVal dummy As String) As Integer
        'Unloads the image immediately after execution within NX
        GetUnloadOption = NXOpen.Session.LibraryUnloadOption.Immediately
    End Function

End Module

 Regards

 

Frank Swinkels

Re: NXOpen - How to tell if a curve/edge is on a face

Siemens Phenom Siemens Phenom
Siemens Phenom

Could you perhaps get the "end caps" of the cylindrical face? If you can, then you can proceed as follows:

 

Loop through all the edges of the cylindrical face.

For each such edge, check its two adjacent faces.

If one of these adjacent faces is an "end cap" of the cylinder, ignore the edge.

If not, blend the edge.

山田
yamada

Re: NXOpen - How to tell if a curve/edge is on a face

Legend
Legend

I have added the checks for the cylinder cap edges to be ignored.

 

Option Strict Off
Imports System
Imports NXOpen
Imports NXOpenUI
Imports NXOpen.UF
Imports NXOpen.Utilities
Imports NXOpen.Features

Module GetEdgeOnCylinder
    Dim s As Session = Session.GetSession()
    Dim ui As UI = ui.GetUI()
    Dim ufs As UFSession = UFSession.GetUFSession()
    Dim wp As Part = s.Parts.Work()
    Sub Main()
        Dim response1 As Selection.Response = Selection.Response.Cancel
        Dim body1 As Body = Nothing
        Dim facetype As Integer = Nothing
        Dim capface(1) As Face
        Dim cnt1 As Integer = 0
        Dim cylinderface As Face = Nothing
        Dim joiningfacetags(1) As Tag
        response1 = select_a_body1("Select the body", body1)
        ' get the body features
        Dim bodyfeats() As Feature = body1.GetFeatures()
        For Each f1 As Feature In bodyfeats
            If f1.FeatureType.ToString.Contains("CYLINDER") Then
                'get cylinder data featurebody
                Dim bodyfeature1 As BodyFeature = DirectCast(f1, BodyFeature)
                Dim cylinderfaces() As Face = bodyfeature1.GetFaces
                For Each face1 As Face In cylinderfaces
                    ' test face to see if it is planar or cylindrical
                    ufs.Modl.AskFaceType(face1.Tag, facetype)
                    If facetype = 22 Then
                        capface(cnt1) = face1
                        cnt1 += 1
                    ElseIf facetype = 16 Then
                        cylinderface = face1
                    End If
                Next
                Dim faceedges1() As Edge = cylinderface.GetEdges
                For Each e1 As Edge In faceedges1
                    ufs.Modl.AskEdgeFaces(e1.Tag, joiningfacetags)
                    If joiningfacetags(0) = capface(0).Tag Or _
                        joiningfacetags(1) = capface(0).Tag Then
                        ' edge connected to cylinder cap 1
                    ElseIf joiningfacetags(0) = capface(1).Tag Or _
                    joiningfacetags(1) = capface(1).Tag Then
                        ' edge connected to cylinder cap 2
                    Else
                        ufs.Disp.SetHighlight(e1.Tag, 1)
                    End If
                Next
            End If
        Next
    End Sub

    Function select_a_body1(ByVal title As String, ByRef body As Body) As Selection.Response
        Dim message As String = Nothing
        Dim scope As Integer = UFConstants.UF_UI_SEL_SCOPE_ANY_IN_ASSEMBLY
        Dim cursor As Point3d = Nothing
        Dim selectionMask_array(1) As Selection.MaskTriple
        With selectionMask_array(0)
            .Type = UFConstants.UF_solid_type
            .Subtype = UFConstants.UF_solid_body_subtype
            .SolidBodySubtype = UFConstants.UF_UI_SEL_FEATURE_BODY
        End With
        Dim resp As Selection.Response = _
    ui.SelectionManager.SelectTaggedObject("Body Selection", title, _
        Selection.SelectionScope.AnyInAssembly, _
        Selection.SelectionAction.ClearAndEnableSpecific, _
        False, False, selectionMask_array, body, cursor)
        If resp = Selection.Response.ObjectSelected Or _
           resp = Selection.Response.ObjectSelectedByName Then
            Return Selection.Response.Ok
        ElseIf resp = Selection.Response.Back Then
            Return Selection.Response.Cancel
        ElseIf resp = Selection.Response.Cancel Then
            Return Selection.Response.Cancel
        End If
        Return Selection.Response.Ok
    End Function

    Public Function GetUnloadOption(ByVal dummy As String) As Integer
        'Unloads the image immediately after execution within NX
        GetUnloadOption = NXOpen.Session.LibraryUnloadOption.Immediately
    End Function

End Module

 

Frank Swinkels