Showing results for 
Search instead for 
Do you mean 
Reply
Solved! Go to solution

Looping through open files in NX.CAE- How to?

To all

 

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.

 

Any suggestions?

 

Thanks

Regards

 

Production: NX9.0.3.4, NX10.0.2.6
Development: VB.NET (amateur level !)
5 REPLIES

Re: Looping through open files in NX.CAE- How to?

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.

Re: Looping through open files in NX.CAE- How to?

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

  thepart.name

Next 

 

but everything I can find in the doc refers to .prt file, no mention of other file type being opened

 

Thanks

Regards

Production: NX9.0.3.4, NX10.0.2.6
Development: VB.NET (amateur level !)

Re: Looping through open files in NX.CAE- How to?

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).

Re: Looping through open files in NX.CAE- How to?

PartCollection is the way to do it.
Please see the following post : posthttp://community.plm.automation.siemens.com/t5/NX-Programming-Customization/NX-10-Bug-in-PartCollection/td-p/312262/jump-to/first-unread-message

If you are using NX 10 you should update to 10.0.2.

Regards
Boris

Solution
Solution
Accepted by topic author selex_ct
‎09-22-2015 05:17 AM

Re: Looping through open files in NX.CAE- How to?

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

 

Thanks

Regards

 

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

 

Production: NX9.0.3.4, NX10.0.2.6
Development: VB.NET (amateur level !)