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!
Solved! Go to Solution.
Just get all the parts in the partCollection, and iterate through the array, like this:
Option Strict Off
Dim theSession As Session = Session.GetSession()
Dim allParts() As Part = theSession.Parts.ToArray()
For Each thisPart In allParts
Echo("Part: " & thisPart.Leaf())
' perform your desired action on the part here
Sub Echo(ByVal output As String)
Public Function GetUnloadOption(ByVal dummy As String) As Integer
If you have a reference to a component, you can get the part with something like this:
This assumes that the component is loaded in memory; if it is not loaded, you may have to load it first.
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.
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.
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.
Thanks everyone for the suggestions! They helped me to do the job.
For anyone interested, I eventually found an excellent C# example: nx_api3405.