Option Strict Off
Imports System
Imports NXOpen
Imports NXOpenUI
Imports NXOpen.UF
Imports NXOpen.Utilities
Module AdjacentTangentFaces
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 startFace As Face = Nothing
Dim faceTangency As Boolean = False
response1 = select_a_face("Select a face", startFace)
ufs.Disp.SetHighlight(startFace.Tag, 1)
Dim startfaceEdges() As Edge = startFace.GetEdges
For Each e1 As Edge In startfaceEdges
Dim adjfacestags(-1) As Tag
ufs.Modl.AskEdgeFaces(e1.Tag, adjfacestags)
If adjfacestags(0) <> startFace.Tag Then
' check if adjacent face is tangent
faceTangency = askForFaceTangency(startFace, e1, adjfacestags(0))
If faceTangency = True Then
ufs.Disp.SetHighlight(adjfacestags(0), 1)
End If
ElseIf adjfacestags(1) <> startFace.Tag Then
faceTangency = askForFaceTangency(startFace, e1, adjfacestags(1))
If faceTangency = True Then
ufs.Disp.SetHighlight(adjfacestags(1), 1)
End If
End If
Next
End Sub
Function select_a_face(ByRef prompt As String, ByRef face1 As Face) As Selection.Response
Dim mask(0) As Selection.MaskTriple
With mask(0)
.Type = UFConstants.UF_solid_type
.Subtype = 0
.SolidBodySubtype = UFConstants.UF_UI_SEL_FEATURE_ANY_FACE
End With
Dim cursor As Point3d = Nothing
Dim response1 As Selection.Response = Selection.Response.Cancel
select_a_face = Nothing
response1 = ui.GetUI.SelectionManager.SelectTaggedObject(prompt, prompt, _
Selection.SelectionScope.AnyInAssembly, _
Selection.SelectionAction.ClearAndEnableSpecific, False, _
False, mask, face1, cursor)
If response1 = Selection.Response.ObjectSelected Or _
response1 = Selection.Response.ObjectSelectedByName Then
Return Selection.Response.Ok
ElseIf response1 = Selection.Response.Back Then
Return Selection.Response.Back
Else
Return Selection.Response.Cancel
End If
End Function
Function askForFaceTangency(ByVal startface As Face, ByVal testedge As Edge, _
ByRef nextFacetag As Tag) As Boolean
Dim istrue As Boolean = False
Dim parm1(1) As Double
Dim pointdbl(2) As Double
Dim junk3(2) As Double
Dim junk2(1) As Double
Dim junk1 As Double = Nothing
Dim normal1(2) As Double
Dim normal2(2) As Double
ufs.Modl.AskCurveProps(testedge.Tag, 0.5, pointdbl, junk3, junk3, junk3, junk1, junk1)
ufs.Modl.AskFaceParm(startface.Tag, pointdbl, parm1, pointdbl)
ufs.Modl.AskFaceProps(startface.Tag, parm1, pointdbl, junk3, junk3, junk3, junk3, normal1, junk2)
ufs.Modl.AskFaceParm(nextFacetag, pointdbl, parm1, pointdbl)
ufs.Modl.AskFaceProps(nextFacetag, parm1, pointdbl, junk3, junk3, junk3, junk3, normal2, junk2)
Dim tangency As Boolean
Dim tol1 As Double = 0.01
ufs.Vec3.IsEqual(normal1, normal2, tol1, tangency)
Return tangency
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