Continue to Site

Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

  • Congratulations SSS148 on being selected by the Eng-Tips community for having the most helpful posts in the forums last week. Way to Go!

Simple way to create spline normal to face? , NX7.5

Status
Not open for further replies.

Toost

Mechanical
Jan 18, 2011
2,993
I got the question on how to, fast & simple, create a spline which is normal to a face in both ends.
See attached example. The example is "exaggerated" to illustrate the question. In one end of the spline it should start at the end of the lines on top of the block, normal to the block, in the other end at the point, normal to the cylinder at the point.
I have not found a simple way of doing this in NX7.5, i.e without creating a number of helper lines to snap the tangent to. ( NX7.5 is our production release at the moment) Neither have i found a way of reversing a tangent if the tangent goes "the opposite".

Any ideas ?
- The simpler the better.

( And yes, the real model will look something similar, the splines represent wires. )

Regards,
Tomas
 
Replies continue below

Recommended for you

There is no "fast & simple" method to do what you want without the help some sort of additional geometry, either something that can be referenced as a vector (such as a line normal to the face of the object) or in this case, a pole (a point offset normal to the face of teh object) to control the direction of the start/end of the spline. If you're going to need to do this a lot, I would suggest crating a simple NX Open program to do thi.

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.
 
Here is a journal that creates splines based on two points and two slopes.

I should point a few limitations. This journal only works for NX7.5 because the studio spline function is quite different for NX8 +. I have used a simpler approach in that the user is asked to make 4 selections. The start face, a point object on the start face and an end face and a point on the end face. It is possible to reduce this but makes the journal much longer. When I used the journal on the supplied example one of the splines was not identical as the existing spline. Not sure why this was so.

Anyway here is the journal. I hope it is of some help.

Code:
Option Strict Off
Imports System
Imports NXOpen
Imports NXOpen.UF

Module Spline2Points2Slopes
    Dim s As Session = Session.GetSession()
    Dim ui As UI = UI.GetUI()
    Dim ufs As UFSession = UFSession.GetUFSession()
    Dim workPart As Part = s.Parts.Work
    Sub Main()
        Dim point1 As Point = Nothing
        Dim face1 As Face = Nothing
        Dim point2 As Point = Nothing
        Dim face2 As Face = Nothing
        Dim message1 As String = "Select Start Face"
        Dim message2 As String = "Select Start Point on Start Face"
        Dim message3 As String = "Select End Face"
        Dim message4 As String = "Select End Point on End Face"

        Dim response1 As Selection.Response = Selection.Response.Cancel
        Dim response2 As Selection.Response = Selection.Response.Cancel
        Dim response3 As Selection.Response = Selection.Response.Cancel
        Dim response4 As Selection.Response = Selection.Response.Cancel
start1:
        response1 = select_a_Face(message1, face1)
        If response1 = Selection.Response.Cancel Then GoTo end1
        response2 = select_a_point(message2, point1)
        If response2 = Selection.Response.Cancel Then GoTo end1
        response3 = select_a_Face(message3, face2)
        If response3 = Selection.Response.Cancel Then GoTo end1
        response4 = select_a_point(message4, point2)
        If response4 = Selection.Response.Cancel Then GoTo end1

        ' get the face normals
        Dim normal1 As Vector3d = New Vector3d
        getFaceNormal(point1, face1, normal1)
        Dim normal2 As Vector3d = New Vector3d
        getFaceNormal(point2, face2, normal2)
        ' create the spline
        CreateStudioSpline2Points2Slopes(point1, normal1, point2, normal2)
        GoTo start1
end1:
    End Sub
    Public Sub getFaceNormal(ByVal thepoint As Point, ByVal theface As Face, ByRef normal1 As Vector3d)

        Dim geometricProperties1 As GeometricAnalysis.GeometricProperties = Nothing
        geometricProperties1 = workPart.AnalysisManager.CreateGeometricPropertiesObject()
        Dim myFaceProps As GeometricAnalysis.GeometricProperties.Face = Nothing
        geometricProperties1.GetFaceProperties(theface, thepoint.Coordinates, myFaceProps)
        normal1 = myFaceProps.Normal

    End Sub
    Function select_a_point(ByVal prompt As String, ByRef selpointobj As Point) As Selection.Response

        Dim ui As UI = ui.GetUI()
        Dim selectionMask(0) As Selection.MaskTriple
        With selectionMask(0)
            .Type = UFConstants.UF_point_type
            .Subtype = 0
            .SolidBodySubtype = 0
        End With
        Dim cursor As Point3d = Nothing
        Dim resp As Selection.Response = _
        ui.SelectionManager.SelectTaggedObject(prompt, prompt, _
            Selection.SelectionScope.AnyInAssembly, _
            Selection.SelectionAction.ClearAndEnableSpecific, _
            False, False, selectionMask, selpointobj, 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(message, 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
    Public Sub CreateTempLineforTangents(ByRef pnt As Point, ByRef vec1 As Vector3d, ByVal dir1 As Integer, ByRef ln As Line)
        Dim linestartpnt As Point3d = New Point3d(pnt.Coordinates.X, pnt.Coordinates.Y, pnt.Coordinates.Z)

        Dim unitvector As Vector3d = MyUnitizeVector(vec1)
         Dim negatedvector = MyNegate(unitvector)
        Dim dist1 As Double = 50.0
        Dim lineendpnt As Point3d = MyAffineComb(linestartpnt, dist1, negatedvector)
         Dim id1 As Session.UndoMarkId
        id1 = s.SetUndoMark(Session.MarkVisibility.Visible, "Lines1")
        If dir1 = 1 Then
            ln = workPart.Curves.CreateLine(lineendpnt, linestartpnt)
        Else
            ln = workPart.Curves.CreateLine(linestartpnt, lineendpnt)
        End If
        Dim nErrs1 As Integer
        nErrs1 = s.UpdateManager.DoUpdate(id1)

    End Sub
    Public Function MyNegate(ByVal v1 As Vector3d) As Vector3d
        Dim v2 As Vector3d
        v2.X = -v1.X
        v2.Y = -v1.Y
        v2.Z = -v1.Z
        Return v2
    End Function
    Public Function MyUnitizeVector(ByVal v1 As Vector3d) As Vector3d
        Dim v2 As Vector3d
        Dim length As Double = Math.Sqrt(v1.X * v1.X + v1.Y * v1.Y + v1.Z * v1.Z)
        v2.X = v1.X / length
        v2.Y = v1.Y / length
        v2.Z = v1.Z / length
        Return v2
    End Function
    Public Function MyAffineComb(ByVal p1 As Point3d, ByVal s As Double, ByVal v1 As Vector3d) As Point3d
        Dim p2 As Point3d
        p2.X = p1.X + s * v1.X
        p2.Y = p1.Y + s * v1.Y
        p2.Z = p1.Z + s * v1.Z
        Return p2
    End Function
    Public Sub CreateStudioSpline2Points2Slopes(ByRef point1 As Point, ByRef normal1 As Vector3d, ByRef point2 As Point, _
                                                ByRef normal2 As Vector3d)

        Dim line1 As Line = Nothing
        Dim line2 As Line = Nothing
        Dim dir1 As Integer = 1
        CreateTempLineforTangents(point1, normal1, dir1, line1)
        dir1 = 2
        CreateTempLineforTangents(point2, normal2, dir1, line2)

        Dim scalar1 As Scalar
        scalar1 = workPart.Scalars.CreateScalar(1.0, Scalar.DimensionalityType.None, SmartObject.UpdateOption.WithinModeling)
        Dim direction1 As Direction
        direction1 = workPart.Directions.CreateDirection(line1, scalar1, Direction.OnCurveOption.Tangent, Sense.Forward, SmartObject.UpdateOption.WithinModeling)
        Dim direction2 As Direction
        direction2 = workPart.Directions.CreateDirection(line2, scalar1, Direction.OnCurveOption.Tangent, Sense.Forward, SmartObject.UpdateOption.WithinModeling)
        Dim nullFeatures_StudioSpline As Features.StudioSpline = Nothing
        Dim studioSplineBuilder1 As Features.StudioSplineBuilder
        studioSplineBuilder1 = workPart.Features.CreateStudioSplineBuilder(nullFeatures_StudioSpline)
        studioSplineBuilder1.Associative = False
        studioSplineBuilder1.InputCurveOption = Features.StudioSplineBuilder.CurveOption.Retain
        studioSplineBuilder1.SplineMethod = Features.StudioSplineBuilder.Method.ThroughPoints
        studioSplineBuilder1.Degree = 3
        studioSplineBuilder1.IsPeriodic = False
        studioSplineBuilder1.MatchKnots = Features.StudioSplineBuilder.MatchKnotsType.None
        Dim knots1(-1) As Double
        studioSplineBuilder1.SetKnots(knots1)
        Dim parameters1(-1) As Double
        studioSplineBuilder1.SetParameters(parameters1)

        Dim geometricConstraintData1 As Features.GeometricConstraintData
        geometricConstraintData1 = studioSplineBuilder1.ConstraintManager.CreateGeometricConstraintData()
        geometricConstraintData1.Point = point1
        geometricConstraintData1.AutomaticConstraintDirection = Features.GeometricConstraintData.ParameterDirection.Iso
        geometricConstraintData1.AutomaticConstraintType = Features.GeometricConstraintData.AutoConstraintType.None
        geometricConstraintData1.TangentDirection = direction1
        Dim nullScalar As Scalar = Nothing
        geometricConstraintData1.TangentMagnitude = nullScalar
        Dim nullOffset As Offset = Nothing
        geometricConstraintData1.Curvature = nullOffset
        geometricConstraintData1.CurvatureDerivative = nullOffset
        geometricConstraintData1.HasSymmetricModelingConstraint = False

        Dim geometricConstraintData2 As Features.GeometricConstraintData
        geometricConstraintData2 = studioSplineBuilder1.ConstraintManager.CreateGeometricConstraintData()
        geometricConstraintData2.Point = point2
        geometricConstraintData2.AutomaticConstraintDirection = Features.GeometricConstraintData.ParameterDirection.Iso
        geometricConstraintData2.AutomaticConstraintType = Features.GeometricConstraintData.AutoConstraintType.None
        geometricConstraintData2.TangentDirection = direction2
        geometricConstraintData2.TangentMagnitude = nullScalar
        geometricConstraintData2.Curvature = nullOffset
        geometricConstraintData2.CurvatureDerivative = nullOffset
        geometricConstraintData2.HasSymmetricModelingConstraint = False
        Dim constraints1(1) As Features.GeometricConstraintData
        constraints1(0) = geometricConstraintData1
        constraints1(1) = geometricConstraintData2
        studioSplineBuilder1.ConstraintManager.SetContents(constraints1)

        Dim feature1 As Features.Feature
        feature1 = studioSplineBuilder1.CommitFeature()
        studioSplineBuilder1.Destroy()
        ufs.Obj.DeleteObject(line1.Tag)
        ufs.Obj.DeleteObject(line2.Tag)
    End Sub
    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
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor