gettig user screen selction In NX.CAE - Hopw to?

To all,

I am sure I have seen examples on how to do this but can't find anything. I am thinking of a possible macro to create and export results to a txt (in NX.CAE). All standard NX stuff I just want to automate the creation and export (so that I can go for a coffee break!!). One of the blocks of code is to get the elements required for the result creation. I am thinking about 2 options. Option 1 - User selects a group, Option 2 - Program uses the user screen selection. I think I have the info to set up option 1. The question is for option 2;

How does one get the user screen selection in NX.CAE? (work flow point 2 below)

My thinking is as follows;
1. Press button execute program
2. Get screen selection
2a. if screen selection is empty then get data from a defined group
2b. if screen selection is NOT empty then check that the "content" = Element (as CAE.FEElement)
2c. put each element in an array (can one create an array of CAE.FEElement ??)
3.execute program by creation results for the elements selected

Thanks

Regards

JXb

You can query and work with pre-selected objects in your journal. The following code, written by Amy Webster of GTAC, shows how to work with the preselected objects.

'Amy Webster
'Date: 03/28/2011
'Subject: Sample NX Open .NET Visual Basic program : report type and subtype of preselected objects
'
'Note: GTAC provides programming examples for illustration only, and
'assumes that you are familiar with the programming language being
'demonstrated and the tools used to create and debug procedures. GTAC
'support professionals can help explain the functionality of a particular
'procedure, but we will not modify these examples to provide added
'functionality or construct procedures to meet your specific needs.

Imports System
Imports NXOpen
Imports NXOpen.UF
Imports NXOpenUI

Module journal

Sub Main
Dim s As Session = Session.GetSession()
Dim ufs As NXOpen.UF.UFSession = NXOpen.UF.UFSession.GetUFSession()
Dim selobj As NXObject
Dim type As Integer
Dim subtype As Integer
Dim lw As ListingWindow = s.ListingWindow

Dim theUI As UI = ui.GetUI
Dim numsel As Integer = theUI.SelectionManager.GetNumSelectedObjects()
lw.Open()
lw.WriteLine("Selected Objects: " & numsel.ToString())

For inx As Integer = 0 To numsel-1
selobj = theUI.SelectionManager.GetSelectedObject(inx)

ufs.Obj.AskTypeAndSubtype(selobj.Tag, type, subtype)
lw.WriteLine("Object: " & selobj.ToString())
lw.WriteLine(" Tag: " & selobj.Tag.ToString())
lw.WriteLine(" Type: " & type.ToString())
lw.WriteLine(" Subtype: " & subtype.ToString())
lw.WriteLine("")
Next

End Sub

End Module

thanks for the code. 1st test on pre-selecting FE elements on the screen failed with error message
InvalidCastException 'Unable to cat object of type 'CAE.FEElement' to type '.NXObject'
Error occurs at the 1st line of the 'For inx' loop. it looks like 'inx' was corrected ( I selected 6 elements)

Thanks
Regards

Look up the FEElement class in the NXOpen API reference, near the bottom of the page it will list the inheritance hierarchy. My guess is: it does not inherit from NXObject and that is why the cast operation fails.

In the journal above, try changing out the NXObject type with the class that FEElement inherits from.

Thanks for the pointer NXJournaling. Much appreciated. The doc states the FEElement (class) inherits from TaggedObject !!

Thanks
Regards