×
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

Get all components in an assembly

Get all components in an assembly

Get all components in an assembly

(OP)
Does anyone know an easy way using NXOpen to get all the components in an assembly (including subassemblies) saved to an array?  I like to sort the assembly tree in descending order and then export it to a spreadsheet.  I would ideally like to get that same structure/order, but I need it in NXOPen variables so that I can manipulate the data.

Thanks

RE: Get all components in an assembly

There's an example of what you want to do in the GTAC API library...

RE: Get all components in an assembly

(OP)
In NXOpen, let's say you have a component 'c' which is part of a multi-level assembly.  When using the assembly navigator, you can 'Pack All' and it will group identical components together in each sub-assembly and put a 'x 2', or whatever, indicating how many of those components are in a particular sub-assembly.  How can I get that number for component 'c' with NXOpen?

RE: Get all components in an assembly

The journal below shows one method to get this info. It is probably not the recommended method, and it only works on loaded components.

CODE


Option Strict Off  

Imports System  
Imports NXOpen  
Imports NXOpen.UF  
Imports NXOpen.Assemblies  

Module NXJournal  

    Public theSession As Session = Session.GetSession()  
    Public ufs As UFSession = UFSession.GetUFSession()  
    Public lw As ListingWindow = theSession.ListingWindow  

    Sub Main()  
        Dim workPart As Part = theSession.Parts.Work  
        Dim dispPart As Part = theSession.Parts.Display  

        lw.Open()  
        Try  
            Dim c As ComponentAssembly = dispPart.ComponentAssembly  
 'to process the work part rather than the display part,
 '  comment the previous line and uncomment the following line
 'Dim c As ComponentAssembly = workPart.ComponentAssembly
            If Not IsNothing(c.RootComponent) Then  
 '*** insert code to process 'root component' (assembly file)
                lw.WriteLine("Assembly: " & c.RootComponent.DisplayName)  
                lw.WriteLine(" + Active Arrangement: " & c.ActiveArrangement.Name)  
 '*** end of code to process root component
                reportComponentChildren(c.RootComponent, 1)  
            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 reportComponentChildren(ByVal comp As Component, ByVal indent As Integer)  

        Dim numOccs(-1) As Tag  

        For Each child As Component In comp.GetChildren()  
 '*** insert code to process component or subassembly
            lw.WriteLine(New String(" ", indent * 2) & child.DisplayName & vbTab & child.Name)  
            Try  
                ufs.Assem.AskOccsOfPart(comp.Prototype.OwningPart.Tag, child.Prototype.OwningPart.Tag, numOccs)  
                lw.WriteLine(New String(" ", indent * 2) & "Quantity: " & numOccs.GetLength(0))  
            Catch ex As System.NullReferenceException  
                lw.WriteLine(New String(" ", indent * 2) & "*** Component quantity information unavailable (component not loaded)")  
            Catch ex As ApplicationException  

            End Try  

 '*** end of code to process component or subassembly
            If child.GetChildren.Length <> 0 Then  
 '*** this is a subassembly, add code specific to subassemblies
                lw.WriteLine(New String(" ", indent * 2) & _  
                 "* subassembly with " & _  
                 child.GetChildren.Length & " components")  
                lw.WriteLine(New String(" ", indent * 2) & _  
                 " + Active Arrangement: " & _  
                 child.OwningPart.ComponentAssembly.ActiveArrangement.Name)  
 '*** end of code to process subassembly
            Else  
 'this component has no children (it is a leaf node)
 'add any code specific to bottom level components
            End If  
            lw.WriteLine("")  
            reportComponentChildren(child, indent + 1)  

        Next  

    End Sub  
 '**********************************************************
    Public Function GetUnloadOption(ByVal dummy As String) As Integer  
        Return Session.LibraryUnloadOption.Immediately  
    End Function  
 '**********************************************************

End Module  
 

www.nxjournaling.com

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