Cancel
Showing results for 
Search instead for 
Did you mean: 

Obtaining assembly component files

Solution Partner Genius Solution Partner Genius
Solution Partner Genius

Hello everyone!

 

I need to go through the assembly and perform action on each component. Could you please advice me how can this be done? I found some samples in the Solution Center, but they all aim at obtaining occurences, rather than actual parts. In other words, if somepart.prt is added twice into assembly, the code obtains them both, where I need to access the actual somepart.prt to perform action on its feature three. If you know relevant Solution Center example, please point me to it. Thanks!

8 REPLIES

Re: Obtaining assembly component files

Legend
Legend

Keyword is "prototype".

 

Search for nx_api3112 in SolutionCenter.

 

Regards

Jan

Jan Böttcher

Re: Obtaining assembly component files

Siemens Phenom Siemens Phenom
Siemens Phenom

Just get all the parts in the partCollection, and iterate through the array, like this:

 

Option Strict Off
Imports System
Imports NXOpen

Module process_every_part_in_session

    Dim theSession As Session = Session.GetSession()

    Sub Main()

        Dim allParts() As Part = theSession.Parts.ToArray()

        For Each thisPart In allParts

            Echo("Part: " & thisPart.Leaf())
            ' perform your desired action on the part here
        Next

    End Sub

    Sub Echo(ByVal output As String)

        theSession.ListingWindow.Open()
        theSession.ListingWindow.WriteLine(output)
        theSession.LogFile.WriteLine(output)

    End Sub

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

End Module

Re: Obtaining assembly component files

Honored Contributor
Honored Contributor

If you have a reference to a component, you can get the part with something like this:

 

{comp}.Prototype.OwningPart

 

This assumes that the component is loaded in memory; if it is not loaded, you may have to load it first.

Re: Obtaining assembly component files

Solution Partner Genius Solution Partner Genius
Solution Partner Genius
So basically I can iterate through all instances and just check if the actual component has been already attended to?

Re: Obtaining assembly component files

Siemens Phenom Siemens Phenom
Siemens Phenom

 

Yes, but based on your initial description, I thought you only wanted to handle each part once.  To do that, you can use the PartCollection, and you will skip all of the multiples.

 

Re: Obtaining assembly component files

Honored Contributor
Honored Contributor

The downside of the PartCollection is that it may contain parts that don't belong to the assembly of interest.

 

You can process the assembly components and keep track of the ones that you have already processed, or process the part collection ensuring that each part is used in the assembly of interest before modifying it.

Re: Obtaining assembly component files

Solution Partner Genius Solution Partner Genius
Solution Partner Genius

I found a neat example nx_api3552. I believe it can be modified to add components to a list and just check each obtained component against it. This way I should be able to end up with a list of assembly files.

Re: Obtaining assembly component files

Solution Partner Genius Solution Partner Genius
Solution Partner Genius

Thanks everyone for the suggestions! They helped me to do the job.

For anyone interested, I eventually found an excellent C# example: nx_api3405.