Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

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

DatumPlane

Status
Not open for further replies.

EngProgrammer

Aerospace
Joined
Jan 14, 2015
Messages
150
Location
US
How do I get a handle on the DatumPlane that is in the workpart. I developed this code and having a problem debugging it.

Code:
    Function GetDatumPlanes(ByVal in_part As Part) As DatumPlane()
        Dim a_DatumPlane As Tag = NXOpen.Tag.Null
        Dim type, subtype As Integer
        Dim bList As ArrayList = New ArrayList

        Do
            theUFsession.Obj.CycleObjsInPart(in_part.Tag, _
                UFConstants.UF_datum_plane_type, a_DatumPlane)
            If Not a_DatumPlane.Equals(NXOpen.Tag.Null) Then
                theUFsession.Obj.AskTypeAndSubtype(a_DatumPlane, type, subtype)
                If subtype = UFConstants.UF_datum_object_subtype Then
                    bList.Add(Utilities.NXObjectManager.Get(a_DatumPlane))
                End If
            End If
        Loop While Not a_DatumPlane.Equals(NXOpen.Tag.Null)

        Return bList.ToArray(GetType(DatumPlane))

    End Function
 
Below are two methods:

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 = "report datum planes"
        Dim markId1 As Session.UndoMarkId
        markId1 = theSession.SetUndoMark(Session.MarkVisibility.Visible, undoMarkName)

        Dim myPlanes As New List(Of DatumPlane)
        myPlanes = GetDatumPlanes(workPart)
        lw.WriteLine("number of datum planes: " & myPlanes.Count.ToString)

        Dim myPlanes2 As New List(Of DatumPlane)
        myPlanes2 = GetDatumPlanes2(workPart)
        lw.WriteLine("number of datum planes: " & myPlanes2.Count.ToString)

        lw.Close()

    End Sub

    Function GetDatumPlanes(ByVal thePart As Part) As List(Of DatumPlane)

        Dim theDatumPlanes As New List(Of DatumPlane)

        For Each temp As DisplayableObject In thePart.Datums
            If TypeOf (temp) Is DatumPlane Then
                theDatumPlanes.Add(temp)
            End If
        Next

        Return theDatumPlanes

    End Function

    Function GetDatumPlanes2(ByVal thePart As Part) As List(Of DatumPlane)

        Dim theDatumPlanes As New List(Of DatumPlane)
        Dim a_DatumPlane As Tag = NXOpen.Tag.Null

        Do
            theUfSession.Obj.CycleObjsInPart(thePart.Tag, UFConstants.UF_datum_plane_type, a_DatumPlane)
            If Not a_DatumPlane.Equals(NXOpen.Tag.Null) Then
                theDatumPlanes.Add(Utilities.NXObjectManager.Get(a_DatumPlane))
            End If
        Loop While Not a_DatumPlane.Equals(NXOpen.Tag.Null)

        Return theDatumPlanes

    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

www.nxjournaling.com
 
How about just "workpart.Datums"? I just looked at that and it gives me all the datums within the workpart. Sorry for the post. I was making it more complicated than it needed to be.
 
That's the method I used in the GetDatumPlanes function above; the Datums collection holds datum planes and axes (possibly csys and points as well), you'll need to sort out the planes from the rest.

www.nxjournaling.com
 
Status
Not open for further replies.

Similar threads

Part and Inventory Search

Sponsor

Back
Top