To all,
I am looking at the possibility of adding an option to a existing (simple) code. The code currently creates groups (As CAE.Group) and put FE.elements into it based on some user specified criteria. Looks all good at the moment. I 'd like to add the option to expand the newly created groups but I am getting a bit stuck after the 'Show Adjacent' step.
I believe one needs to get an array of taggedobject to add to the group. The output of the step showAdjacentBuilder1.Commit() is an variable of type NXObject.
Is there anyway of re-using this output (after conversion ?) or does one need to somehow loop through all the FE.Elements displayed on the screen (to create a new array of TaggedObject)?
I have posted bit of the test code I have created so
Thanks
Regards
Sub ExpandOutputGroups(ByRef saTheInputGroups() As String)
Dim i, j, k, N, iloop As Integer 'general integer for loops
'theLW.WriteLine("Expanding Output stress group(s)...")
For Each sgroupname As String In saTheInputGroups
'convert string name to a CAE.Group and get the list of element in the group
Dim caeGroup1 As CAE.CaeGroup = GetCAEGroupFromName(sgroupname)
Dim arrFEElmInGroupTarget() As CAE.FEElement = GetGroupElements(caeGroup1).ToArray
Dim caePart1 As CAE.CaePart = CType(theSimPart, CAE.CaePart)
Dim showAdjacentBuilder1 As CAE.ShowAdjacentBuilder
showAdjacentBuilder1 = caePart1.ShowHideMgr.CreateShowAdjacentBuilder()
'theLW.WriteLine("Group name :" & sgroupname)
'theLW.WriteLine("Number of element in group: " & arrFEElmInGroupTarget.Length)
Dim objects1(arrFEElmInGroupTarget.Length-1) As TaggedObject
For i = 0 to arrFEElmInGroupTarget.Length-1
objects1(i) = arrFEElmInGroupTarget(i)
Next i
Dim added1 As Boolean
added1 = showAdjacentBuilder1.Selection.Add(objects1)
Dim nXObject1 As NXObject
nXObject1 = showAdjacentBuilder1.Commit()
showAdjacentBuilder1.Destroy()
'expand group
'loop through all the element on the screen following the show adjacent
'Dim objects2(8) As TaggedObject
'caeGroup1.AddEntities(objects2)
Next sgroupname
End Sub
RE: Looping through a NXObject ?
Is it possible to loop through a NXObject? I am testing the following code to see if I can "check" what is the "content" of NXobject1 which is returned by the showAdjacentBuilder1.Commit() , see code in previous post.
Dim ListOfTaggedObject As New List(Of TaggedObject)
For Each obj As NXObject In nXObject1
If TypeOf (obj) Is CAE.FEElement Then 'It's just a test as NXobject1 should only contain FEElement
ListOfTaggedObject.Add(obj)
theLW.WriteLine("added object")
Else
theLW.WriteLine("CANNOT add object")
End If
Next
Thanks
Regards
re: showAdjacentBuilder
I don't have experience using the ShowAdjacentBuilder object; but after looking at the API reference, you might want to use the .GetCommittedObjects method of the builder. This method will return the array of objects that the builder creates. You can then loop through the returned array. The .Commit method only returns a single object; in most cases this is the feature or single object created by the builder. I've not tried it, but I'm guessing that you will need to call .GetCommittedObjects after the call to .Commit and before the call to .Destroy.
Re: .GetCommittedObjects return blank array
Just tested the suggestion of using the .GetCommittedObjects for the Builder 'ShowAdjacentBuilder' but it seems that it's returning an empty array (length = 0)
Sub ExpandOutputGroups(ByRef saTheInputGroups() As String)
Dim i, j, k, N, iloop As Integer 'general integer for loops
For Each sgroupname As String In saTheInputGroups
theLW.WriteLine("Group name: " & sgroupname)
Dim caeGroup1 As CAE.CaeGroup = CType(theSimPart.CaeGroups.FindObject(sgroupname), CAE.CaeGroup)
Dim arrFEElmInGroupTarget() As CAE.FEElement = GetGroupElements(caeGroup1).ToArray
Dim caePart1 As CAE.CaePart = CType(theSimPart, CAE.CaePart)
Dim showAdjacentBuilder1 As CAE.ShowAdjacentBuilder
showAdjacentBuilder1 = caePart1.ShowHideMgr.CreateShowAdjacentBuilder()
Dim objects1(arrFEElmInGroupTarget.Length-1) As TaggedObject
For i = 0 to arrFEElmInGroupTarget.Length-1
objects1(i) = arrFEElmInGroupTarget(i)
Next i
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 'theCAEGroup.GetEntities()
theLW.WriteLine("Type1 is: " & obj.ToString)
theLW.WriteLine("Type2 is: " & obj.GetType.ToString)
Next
showAdjacentBuilder1.Destroy()
Next sgroupname
End Sub
Thanks
Regards