×
INTELLIGENT WORK FORUMS
FOR ENGINEERING PROFESSIONALS

Log In

Come Join Us!

Are you an
Engineering professional?
Join Eng-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Eng-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Jobs

Automatic Datum Axis Creation

Automatic Datum Axis Creation

Automatic Datum Axis Creation

(OP)
Dear All,

I need help for the journal or other type of NX custom for Automatic Datum Axis Creation,
In my case I have 8-points that connected with one to another with curves, it will looked like this picture, only one click will automatically created the datum axis. I have tried using macro approach, but fail. Somebody please give suggestions.

Thanks,
MAR.

RE: Automatic Datum Axis Creation

Maybe something like this:

CODE

Option Strict Off
Imports System
Imports System.Collections.Generic
Imports NXOpen
Imports NXOpen.UF

Module Module1
    Dim theSession As Session = Session.GetSession()
    Dim theUfSession As UFSession = UFSession.GetUFSession

    Sub Main()

        If IsNothing(theSession.Parts.BaseWork) Then
            'active part required
            Return
        End If

        Dim workPart As Part = theSession.Parts.Work
        Dim lw As ListingWindow = theSession.ListingWindow
        lw.Open()

        Const undoMarkName As String = "NXJ journal"
        Dim markId1 As Session.UndoMarkId
        markId1 = theSession.SetUndoMark(Session.MarkVisibility.Visible, undoMarkName)

        Dim myPt As Point = Nothing

        If SelectPoint("select a point", myPt) = Selection.Response.Cancel Then
            Return
        End If

        lw.WriteLine("point selected: " & myPt.Coordinates.ToString)

        Dim theLines As New List(Of LineRay)

        For Each tempLine As Line In workPart.Lines

            If PointsEqual(tempLine.StartPoint, myPt.Coordinates) Then
                theLines.Add(New LineRay(tempLine, False))
                Continue For
            End If

            If PointsEqual(tempLine.EndPoint, myPt.Coordinates) Then
                theLines.Add(New LineRay(tempLine, True))
            End If

        Next

        lw.WriteLine("number of lines from point: " & theLines.Count.ToString)

        For Each temp As LineRay In theLines

            Dim nullFeatures_Feature As Features.Feature = Nothing
            Dim datumAxisBuilder1 As Features.DatumAxisBuilder
            datumAxisBuilder1 = workPart.Features.CreateDatumAxisBuilder(nullFeatures_Feature)

            datumAxisBuilder1.CurveOrientation = Features.DatumAxisBuilder.CurveOrientations.Normal
            If temp.Reverse Then
                datumAxisBuilder1.IsAxisReversed = True
            End If
            datumAxisBuilder1.IsAssociative = True

            Dim added1 As Boolean
            added1 = datumAxisBuilder1.Objects.Add(temp.Line)

            datumAxisBuilder1.ArcLength.Update(GeometricUtilities.OnPathDimensionBuilder.UpdateReason.Path)

            Dim nXObject1 As NXObject
            nXObject1 = datumAxisBuilder1.Commit()

            datumAxisBuilder1.Destroy()

        Next

        lw.Close()

    End Sub

    Function SelectPoint(ByVal prompt As String, ByRef selPt As Point) As Selection.Response

        Dim theUI As UI = UI.GetUI
        Dim title As String = "Select a point"
        Dim includeFeatures As Boolean = False
        Dim keepHighlighted As Boolean = False
        Dim selAction As Selection.SelectionAction = Selection.SelectionAction.ClearAndEnableSpecific
        Dim cursor As Point3d
        Dim scope As Selection.SelectionScope = Selection.SelectionScope.WorkPart
        Dim selectionMask_array(0) As Selection.MaskTriple
        Dim selObj As TaggedObject

        With selectionMask_array(0)
            .Type = UFConstants.UF_point_type
            .Subtype = UFConstants.UF_all_subtype
        End With

        Dim resp As Selection.Response = theUI.SelectionManager.SelectTaggedObject(prompt, _
         title, scope, selAction, _
         includeFeatures, keepHighlighted, selectionMask_array, _
         selobj, cursor)
        If resp = Selection.Response.ObjectSelected OrElse resp = Selection.Response.ObjectSelectedByName Then
            selPt = Utilities.NXObjectManager.Get(selObj.Tag)
            Return Selection.Response.Ok
        Else
            Return Selection.Response.Cancel
        End If

    End Function

    Function PointsEqual(ByVal pt1 As Point3d, ByVal pt2 As Point3d) As Boolean

        Dim modTol As Double
        theUfSession.Modl.AskDistanceTolerance(modTol)

        If Math.Abs(pt1.X - pt2.X) <= modTol AndAlso Math.Abs(pt1.Y - pt2.Y) <= modTol AndAlso Math.Abs(pt1.Z - pt2.Z) <= modTol Then
            Return True
        Else
            Return False
        End If


    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



Class LineRay

    Private _line As Line
    Public ReadOnly Property Line() As Line
        Get
            Return _line
        End Get
    End Property

    Private _reverse As Boolean
    Public ReadOnly Property Reverse() As Boolean
        Get
            Return _reverse
        End Get
    End Property

    Sub New(ByVal theLine As Line, ByVal reverseIt As Boolean)

        _line = theLine
        _reverse = reverseIt


    End Sub

End Class 

www.nxjournaling.com

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Eng-Tips Forums free from inappropriate posts.
The Eng-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Eng-Tips forums is a member-only feature.

Click Here to join Eng-Tips and talk with other members!


Resources