×
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

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

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

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

(OP)
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

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

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

www.nxjournaling.com

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

(OP)
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....


regards Lklo

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

(OP)

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 

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

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

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

(OP)
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

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! Already a Member? Login


Resources

eBook - Manufacturing the Cars of Tomorrow
In this ebook, we'll explore how additive manufacturing is going to transform the way cars are made. This includes commentary from thought leaders such as Ford's CTO, Ken Washington, Customer case studies of ways 3D printing is being used today, and a variety of part examples where 3D printing is already impacting how automobiles are made. Download Now
White Paper - Smart Manufacturing for Semiconductor
New technologies and approaches present great opportunities for semiconductor manufacturers to achieve high levels of innovation, yield and improvement. This white paper explores some of these cutting-edge technologies and how they can be applied effectively in the semiconductor industry. Read about how Smart Manufacturing is transforming the semiconductor industry. Download Now
White Paper - Analysis and Simulation in Aircraft Structure Certification
Organizations using simulation and analysis tools effectively see the benefits in their ability to achieve certification faster and with drastically less total cost than those who do not maximize these tools. Read this White Paper to learn about how digital tools such as analysis and simulation help in aircraft structure certification. Download Now

Close Box

Join Eng-Tips® Today!

Join your peers on the Internet's largest technical engineering professional community.
It's easy to join and it's free.

Here's Why Members Love Eng-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close