Continue to Site

Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

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

Extract the Tag from the associated Drafting Entity from a selected Drafting Entity...

Status
Not open for further replies.

lklo

Industrial
Nov 24, 2010
226
Hi -
In NXOpen - VB.Net I will kindly ask one of you guy's:

I'm trying to get the Tag from the associated Drafting Entity, when a selected Drafting entity is picked on the active NX drawingsheet....

1.Say I have "Dimension 1" which is associated to antoher dimension (Dimension 2).... ( Horizontal alligned, Vertical alligned, Stacked etc. )
I would like to get the Tag of Dimension 2 , when I pick Dimension 1....
I am able to get the boolean Value - True or False, if I pick Dimension 1, by using "myDimension.HasAssociativeOrigin"...
But I am strugling a bit, to figure out, on also to get the Tag of the Dimension 2

If any of you have a direction, I can follow, please comment...
regards Lklo
 
Replies continue below

Recommended for you

The .GetAssociativeOrigin method will return information about the type of association and the annotation that it is associated to.

www.nxjournaling.com
 
Hi Cowski -

As always - thanks a lot for your reply , when I ask here at EngTips....

I have already tried the method: GetAssociativeOrigin , but I will give it yet another try tommorrow...
I can get a lot of information out of this method - but not the Tag itself from the Annotation that my dimension is associated to....
2019-07-15_16_31_06-NX11_NXOpen_.Net_API_References_phsjcp.jpg


regards Lklo
 
Code:
Option Strict Off
Imports System
Imports NXOpen
Imports NXOpen.UF
Imports NXOpen.Drawings
'Imports NXOpen.Assemblies
'Imports NXOpen.PDM
'Imports System.Collections
'Imports System.Collections.Generic
Imports NXOpen.Annotations
Imports System.Text
Imports NXOpen.Utilities
'Imports System.Text.RegularExpressions
'Imports System.Diagnostics
'Imports NXOpen.Routing
'Imports NXOpen.Features



Module Lkl_Summary_TabNote

    Dim theSession As Session = Session.GetSession()
    Dim theUI As UI = UI.GetUI()
    Dim workPart As Part = theSession.Parts.Work
    Dim displayPart As Part = theSession.Parts.Display
    Dim ufs As UFSession = UFSession.GetUFSession()
    Dim output_To_NXListingWindow As Boolean = True
    Dim output_To_NXLogFile As Boolean = True

    Sub Main()
        ufs.Ui.ExitListingWindow() ' close windows before displaying it again
        'START HERE

        Report_Object()

    End Sub



    '=========================== NX LISTING WINDOW FUNCTION=======================================

    Public Sub NX(ByVal input As String) '' output variable listwindow - just for building VB

        If output_To_NXListingWindow Then
            Dim displayPart As Part = theSession.Parts.Display
            Dim lw As ListingWindow = theSession.ListingWindow()
            lw.Open()
            lw.WriteLine(input)
        End If

    End Sub
    '===============================================================================================

    '=========================== NX WRITE TO LOGFILE FUNCTION=======================================

    Public Sub NX_log(ByVal input As String) '' output variable listwindow - just for building VB

        If output_To_NXLogFile Then
            theSession.LogFile.WriteLine(input)
        End If

    End Sub
    '================================================================================================

    '=========================== NX UNLOAD FUNCTION ================================================

    Public Function GetUnloadOption(ByVal dummy As String) As Integer

        GetUnloadOption = NXOpen.Session.LibraryUnloadOption.Immediately
        'GetUnloadOption = NXOpen.Session.LibraryUnloadOption.AtTermination ' typically used in Checkmate only

    End Function
    '================================================================================================

    '======================================   SELECTION MASK   ========================================

    Function select_a_DraftingEntity(ByVal prompt As String, ByRef TagOfDrfEntity As DisplayableObject, ByRef cursor As Point3d)

        '-------------------------------------------------------------------------------------------------------
        ' Start define type Mask......Lets define which drafting entities to be able to select...

        'how may Drafting entities to select....
        Dim mask(5) As Selection.MaskTriple

        'Dimension > PerpendicularDimension: Type:26, SubType: 5
        'HorizontalDimension: Type:26, SubType: 1
        With mask(0)
            .Type = UFConstants.UF_dimension_type
            .Subtype = 0
            .SolidBodySubtype = 0
        End With

        'DraftingFcf  > Type:25, SubType: 4
        'DraftingDatum > Type:25, SubType: 4
        With mask(1)
            .Type = UFConstants.UF_drafting_entity_type '25
            .Subtype = 4
            .SolidBodySubtype = 0
        End With

        'LineWeld > Type:25, SubType: 2
        With mask(2)
            .Type = UFConstants.UF_drafting_entity_type '25
            .Subtype = 2
            .SolidBodySubtype = 0
        End With

        'DraftingSurfaceFinish > Type:158, SubType: 2
        With mask(3)
            .Type = 158
            .Subtype = 2
            .SolidBodySubtype = 0
        End With

        'IdSymbol > Type: 25, SubType: 3
        With mask(4)
            .Type = 25
            .Subtype = 3
            .SolidBodySubtype = 0
        End With

        'CustomSymbol > Type: 25, SubType: 30
        With mask(5)
            .Type = 25
            .Subtype = 10
            .SolidBodySubtype = 0
        End With

        '
       ' End of type Mask......
        '-------------------------------------------------------------------------------------------------------

        Dim resp As Selection.Response =
    theUI.SelectionManager.SelectTaggedObject(prompt, prompt,
        Selection.SelectionScope.AnyInAssembly,
        Selection.SelectionAction.ClearAndEnableSpecific,
        False, False, mask, TagOfDrfEntity, 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

    '===============================================================================================

    '=============================================================================================

    Public Sub Report_Object()


        Dim cursor As Point3d = Nothing
        Dim draftingEntity As DisplayableObject = Nothing

        While select_a_DraftingEntity("Select a Drafting Object for Reporting info", draftingEntity, cursor) = Selection.Response.Ok

            'here we output the Tag of the selected Drafting Object - dimension, weld symbol, GDT; etc...
            NX("Tag of selected Drafing Entity :" & draftingEntity.Tag)
            Dim mySelectedDraftEntity As Annotation = Utilities.NXObjectManager.Get(draftingEntity.Tag)
            NX("")
            'the Object Type to string...
            Dim DraftEntityType As String = (mySelectedDraftEntity.GetType.ToString).Split(".")(2)
            NX("Drafting entity Type :" & DraftEntityType)
            NX("")

            'lets find the Type
            'Dimension = type 26 
            'DraftingFcf = type 25
            'DraftingDatum = type 25
            'LineWeld = type 25
            'DraftingSurfaceFinish = type 158
            'IdSymbol = type 25
            'CustomSymbol = type 25

            Dim type As Integer
            Dim subtype As Integer
            ufs.Obj.AskTypeAndSubtype(mySelectedDraftEntity.Tag, type, subtype)
            NX(type)

            Select Case type

                '--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
                Case = 26 'if Dimension

                    Dim myDimension As Annotations.Dimension = Utilities.NXObjectManager.Get(mySelectedDraftEntity.Tag)
                    Dim mainText() As String = Nothing
                    Dim dualText() As String = Nothing
                    Dim myUpperTolerance As Double = Nothing
                    Dim myLowerTolerance As Double = Nothing


                    myDimension.GetDimensionText(mainText, dualText)
                    myUpperTolerance = myDimension.UpperMetricToleranceValue
                    myLowerTolerance = myDimension.LowerMetricToleranceValue

                    NX(mainText.Length)
                    NX(dualText.Length)
                    NX("Dimension Main Text :" & mainText(0))
                    ' NX("Dimension Dual Text :" & dualText(0))
                    NX("UpperTolerance :" & myUpperTolerance)
                    NX("LowerTolerance :" & myLowerTolerance)

                    'lets try extract the Object the dimension is associated to...

                    Dim myNumberOfAsso As Integer = myDimension.NumberOfAssociativities
                    Dim anAsso As Associativity

                    NX("have associated origin :" & myDimension.HasAssociativeOrigin)
                    NX("number of associatives :" & myNumberOfAsso)

                    'lets try UFS instead..
                    Dim myData() As UFDrf.ObjectAssocData = Nothing
                    For i As Integer = 1 To myNumberOfAsso
                        anAsso = myDimension.GetAssociativity(i)
                        NX(anAsso.ToString)
                        ufs.Drf.AskAssociativityData(myDimension.Tag, i, myData)
                        NX(myData.Length)

                        anAsso = myDimension.GetAssociativity(1)
                        Dim obj As NXObject = anAsso.FirstObject
                        NX(obj.Tag)
                        NX(obj.ToString)

                        ' hmmm - how to extract info from the "myData" array...?
                    Next





                    '--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

            End Select

            NX("=====================================")

        End While

    End Sub

    '=============================================================================================
End Module
 
Below is some code that I wrote a while back that may help. It runs through all the dimensions in the part and reports the associativity.

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

Module Module1

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

    Dim theUI As UI = UI.GetUI()
    Dim lw As ListingWindow = theSession.ListingWindow

    Sub Main()

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

        lw.Open()

        For Each tempDim As Annotations.Dimension In theSession.Parts.Work.Dimensions
            lw.WriteLine("dim tag: " & tempDim.Tag.ToString)
            lw.WriteLine("has associative origin: " & tempDim.HasAssociativeOrigin.ToString)

            If tempDim.HasAssociativeOrigin Then
                Dim tempOrigin As Point3d
                Dim tempAssOriginData As Annotations.Annotation.AssociativeOriginData
                tempAssOriginData = tempDim.GetAssociativeOrigin(tempOrigin)

                lw.WriteLine("associative origin type: " & tempAssOriginData.OriginType.ToString)
                Select Case tempAssOriginData.OriginType
                    Case Is = Annotations.AssociativeOriginType.Drag

                    Case Is = Annotations.AssociativeOriginType.RelativeToView

                    Case Is = Annotations.AssociativeOriginType.RelativeToGeometry

                    Case Is = Annotations.AssociativeOriginType.VerticallyAligned
                        Dim alignedAnnotation As Annotations.Annotation = Nothing
                        alignedAnnotation = tempAssOriginData.VertAnnotation
                        lw.WriteLine("aligned to annotation: " & alignedAnnotation.Tag.ToString)

                    Case Is = Annotations.AssociativeOriginType.HorizontallyAligned
                        Dim alignedAnnotation As Annotations.Annotation = Nothing
                        alignedAnnotation = tempAssOriginData.HorizAnnotation
                        lw.WriteLine("aligned to annotation: " & alignedAnnotation.Tag.ToString)

                    Case Is = Annotations.AssociativeOriginType.AlignedWithArrows
                        Dim alignedAnnotation As Annotations.Annotation = Nothing
                        alignedAnnotation = tempAssOriginData.AlignedAnnotation
                        lw.WriteLine("aligned to annotation: " & alignedAnnotation.Tag.ToString)

                    Case Is = Annotations.AssociativeOriginType.AtAPoint
                        Dim associatedPoint As Point = Nothing
                        associatedPoint = tempAssOriginData.AssociatedPoint
                        lw.WriteLine("aligned to point: " & associatedPoint.Tag.ToString)
                        lw.WriteLine("  " & associatedPoint.Coordinates.ToString)

                    Case Is = Annotations.AssociativeOriginType.OffsetFromText

                    Case Is = Annotations.AssociativeOriginType.AttachedToStack


                End Select

            End If

            If tempDim.IsRetained Then
                lw.WriteLine("dim is retained")
            Else
                lw.WriteLine("dim is NOT retained")
            End If

            lw.WriteLine("")

        Next

        lw.Close()

    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

www.nxjournaling.com
 
hi Cowski -

Thank you so much....Your code snippet is Exactly what I need...
I did try play with "GetAssociativeOrigin" before my initial post here - But I totally missed, that the Tag's of the different allignMethods,
would point directly to the Annotation, that is Associated To....
Thanks again..

best regards...Lars
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor