Continue to Site

Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

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

NXOpen Getting Feature Assoicated with Dimension

Status
Not open for further replies.

EngProgrammer

Aerospace
Jan 14, 2015
150
Dear Forum,

Is there a way to get a particular feature attached to a dimension with NXOpen? Say for example, I have a drawing dimension that is associated with a hole feature is there a way through NXOpen to get the instance feature(s) that the extension lines of the dimensions are attached too??

Any ideas?

Thanks
 
Replies continue below

Recommended for you

Drawing dimensions are attached to geometry, not directly to features. I'd guess that you would have to relate the drafting curve back to an edge or face in the model and from there determine which feature created the edge/face. Not impossible, but probably not easy either.

What version of NX?

www.nxjournaling.com
 
I tried something similar with PMI in a model but couldn't find a way to get the feature. I ended up using the position of the end of the arrow to match up with the point I was trying to find.

Mike Hyde
NX8.5 with TC9.1
Moving to NX10 with TC11.2
 
Below is some quick "proof of concept" code. Start a new file, create a block and make a hole feature in the block, switch to drafting, create a view and a dimension between an edge of the block and the hole center; when you run the journal it will report what feature edges the dimension is attached to. The code isn't bulletproof, there are many things that will cause this version to fail or return unexpected results (such as dimensioning to the center mark rather than the hole center point).

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

Module Module1

    Sub Main()

        Dim theSession As Session = Session.GetSession()
        Dim theUfSession As UFSession = UFSession.GetUFSession()
        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 = "dimension -> feature(s)"
        Dim markId1 As Session.UndoMarkId
        markId1 = theSession.SetUndoMark(Session.MarkVisibility.Visible, undoMarkName)

        Dim theDimension As Annotations.Dimension
        If SelectDimension("Select a drafting dimension", theDimension) = Selection.Response.Cancel Then
            Return
        End If

        lw.WriteLine("number of associativities: " & theDimension.NumberOfAssociativities.ToString)
        If theDimension.NumberOfAssociativities > 0 Then
            Dim firstA As Annotations.Associativity = theDimension.GetFirstAssociativity
            If Not IsNothing(firstA.FirstObject) Then
                lw.WriteLine("first object: " & firstA.FirstObject.GetType.ToString)
                If TypeOf (firstA.FirstObject) Is Edge Then
                    Dim edgeFeatureList() As Tag
                    theUfSession.Modl.AskEdgeFeats(firstA.FirstObject.Tag, edgeFeatureList)
                    For Each temp As Tag In edgeFeatureList
                        Dim edgeFeat As Features.Feature = Utilities.NXObjectManager.Get(temp)
                        lw.WriteLine("  feature: " & edgeFeat.GetFeatureName)
                    Next
                End If
            Else
                lw.WriteLine("first object is NOTHING")
            End If
        End If

        If theDimension.NumberOfAssociativities > 1 Then
            Dim secondA As Annotations.Associativity = theDimension.GetSecondAssociativity
            If Not IsNothing(secondA.FirstObject) Then
                lw.WriteLine("second object: " & secondA.FirstObject.GetType.ToString)
                If TypeOf (secondA.FirstObject) Is Edge Then
                    Dim edgeFeatureList() As Tag
                    theUfSession.Modl.AskEdgeFeats(secondA.FirstObject.Tag, edgeFeatureList)
                    For Each temp As Tag In edgeFeatureList
                        Dim edgeFeat As Features.Feature = Utilities.NXObjectManager.Get(temp)
                        lw.WriteLine("  feature: " & edgeFeat.GetFeatureName)
                    Next
                End If

            Else
                lw.WriteLine("second object is NOTHING")
            End If
        End If

        lw.Close()

    End Sub

    Function SelectDimension(ByVal prompt As String, ByRef selDim As Annotations.Dimension) As Selection.Response

        Dim selObj As TaggedObject = Nothing
        Dim theUI As UI = UI.GetUI
        Dim title As String = "Select a drafting dimension"
        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

        With selectionMask_array(0)
            .Type = UFConstants.UF_dimension_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
            selDim = Utilities.NXObjectManager.Get(selObj.Tag)
            Return Selection.Response.Ok
        Else
            Return Selection.Response.Cancel
        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

www.nxjournaling.com
 
thanks cowski. These are the nuggets of code I am looking for. Thank you.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor