I am looking for information/method on how to get whatever is shown/displayed on the screen (in NX.CAE) following a 'Show Adjacent' step.
The output variable of showAdjacentBuilder1.Commit() is of type NXObject.
I have tried GetCommittedObjects() but the array returned is blank
Dim added1 As Boolean Dim NXObject1 As NXObject added1 = showAdjacentBuilder1.Selection.Add(objects1) NXObject1 = showAdjacentBuilder1.Commit() Dim NXObjectcommited() As NXObject NXObjectcommited = showAdjacentBuilder1.GetCommittedObjects() theLW.WriteLine("Length of NXObjectcommited: " & NXObjectcommited.Length) For Each obj As NXObject In NXObjectcommited theLW.WriteLine("Object is : " & obj.ToString) theLW.WriteLine(" and it's Type is: " & obj.GetType.ToString) Next showAdjacentBuilder1.Destroy()
you could use a combination of "show only" and "show adjacent" (for your "objects1") and afterwards cycle all objects in part with:
and check every cycled object wheter it is visible or not with:
This is sincerely not the nicest way but at least I think it should be a workaround.
Thanks for the pointer MGeyer. Haven't come back to that problem yet!
No idea why the 'GetCommittedObjects' returns blank!
I have never used the UF functions so you'll have to push me in the right direction! As a very top level workflow you are suggesting someting like that
Dim objects2() As TaggedObject For Each obj As NXObject In theUFSession.Obj.CycleObjsInPart If theUFSession.Obj.AskDisplayProperties = True Then objects2(i) = obj Next Dim caeGroup1 As CAE.CaeGroup caeGroup1.AddEntities(objects2)
using your NX Open with UF Functions could be something like the following:
first do a "Show Only" for the objects you are wishing to use with your "Show Adjacent", then you can do the "Show Adjacent":
'Copied from your Code: added1 = showAdjacentBuilder1.Selection.Add(objects1) NXObject1 = showAdjacentBuilder1.Commit()
Now after this your selected object and all the adjacent objects should be visible in the graphics area.
This is where using UF Functions will start: (my example is cycling all visible polygon faces in a fem part)
'Get the UFSession: Dim theUfSession As UFSession = UFSession.GetUFSession()
'Get the fem part Dim thefempart As CAE.FemPart = CType(theSession.Parts.BaseDisplay, CAE.FemPart)
'Initialize a collection for the objects you are wanting to collect: Dim facelist As New List(Of TaggedObject) 'Initializie a Variable of type Tag Dim ObjTag As Tag = Tag.Null 'Do a first cycle with UF Functions (means pushing the first type matching objects tag into the variable "Obj_Tag"): theUfSession.Obj.CycleObjsInPart(thefempart.Tag, UFConstants.UF_caegeom_type, ObjTag) 'Now every type matching object should be cycled within a while loop: Do While (ObjTag <> Tag.Null) 'Initialize two Variables for checking the matching type: Dim type As Integer = 0 Dim subtype As Integer = 0 'Get the momentarily cycled object's type: theUfSession.Obj.AskTypeAndSubtype(ObjTag, type, subtype) 'Initialize a Variable of type DispProps: Dim dispprops As UFObj.DispProps 'Push the DispProps of the momentarily cycled object into this Variable: theUfSession.Obj.AskDisplayProperties(ObjTag, dispprops) 'Now you need a conditional: if the subtype and display properties (e.g. being visible) matches, you can do something with your momentarily cycled object: If (subtype = UFConstants.UF_caegeom_face_subtype And dispprops.blank_status = UFConstants.UF_OBJ_NOT_BLANKED) Then 'at first you will need to transfer the cycled Obect's Tag into an NXOpen.TaggedObject and then add it to your collection facelist.add(Utilities.NXObjectManager.Get(ObjTag)
) End If 'Do not forget to put this cycling in your while loop or it will never reach its termination condition: theUfSession.Obj.CycleObjsInPart(thefempart.Tag, UFConstants.UF_caegeom_type, ObjTag)
hopefully you can use this suggestion for your problem.
Thanks a lot for the example M Geyer. Much appreciated. Working my way (slowly) through it !
I have just looked at the doc for UFConstant and cannot see anything (obvious) for an FE Element Type except: UF_gfem_element_type. So I tried it and it seems that this type does not have a subtype!
So a couple of questions if i may:
Q1: is the UFConstant I foudn the correct one?
Q2: What should the subtype be?
I did a quick test by excluding the IF check (in the Do.. Loop) and it's not executed as I suspect the ObjTag is still NULL
'Get the fem part 'Dim thefempart As CAE.FemPart = CType(theSession.Parts.BaseWork, CAE.FemPart) 'Initialize a collection for the objects you are wanting to collect: Dim ListofFEElmToAdd As New List(Of TaggedObject) 'Initializie a Variable of type Tag Dim ObjTag As Tag = Tag.Null theUfSession.Obj.CycleObjsInPart(thefempart.Tag, UFConstants.UF_gfem_element_type, ObjTag) Do While (ObjTag <> Tag.Null) 'Initialize two Variables for checking the matching type: Dim type As Integer = 0 Dim subtype As Integer = 0 theUfSession.Obj.AskTypeAndSubtype(ObjTag, type, subtype) Dim dispprops As UFObj.DispProps theUfSession.Obj.AskDisplayProperties(ObjTag, dispprops) If (subtype = UFConstants.UF_gfem_element_subtype And dispprops.blank_status = UFConstants.UF_OBJ_NOT_BLANKED) Then ListofFEElmtoAdd.add(Utilities.NXObjectManager.Get
(ObjTag)) End If theUfSession.Obj.CycleObjsInPart(thefempart.Tag, UFConstants.UF_gfem_element_type, ObjTag) Loop
Okay, to clarify the problem a bit:
you like to get the FE Elements which are adjacent to a selected FE Element?
If we suggest so, UFConstants.UF_gfem_element_type is not what you need.
I also tried to find a matching type throug the following:
Dim fEElement1 As NXOpen.CAE.FEElement = CType(fEModel1.Find("Element"), NXOpen.CAE.FEElement) Dim type As Integer = 0 Dim subtype As Integer = 0 theUfSession.Obj.AskTypeAndSubtype(fEElement1.Tag, type, subtype) MsgBox("Type is: " & type.ToString & " and subtype is: " & subtype.ToString)
Unfortunately this fails with an message saying the first parameter passed in is not valid.
I am quite sorry this is not working...
Last thing I can imagine is to use the meshManager to get all meshes in your fem part and from those get all the elements and ask every element in a loop with the following:
Dim dispprops As UFObj.DispPropstheUfSession.Obj.AskDisplayProperti
es(MyElement.Tag, dispprops) If (dispprops.blank_status = UFConstants.UF_OBJ_NOT_BLANKED) Then ListofFEElmtoAdd.add(MyElement) End If
But having large FE Models this will probably be very slow...
On any builder, Commit() and GetCommittedObjects() inherit from NXOpen.Builder and return object(s) of type NXOpen.NXObject. If the builders output object type inherits from NXObject, it will be returned by the builder.
NXOpen.CAE.FEElement (and FENode) are 'lightweight' objects that inherit from NXOpen.TaggedObject, not NXObject. As such, any builders that *should* return nodes or elements will return nothing.
Some builders have special methods added to return the CAE objects, for example, NXOpen.CAE.MultipleNodeCreateBuilder.CommitNodes()
As for the UFConstant, most of these are defined in %UGII_BASE_DIR%\ugopen\uf_object_types.h However, for non-NXObject types, there are additional constants defined in %UGII_BASE_DIR%\ugopen\uf_ui_types.h In here, you will find the UFConstants for node and element:
/* Define UF_pseudo_object_type and corresponsing subtypes and detail types: * UF_pseudo_object_type is used for selection only and for object types not defined in uf_object_types.h */ #define UF_pseudo_object_type (-1) /* The subtypes for UF_pseudo_object_type: */ /* For CAE: */ #define UF_pseudo_CAE_subtype (1) #define UF_pseudo_CAE_node (1) /* first CAE detail type */ #define UF_pseudo_CAE_element (2) /* second CAE detail type */
Hi MGeyer. Thanks for taking the time to look at the problem.
The simple code I have does the following;
step3 s1 to 3 works
step 4 is achieved uisng
Dim objects1(arrFEElmInGroupTarget.Length-1) As TaggedObject For i = 0 to N-1 objects1(i) = arrFEElmInGroupTarget(i) Next i Dim added1 As Boolean Dim nXObject1 As NXObject added1 = showAdjacentBuilder1.Selection.Add(objects1) nXObject1 = showAdjacentBuilder1.Commit()
While the suggestion of the MeshManager might be a work around I don't think this is a "realistic" approach as it might be very slow for a large FE model
Note that another alternative which may be easier to code is to build your own ShowAdjacent utility. The attached file (showConnectedElements.vb) was written as a simple model connectivity check. It asks the user to pick a set of seed elements, then displays all of the elements that are ultimately connected to those elements. It performs a loop, using the SmartSelection RelatedNodeMethod to get nodes related to those elements, then the RelatedElementMethod to get the elements related to those nodes. These elements are added to the seed list and the loop continues.
Without the loop, this is a simple show adjacent element command.