×
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

Journal: Getting the source part occurrence of a WAVE link

Journal: Getting the source part occurrence of a WAVE link

Journal: Getting the source part occurrence of a WAVE link

(OP)
Hi,

I'm writing a program to allow the user to select a new source assembly which will automatically re-link all wave links in a part to the new source assembly. That way the user doesn't have to manually re-link every wave link feature when parts/assemblies are copied, renamed etc.

To get the current source part of a wave link feature, I use this:

CODE -->

ufs.Wave.AskLinkSource(in_linkedfeature, in_allowload, out_sourceentity)
Dim outObject As NXObject = NXObjectManager.Get(out_sourceentity)
out_part = outObject.OwningPart 

but out_part is the prototype part. What if there are many instances of the same prototype part, how can I find out which part instance the wave link feature is linking to?

I've tried this:

CODE -->

Dim partocc As Tag = ufs.Assem.AskPartOccurrence(out_sourceentity) 

but it returns null.

NX10.0 Win8.1 64bit i7-3770K 16GB Quadro2000

RE: Journal: Getting the source part occurrence of a WAVE link

Below is a short journal that will find the parent "component" by using the UF function: AskAssyCtxtPartOcc.

To use it, create a small assembly: add a part as a component - specify a number of duplicates (spread them out - use the "scatter" option). Add a new empty part as a component and create a wave linked mirror body feature in the new part; pick any component instance you like to be the parent of the mirror body. Give the "parent component" a unique name, this will help when testing the journal (RMB the component, properties, general, enter name, OK). Run the journal with the assembly as the displayed/work part. The journal will process all the components and report the parent component of the linked mirror body. Parts must be fully loaded for the journal to work, journal only reports the first linked mirror body found in each component. The same strategy will work for other linked features, this journal only looks specifically for linked mirror bodies.

CODE

Option Strict Off
Imports System
Imports NXOpen
Imports NXOpen.Assemblies
Imports NXOpen.UF
 
Module Module1
 
    Dim theSession As Session = Session.GetSession()
    Dim theUfSession As UFSession = UFSession.GetUFSession()
 
    Dim lw As ListingWindow = theSession.ListingWindow
 
    Sub Main()
 
        If IsNothing(theSession.Parts.BaseWork) Then
            'active part required
            Return
        End If
 
        Dim workPart As Part = theSession.Parts.Work
        lw.Open()
 
        Const undoMarkName As String = "NXJ journal"
        Dim markId1 As Session.UndoMarkId
        markId1 = theSession.SetUndoMark(Session.MarkVisibility.Visible, undoMarkName)
 
        Try
            Dim c As ComponentAssembly = theSession.Parts.Display.ComponentAssembly
            If Not IsNothing(c.RootComponent) Then
                'lw.WriteLine("processing components...")
                ProcessChildren(c.RootComponent, 0)
            Else
                '*** insert code to process piece part
                'lw.WriteLine("Part has no components")
            End If
        Catch e As Exception
            theSession.ListingWindow.WriteLine("Failed: " & e.ToString)
        End Try
 
 
        lw.Close()
 
    End Sub
 
    Sub ProcessChildren(ByVal comp As Component, _
    ByVal indent As Integer)
 
        'lw.WriteLine("component: " & comp.DisplayName)
 
        Dim linkedFeature As Features.Feature
 
        For Each child As Component In comp.GetChildren()
            Dim part1 As Part = child.Prototype.OwningPart
            linkedFeature = ProcessFeatures(part1)
            If Not IsNothing(linkedFeature) Then
 
                Dim theXformTag As Tag
                Dim fromPartOccTag As Tag
                Dim fromComp As Assemblies.Component
 
                theUfSession.Wave.AskLinkXform(linkedFeature.Tag, theXformTag)
                theUfSession.So.AskAssyCtxtPartOcc(theXformTag, child.Tag, fromPartOccTag)
 
                fromComp = Utilities.NXObjectManager.Get(fromPartOccTag)
 
                lw.WriteLine("linked from part: " & fromComp.Prototype.OwningPart.Leaf & " [component name: " & fromComp.Name & "]")
                lw.WriteLine("")
 
            End If
            ProcessChildren(child, indent + 1)
        Next
 
    End Sub
 
    Function ProcessFeatures(ByVal thePart As Part) As Features.Feature
 
        'return first linked mirror feature
 
        For Each myfeature As Features.Feature In thePart.Features
 
            If myfeature.FeatureType = "LINKED_MIRROR" Then
                lw.WriteLine("linked mirror body feature found in part: " & thePart.Leaf)
                Return myfeature
            End If
 
        Next
 
        Return Nothing
 
    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

RE: Journal: Getting the source part occurrence of a WAVE link

(OP)
Thanks cowski, that helps.

However, here is a situation where AskAssyCtxtPartOcc fails:

Create an assembly like this:

MAIN.PRT
SOURCE1.PRT
A.PRT
A.PRT
A.PRT
A.PRT (A-4)
A.PRT
SOURCE2.PRT
A.PRT
A.PRT
A.PRT
A.PRT (A-4)
A.PRT
B.PRT

Suppress SOURCE2.PRT. Create the linked mirror body to A-4 from SOURCE1.PRT. Run your journal (include code to ignore suppressed parts, like If child.Prototype.OwningPart IsNot Nothing Then).
The journal works fine.
Now suppress SOURCE1.PRT and unsuppress SOURCE2.PRT. Run the journal again. Now AskAssyCtxtPartOcc gives null.

Is there a way to find the identical A-4 from SOURCE2?

NX10.0 Win8.1 64bit i7-3770K 16GB Quadro2000

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