I am making some note for a possible program which may (or may not!) end up with a GUI (UI Builder). I'd like to know what is the "best" way to loop through all the files open in NX.CAE (sim, afm, fem, prt, "any" file really) as I'd like to check if one of them is a sim file.
I am thinking about this so that when the GUI is loaded if one of the open files is a sim something is "defaulted" to that file name so the use don't hae to do a manual selection.
Solved! Go to Solution.
The session object maintains the part collection that gives you access to all the currently open parts. You could iterate through the part collection looking at the file types and names.
Thank for the pointer. I think the doc starting to make sense as I can see something like
Dim thepartcollection as PartCollection = thesession.Parts
Will have test something like
For each thepart as CAE.Part In thepartcollection
but everything I can find in the doc refers to .prt file, no mention of other file type being opened
The part collection can contain CAE parts (sim, fem, etc) as well as "model" parts (prt). I'd suggest that you try something like the following:
For each thepart as BasePart In thepartcollection thepart.name 'check for part type Next
Note the use of BasePart rather than CAE.Part; a BasePart can represent any type of NX part. If you loop through the collection with the code that you posted, it will attempt to convert each part in the collection to a CAE.Part and will error if any non-CAE parts are open (.prt parts).
Thanks. Upgrading to NX10 is still on my to-do list!
Looks like I have found a way of to do what I have in mind
Dim ListofSIMPart As New List(Of String) Dim thepartcollection as PartCollection = theSession.Parts 'Type are 'NXOpen.CAE.FemPart 'NXOpen.CAE.AssyFemPart 'NXOpen.CAE.SimPart For each thepart as BasePart In thepartcollection theLW.WriteLine("" & thepart.FullPath) theLW.WriteLine("" & thepart.Leaf) theLW.WriteLine("Type is " & thepart.GetType.ToString) If thepart.GetType.ToString = "NXOpen.CAE.SimPart" Then ListofSIMPart.Add(thepart.Leaf) End If Next