Creating Points at the maximum distance between 2 splines
Creating Points at the maximum distance between 2 splines
(OP)
I am trying to generate points at the maximum distance between 2 splines, my only solution is to go into the deviation checking tool and find the maximum point between 2 curves.
This generates XYZ co-ordinates for the source curve which I can then input into the point command to create a point in space. I then have to go through this process again but reverse the selection between the curves.
This would be OK if I was doing it for one set of curves but when I have to create points for hundreds of sections this can get a bit laborious!
Surely this isn't the only solution, is there a simpler method that I have completely missed or has someone created a grip for this?
This generates XYZ co-ordinates for the source curve which I can then input into the point command to create a point in space. I then have to go through this process again but reverse the selection between the curves.
This would be OK if I was doing it for one set of curves but when I have to create points for hundreds of sections this can get a bit laborious!
Surely this isn't the only solution, is there a simpler method that I have completely missed or has someone created a grip for this?





RE: Creating Points at the maximum distance between 2 splines
John R. Baker, P.E.
Product 'Evangelist'
Product Engineering Software
Siemens PLM Software Inc.
Industry Sector
Cypress, CA
Siemens PLM:
UG/NX Museum:
To an Engineer, the glass is twice as big as it needs to be.
RE: Creating Points at the maximum distance between 2 splines
CODE -->
Option Strict Off Imports System Imports NXOpen Imports NXOpen.UI Imports NXOpen.UF Module PointsBetweenSplines Dim s As Session = Session.GetSession() Dim ufs As UFSession = UFSession.GetUFSession() Dim workPart As Part = s.Parts.Work Sub Main() Dim spline1 As NXOpen.Tag = NXOpen.Tag.Null Dim spline2 As NXOpen.Tag = NXOpen.Tag.Null Dim response1 As NXOpen.Selection.Response = Selection.Response.Cancel Dim response2 As NXOpen.Selection.Response = Selection.Response.Cancel Dim title1 As String = "Select Spline 1" Dim title2 As String = "Select Spline 2" start1: response1 = select_spline(spline1, title1) If response1 = Selection.Response.Cancel Then Exit Sub If response1 = Selection.Response.Back Then Exit Sub response2 = select_spline(spline2, title2) If response2 = Selection.Response.Cancel Then Exit Sub If response2 = Selection.Response.Back Then GoTo start1 Dim junk3(2) As Double Dim junk As Double Dim point() As Double = {0.0, 0.0, 0.0} Dim point1() As Double = {0.0, 0.0, 0.0} Dim point2() As Double = {0.0, 0.0, 0.0} Dim vec1(2), vec2(2), vec3(2), vec4(2) As Double Dim unitv0(2), unitv1(2), unitv2(2), unitv3(2), unitv4(2) As Double Dim point3(2), point4(2), point5(2) As Double Dim parm, parm1, parm2 As Double Dim l0, l1, l2, del1, del2 As Double Dim tempTag As NXOpen.Tag = NXOpen.Tag.Null For i As Integer = 0 To 50 parm = i / 50.0 ufs.Modl.AskCurveProps(spline1, parm, point1, vec1, junk3, junk3, junk, junk) ufs.Modl.AskCurveProps(spline2, parm, point2, vec2, junk3, junk3, junk, junk) ufs.Vec3.Sub(point1, point2, vec3) ufs.Vec3.Unitize(vec3, 0.001, l0, unitv1) l0 /= 2.0 point3(0) = (point1(0) + point2(0)) / 2.0 point3(1) = (point1(1) + point2(1)) / 2.0 point3(2) = (point1(2) + point2(2)) / 2.0 ufs.Modl.AskCurveParm(spline1, point3, parm1, point4) If parm1 < 0 Or parm1 > 1 Then Continue For ufs.Vec3.Distance(point3, point4, l1) ufs.Modl.AskCurveParm(spline2, point3, parm2, point5) If parm2 < 0 Or parm2 > 1 Then Continue For ufs.Vec3.Distance(point3, point5, l2) del1 = l1 - l2 del2 = Math.Abs(del1) Dim cnt1 As Integer = 0 While del2 > 0.001 l0 = l0 + del1 / 2.0 ufs.Vec3.AffineComb(point2, l0, unitv1, point3) ufs.Modl.AskCurveParm(spline1, point3, parm1, point4) If parm1 < 0 Or parm1 > 1 Then Continue For ufs.Modl.AskCurveParm(spline2, point3, parm2, point5) If parm2 < 0 Or parm2 > 1 Then Continue For ufs.Vec3.Distance(point3, point4, l1) ufs.Modl.AskCurveParm(spline2, point3, parm2, point5) If parm2 < 0 Or parm2 > 1 Then Continue For ufs.Vec3.Distance(point3, point5, l2) del1 = l1 - l2 del2 = Math.Abs(del1) cnt1 += 1 If cnt1 > 10 Then MsgBox("Not converging") Exit While End If End While ufs.Curve.CreatePoint(point3, tempTag) Next ufs.Disp.SetHighlight(spline1, 0) ufs.Disp.SetHighlight(spline2, 0) End Sub Function select_spline(ByRef spline As NXOpen.Tag, ByVal title As String) _ As Selection.Response Dim mssg As String = "Mid Points:" Dim scope As Integer = UFConstants.UF_UI_SEL_SCOPE_ANY_IN_ASSEMBLY Dim response As Integer Dim view As NXOpen.Tag Dim cursor(2) As Double Dim mask_splines As UFUi.SelInitFnT = AddressOf mask_for_splines ufs.Ui.LockUgAccess(UFConstants.UF_UI_FROM_CUSTOM) Try ufs.Ui.SelectWithSingleDialog(mssg, title, scope, mask_splines, _ Nothing, response, spline, cursor, view) Finally ufs.Ui.UnlockUgAccess(UFConstants.UF_UI_FROM_CUSTOM) End Try If response <> UFConstants.UF_UI_OBJECT_SELECTED And _ response <> UFConstants.UF_UI_OBJECT_SELECTED_BY_NAME Then Return Selection.Response.Cancel ElseIf response = Selection.Response.Back Then Return Selection.Response.Back Else Return Selection.Response.Ok End If End Function Function mask_for_splines(ByVal select_ As IntPtr, _ ByVal userdata As IntPtr) As Integer Dim num_triples As Integer = 1 Dim mask_triples(0) As UFUi.Mask mask_triples(0).object_type = UFConstants.UF_spline_type mask_triples(0).object_subtype = UFConstants.UF_spline_subtype mask_triples(0).solid_type = 0 ufs.Ui.SetSelMask(select_, _ UFUi.SelMaskAction.SelMaskClearAndEnableSpecific, _ num_triples, mask_triples) Return UFConstants.UF_UI_SEL_SUCCESS 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 ModuleFrank Swinkels
RE: Creating Points at the maximum distance between 2 splines
RE: Creating Points at the maximum distance between 2 splines
Regards,
Tomas
RE: Creating Points at the maximum distance between 2 splines
For each pair of intersection curves, create a sketch on the same plane as the curves and in the sketch draw two lines which are constrained to be horizonal and then constrain each line to be tangent to one of the two intersection curves (note that the intrsection curves do NOT have to be added to the sketch as long as they lay in the same plane as the sketch). Then create a line between the end points of one end of each line and constrain this line to be vertical. Once you leave the sketch this line can be measured and its length captured as an expression which will represent the 'thickness' of your airfoil at that particular 'station'. If the intersection curves were created as associative curves, then when you edit your original airfoil surfaces the various 'thickness' values for each pair of curves will update automatically.
To see how this would work see the attached file showing what one of those sketches would look like and how it would be constrained.
John R. Baker, P.E.
Product 'Evangelist'
Product Engineering Software
Siemens PLM Software Inc.
Industry Sector
Cypress, CA
Siemens PLM:
UG/NX Museum:
To an Engineer, the glass is twice as big as it needs to be.
RE: Creating Points at the maximum distance between 2 splines
Frank Swinkels
RE: Creating Points at the maximum distance between 2 splines
CODE -->
Option Strict Off Imports System Imports NXOpen Imports NXOpen.UI Imports NXOpen.UF Module MaximumDistanceSplines Dim s As Session = Session.GetSession() Dim ufs As UFSession = UFSession.GetUFSession() Dim workPart As Part = s.Parts.Work Dim lw As ListingWindow = s.ListingWindow Sub Main() Dim spline1 As NXOpen.Tag = NXOpen.Tag.Null Dim spline2 As NXOpen.Tag = NXOpen.Tag.Null Dim response1 As NXOpen.Selection.Response = Selection.Response.Cancel Dim response2 As NXOpen.Selection.Response = Selection.Response.Cancel Dim title1 As String = "Select Spline 1" Dim title2 As String = "Select Spline 2" start1: response1 = select_spline(spline1, title1) If response1 = Selection.Response.Cancel Then Exit Sub If response1 = Selection.Response.Back Then Exit Sub response2 = select_spline(spline2, title2) If response2 = Selection.Response.Cancel Then Exit Sub If response2 = Selection.Response.Back Then GoTo start1 Dim lowerparm As Double = 0.0 Dim upperparm As Double = 1.0 Dim lowerdistance As Double = 0.0 Dim upperdistance As Double = 0.0 Dim middistance As Double = 0.0 Dim cnt2 As Integer = 0 Dim pt1(2), pt2(2), pt3(2) As Double ' first iteration determineNewLimits(spline1, spline2, lowerparm, upperparm, lowerdistance, middistance, upperdistance, pt1, pt2, pt3) Dim testdel As Double = Math.Abs((lowerdistance + upperdistance) / 2.0 - middistance) While testdel > 0.0001 determineNewLimits(spline1, spline2, lowerparm, upperparm, lowerdistance, middistance, upperdistance, pt1, pt2, pt3) testdel = Math.Abs((lowerdistance + upperdistance) / 2.0 - middistance) cnt2 += 1 If cnt2 > 10 Then Exit While End While ' create the points Dim temptag As Tag = NXOpen.Tag.Null ufs.Curve.CreatePoint(pt1, temptag) ufs.Curve.CreatePoint(pt2, temptag) ufs.Curve.CreatePoint(pt3, temptag) End Sub Sub determineNewLimits(ByVal spline1 As Tag, ByVal spline2 As Tag, ByRef lowerparm As Double, ByRef upperparm As Double, _ ByRef lowerdistance As Double, ByRef middistance As Double, ByRef upperdistance As Double, _ ByRef point3() As Double, ByRef point4() As Double, ByRef point5() As Double) Dim junk3(2) As Double Dim junk As Double Dim vec1(2), vec2(2), vec3(2), vec4(2) As Double Dim unitv0(2), unitv1(2), unitv2(2), unitv3(2), unitv4(2) As Double Dim point1(2), point2(2) As Double Dim parm1, parm2 As Double Dim l0, l1, l2, del1, del2 As Double Dim distances1(10) As Double Dim parms1(10) As Double Dim parms2(10) As Double Dim cnt1 As Integer = 0 Dim delparm As Double = (upperparm - lowerparm) / 10.0 For parm As Double = lowerparm + delparm To upperparm - delparm Step delparm cnt1 += 1 ufs.Modl.AskCurveProps(spline1, parm, point1, vec1, junk3, junk3, junk, junk) ufs.Modl.AskCurveProps(spline2, parm, point2, vec2, junk3, junk3, junk, junk) ufs.Vec3.Sub(point1, point2, vec3) ufs.Vec3.Unitize(vec3, 0.001, l0, unitv1) l0 /= 2.0 point3(0) = (point1(0) + point2(0)) / 2.0 point3(1) = (point1(1) + point2(1)) / 2.0 point3(2) = (point1(2) + point2(2)) / 2.0 ufs.Modl.AskCurveParm(spline1, point3, parm1, point4) If parm1 < 0 Or parm1 > 1 Then Continue For ufs.Vec3.Distance(point3, point4, l1) ufs.Modl.AskCurveParm(spline2, point3, parm2, point5) If parm2 < 0 Or parm2 > 1 Then Continue For ufs.Vec3.Distance(point3, point5, l2) del1 = l1 - l2 del2 = Math.Abs(del1) Dim cnt2 As Integer = 0 While del2 > 0.001 l0 = l0 + del1 / 2.0 ufs.Vec3.AffineComb(point2, l0, unitv1, point3) ufs.Modl.AskCurveParm(spline1, point3, parm1, point4) If parm1 < 0 Or parm1 > 1 Then Continue For ufs.Modl.AskCurveParm(spline2, point3, parm2, point5) If parm2 < 0 Or parm2 > 1 Then Continue For ufs.Vec3.Distance(point3, point4, l1) ufs.Modl.AskCurveParm(spline2, point3, parm2, point5) If parm2 < 0 Or parm2 > 1 Then Continue For ufs.Vec3.Distance(point3, point5, l2) del1 = l1 - l2 del2 = Math.Abs(del1) cnt2 += 1 If cnt2 > 10 Then MsgBox("Not converging") Exit Sub End If End While distances1(cnt1) = l1 + l2 parms1(cnt1) = parm1 parms2(cnt1) = parm2 Next ufs.Disp.SetHighlight(spline1, 0) ufs.Disp.SetHighlight(spline2, 0) distances1(0) = lowerparm distances1(10) = upperparm For i As Integer = 2 To 8 If distances1(i - 2) < distances1(i - 1) And distances1(i - 1) > distances1(i) Then lowerparm = lowerparm + delparm * (i - 2) upperparm = lowerparm + delparm * i lowerdistance = distances1(i - 2) middistance = distances1(i - 1) upperdistance = distances1(i) Exit For End If Next End Sub Function select_spline(ByRef spline As NXOpen.Tag, ByVal title As String) _ As Selection.Response Dim mssg As String = "Mid Points:" Dim scope As Integer = UFConstants.UF_UI_SEL_SCOPE_ANY_IN_ASSEMBLY Dim response As Integer Dim view As NXOpen.Tag Dim cursor(2) As Double Dim mask_splines As UFUi.SelInitFnT = AddressOf mask_for_splines ufs.Ui.LockUgAccess(UFConstants.UF_UI_FROM_CUSTOM) Try ufs.Ui.SelectWithSingleDialog(mssg, title, scope, mask_splines, _ Nothing, response, spline, cursor, view) Finally ufs.Ui.UnlockUgAccess(UFConstants.UF_UI_FROM_CUSTOM) End Try If response <> UFConstants.UF_UI_OBJECT_SELECTED And _ response <> UFConstants.UF_UI_OBJECT_SELECTED_BY_NAME Then Return Selection.Response.Cancel ElseIf response = Selection.Response.Back Then Return Selection.Response.Back Else Return Selection.Response.Ok End If End Function Function mask_for_splines(ByVal select_ As IntPtr, _ ByVal userdata As IntPtr) As Integer Dim num_triples As Integer = 1 Dim mask_triples(0) As UFUi.Mask mask_triples(0).object_type = UFConstants.UF_spline_type mask_triples(0).object_subtype = UFConstants.UF_spline_subtype mask_triples(0).solid_type = 0 ufs.Ui.SetSelMask(select_, _ UFUi.SelMaskAction.SelMaskClearAndEnableSpecific, _ num_triples, mask_triples) Return UFConstants.UF_UI_SEL_SUCCESS 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 ModuleRegards
Frank Swinkels