' Journal to get limit points
Option Strict Off
Imports System
Imports NXOpen
Imports NXOpen.UF
Imports NXOpenUI
Module incidentangle50
Dim s As Session = Session.GetSession()
Dim ui As UI = ui.GetUI()
Dim ufs As UFSession = UFSession.GetUFSession()
Sub Main()
Dim wp As Part = s.Parts.Work
PointStart:
' select a point
Dim pnt1 As Point = Nothing
Dim response1 As Selection.Response = Selection.Response.Cancel
response1 = select_a_Point(pnt1)
If response1 = Selection.Response.Back Then GoTo End1
If response1 = Selection.Response.Cancel Then GoTo End1
Dim coordpnt() As Double = {pnt1.Coordinates.X, pnt1.Coordinates.Y, pnt1.Coordinates.Z}
FaceStart:
Dim face1 As Face = Nothing
Dim message1 As String = "Select a face"
Dim response2 As Selection.Response = Selection.Response.Cancel
response2 = select_a_Face(message1, face1)
If response2 = Selection.Response.Back Then GoTo PointStart
If response2 = Selection.Response.Cancel Then GoTo End1
Dim response3 As Selection.Response = Selection.Response.Cancel
' get limit points for constant u and constant v
' first get the normal point
Dim parm0(1) As Double
Dim pt0(2) As Double
Dim pt1(2) As Double
Dim pt2(2) As Double
Dim pt3(2) As Double
Dim parm1(1) As Double
Dim parm2(1) As Double
Dim parm3(1) As Double
Dim ptlimit1(2) As Double
Dim vec1(2) As Double
Dim cross1(2) As Double
Dim angle1 As Double = Nothing
Dim junk3(2) As Double
Dim norm1(2) As Double
Dim junk2(1) As Double
Dim u0 As Double = Nothing
Dim u1 As Double = Nothing
Dim u2 As Double = Nothing
Dim v0 As Double = Nothing
Dim v1 As Double = Nothing
Dim v2 As Double = Nothing
Dim v3 As Double = Nothing
Dim n0(2) As Double
Dim n1(2) As Double
Dim n2(2) As Double
Dim n3(2) As Double
Dim temptag As Tag = Tag.Null
Dim foundlimitpoint As Boolean = False
Dim uvminmax(3) As Double
ufs.Modl.AskFaceUvMinmax(face1.Tag, uvminmax)
' point1
ufs.Modl.AskFaceParm(face1.Tag, coordpnt, parm0, pt0)
parm1(0) = uvminmax(0)
parm1(1) = parm0(1)
ufs.Modl.AskFaceProps(face1.Tag, parm1, pt1, junk3, junk3, junk3, junk3, n1, junk2)
ufs.Vec3.Sub(coordpnt, pt1, vec1)
ufs.Vec3.Cross(vec1, n1, cross1)
ufs.Vec3.AngleBetween(vec1, n1, cross1, angle1)
angle1 = convertRadianToDegree(angle1)
If angle1 > 50.0 Then
ufs.Modl.AskFaceParm(face1.Tag, coordpnt, parm0, pt0)
foundlimitpoint = getLimitPoint(face1, coordpnt, pt0, pt1, parm0, parm1, pt3, angle1)
If foundlimitpoint = True Then
ufs.Curve.CreatePoint(pt3, temptag)
End If
End If
' point2
ufs.Modl.AskFaceParm(face1.Tag, coordpnt, parm0, pt0)
parm1(0) = uvminmax(1)
parm1(1) = parm0(1)
ufs.Modl.AskFaceProps(face1.Tag, parm1, pt1, junk3, junk3, junk3, junk3, n1, junk2)
ufs.Vec3.Sub(coordpnt, pt1, vec1)
ufs.Vec3.Cross(vec1, n1, cross1)
ufs.Vec3.AngleBetween(vec1, n1, cross1, angle1)
angle1 = convertRadianToDegree(angle1)
If angle1 > 50.0 Then
foundlimitpoint = getLimitPoint(face1, coordpnt, pt0, pt1, parm0, parm1, pt3, angle1)
If foundlimitpoint = True Then
ufs.Curve.CreatePoint(pt3, temptag)
End If
End If
' point3
ufs.Modl.AskFaceParm(face1.Tag, coordpnt, parm0, pt0)
parm1(0) = parm0(0)
parm1(1) = uvminmax(2)
ufs.Modl.AskFaceProps(face1.Tag, parm1, pt1, junk3, junk3, junk3, junk3, n1, junk2)
ufs.Vec3.Sub(coordpnt, pt1, vec1)
ufs.Vec3.Cross(vec1, n1, cross1)
ufs.Vec3.AngleBetween(vec1, n1, cross1, angle1)
angle1 = convertRadianToDegree(angle1)
If angle1 > 50.0 Then
foundlimitpoint = getLimitPoint(face1, coordpnt, pt0, pt1, parm0, parm1, pt3, angle1)
If foundlimitpoint = True Then
ufs.Curve.CreatePoint(pt3, temptag)
End If
End If
' point4
ufs.Modl.AskFaceParm(face1.Tag, coordpnt, parm0, pt0)
parm1(0) = parm0(0)
parm1(1) = uvminmax(3)
ufs.Modl.AskFaceProps(face1.Tag, parm1, pt1, junk3, junk3, junk3, junk3, n1, junk2)
ufs.Vec3.Sub(coordpnt, pt1, vec1)
ufs.Vec3.Cross(vec1, n1, cross1)
ufs.Vec3.AngleBetween(vec1, n1, cross1, angle1)
angle1 = convertRadianToDegree(angle1)
If angle1 > 50.0 Then
foundlimitpoint = getLimitPoint(face1, coordpnt, pt0, pt1, parm0, parm1, pt3, angle1)
If foundlimitpoint = True Then
ufs.Curve.CreatePoint(pt3, temptag)
End If
End If
' point5
ufs.Modl.AskFaceParm(face1.Tag, coordpnt, parm0, pt0)
parm1(0) = uvminmax(0)
parm1(1) = uvminmax(2)
ufs.Modl.AskFaceProps(face1.Tag, parm1, pt1, junk3, junk3, junk3, junk3, n1, junk2)
ufs.Vec3.Sub(coordpnt, pt1, vec1)
ufs.Vec3.Cross(vec1, n1, cross1)
ufs.Vec3.AngleBetween(vec1, n1, cross1, angle1)
angle1 = convertRadianToDegree(angle1)
If angle1 > 50.0 Then
ufs.Modl.AskFaceParm(face1.Tag, coordpnt, parm0, pt0)
foundlimitpoint = getLimitPoint(face1, coordpnt, pt0, pt1, parm0, parm1, pt3, angle1)
If foundlimitpoint = True Then
ufs.Curve.CreatePoint(pt3, temptag)
End If
End If
' point6
ufs.Modl.AskFaceParm(face1.Tag, coordpnt, parm0, pt0)
parm1(0) = uvminmax(1)
parm1(1) = uvminmax(2)
ufs.Modl.AskFaceProps(face1.Tag, parm1, pt1, junk3, junk3, junk3, junk3, n1, junk2)
ufs.Vec3.Sub(coordpnt, pt1, vec1)
ufs.Vec3.Cross(vec1, n1, cross1)
ufs.Vec3.AngleBetween(vec1, n1, cross1, angle1)
angle1 = convertRadianToDegree(angle1)
If angle1 > 50.0 Then
foundlimitpoint = getLimitPoint(face1, coordpnt, pt0, pt1, parm0, parm1, pt3, angle1)
If foundlimitpoint = True Then
ufs.Curve.CreatePoint(pt3, temptag)
End If
End If
' point7
ufs.Modl.AskFaceParm(face1.Tag, coordpnt, parm0, pt0)
parm1(0) = uvminmax(0)
parm1(1) = uvminmax(3)
ufs.Modl.AskFaceProps(face1.Tag, parm1, pt1, junk3, junk3, junk3, junk3, n1, junk2)
ufs.Vec3.Sub(coordpnt, pt1, vec1)
ufs.Vec3.Cross(vec1, n1, cross1)
ufs.Vec3.AngleBetween(vec1, n1, cross1, angle1)
angle1 = convertRadianToDegree(angle1)
If angle1 > 50.0 Then
foundlimitpoint = getLimitPoint(face1, coordpnt, pt0, pt1, parm0, parm1, pt3, angle1)
If foundlimitpoint = True Then
ufs.Curve.CreatePoint(pt3, temptag)
End If
End If
' point8
ufs.Modl.AskFaceParm(face1.Tag, coordpnt, parm0, pt0)
parm1(0) = uvminmax(1)
parm1(1) = uvminmax(3)
ufs.Modl.AskFaceProps(face1.Tag, parm1, pt1, junk3, junk3, junk3, junk3, n1, junk2)
ufs.Vec3.Sub(coordpnt, pt1, vec1)
ufs.Vec3.Cross(vec1, n1, cross1)
ufs.Vec3.AngleBetween(vec1, n1, cross1, angle1)
angle1 = convertRadianToDegree(angle1)
If angle1 > 50.0 Then
foundlimitpoint = getLimitPoint(face1, coordpnt, pt0, pt1, parm0, parm1, pt3, angle1)
If foundlimitpoint = True Then
ufs.Curve.CreatePoint(pt3, temptag)
End If
End If
End1:
End Sub
Public Function getLimitPoint(ByVal face1 As Face, ByVal p0() As Double, ByVal p1() As Double, ByVal p2() As Double, ByVal parm1() As Double, _
ByVal parm2() As Double, ByRef p3() As Double, ByRef a3 As Double) As Boolean
Dim junk3(2) As Double
Dim norm1(2) As Double
Dim junk2(1) As Double
Dim aimangle As Double = 50.0 * Math.PI / 180.0
Dim checkcount As Integer = 0
Dim tol1 As Double = 0.0001
Dim n3(2) As Double
Dim vec1(2) As Double
Dim delangle As Double = Nothing
Dim parm3() As Double = {(parm1(0) + parm1(0)) / 2.0, (parm1(1) + parm1(1)) / 2.0}
Dim cross1(2) As Double
ufs.Modl.AskFaceProps(face1.Tag, parm2, p3, junk3, junk3, junk3, junk3, n3, junk2)
ufs.Vec3.Sub(p0, p3, vec1)
ufs.Vec3.Cross(vec1, n3, cross1)
ufs.Vec3.AngleBetween(vec1, n3, cross1, a3)
If a3 < aimangle Then
Return False
End If
delangle = Math.Abs(a3 - aimangle)
While delangle > tol1
If a3 > aimangle Then
ufs.Vec3.Copy(p3, p2)
ufs.Modl.AskFaceParm(face1.Tag, p1, parm1, p1)
ufs.Modl.AskFaceParm(face1.Tag, p2, parm2, p2)
Else
ufs.Vec3.Copy(p3, p1)
ufs.Modl.AskFaceParm(face1.Tag, p1, parm1, p1)
ufs.Modl.AskFaceParm(face1.Tag, p2, parm2, p2)
End If
parm3(0) = (parm1(0) + parm2(0)) / 2.0
parm3(1) = (parm1(1) + parm2(1)) / 2.0
ufs.Modl.AskFaceProps(face1.Tag, parm3, p3, junk3, junk3, junk3, junk3, n3, junk2)
ufs.Vec3.Sub(p0, p3, vec1)
ufs.Vec3.Cross(vec1, n3, cross1)
ufs.Vec3.AngleBetween(vec1, n3, cross1, a3)
checkcount += 1
If checkcount > 20 Then
Return False
End If
delangle = Math.Abs(a3 - aimangle)
End While
Return True
End Function
Public Function convertRadianToDegree(ByVal angleRadians As Double) As Double
Dim angledegrees As Double = angleRadians * 180.0 / Math.PI
Return angledegrees
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
Function select_a_Point(ByRef pnt1 As Point) As Selection.Response
Dim mask(0) As Selection.MaskTriple
With mask(0)
.Type = UFConstants.UF_point_type
.Subtype = 0
.SolidBodySubtype = 0
End With
Dim cursor As Point3d = Nothing
Dim resp As Selection.Response = _
ui.SelectionManager.SelectObject("Select point to project from", "Select a Point", _
Selection.SelectionScope.AnyInAssembly, _
Selection.SelectionAction.ClearAndEnableSpecific, _
False, False, mask, pnt1, cursor)
If resp = Selection.Response.ObjectSelected Or _
resp = Selection.Response.ObjectSelectedByName Then
Return Selection.Response.Ok
Else
Return Selection.Response.Cancel
End If
End Function
Function select_a_Face(ByVal message As String, ByRef obj As Face) As Selection.Response
Dim selectionMask_array(0) As Selection.MaskTriple
With selectionMask_array(0)
.Type = UFConstants.UF_face_type
.Subtype = 0
.SolidBodySubtype = 0
End With
Dim cursor As Point3d = Nothing
Dim resp As Selection.Response = _
ui.SelectionManager.SelectObject("Face Selection", message, _
Selection.SelectionScope.AnyInAssembly, _
Selection.SelectionAction.ClearAndEnableSpecific, _
False, False, selectionMask_array, obj, 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.Back
Else
Return Selection.Response.Cancel
End If
End Function
End Module