Frank2288
Mechanical
- Nov 20, 2015
- 38
I'm writing in VB a tool that needs to perform a series of modeling operations starting from a CAD template part that is given as input (it is manually modelled by an operator before the use of the automatic tool).
For a series of reasons i need to be sure that the part that I am using as template is characterized by only one body; the operator knows this requirement and makes sure to have only one body when he/she finishes the modeling operations).
Just to be sure I added a check in the first operations performed by the VB tool to assure that the bodycollection of the part returns 1 element.
Check:
The problem is that I often found more than one body in the part, although the user designed the part as a single body and by opening the part (manually) the 3D model that has been generated seems like a single body. Summing up, I don't know why but I found these "ghosts bodies" very often and it is a problem.
1) Does anybody knows why these ghost bodies are created? Which modeling operation could be responsible for this?
2) I tried to cycle through all the bodies in the body collection of a part and highlight each single body, and I found out that the only body that is actually highlighted is always the first one (nothing is highlighted when considering the "ghost bodies"). So it could be ok for me to just remove these other bodies. I tried this solution but it does not work: anybody knows why?
For a series of reasons i need to be sure that the part that I am using as template is characterized by only one body; the operator knows this requirement and makes sure to have only one body when he/she finishes the modeling operations).
Just to be sure I added a check in the first operations performed by the VB tool to assure that the bodycollection of the part returns 1 element.
Check:
Code:
Dim body_collection As NXOpen.BodyCollection = workPart.Bodies
If body_collection.ToArray.Length > 1 Then
Dim title As String = "WARNING"
Dim multiple_bodies_text As String = "The provided template is composed by multiple solid bodies"
System.Windows.Forms.MessageBox.Show(multiple_bodies_text, title, Windows.Forms.MessageBoxButtons.OK, Windows.Forms.MessageBoxIcon.Information)
'Error 5
End If
The problem is that I often found more than one body in the part, although the user designed the part as a single body and by opening the part (manually) the 3D model that has been generated seems like a single body. Summing up, I don't know why but I found these "ghosts bodies" very often and it is a problem.
1) Does anybody knows why these ghost bodies are created? Which modeling operation could be responsible for this?
2) I tried to cycle through all the bodies in the body collection of a part and highlight each single body, and I found out that the only body that is actually highlighted is always the first one (nothing is highlighted when considering the "ghost bodies"). So it could be ok for me to just remove these other bodies. I tried this solution but it does not work: anybody knows why?
Code:
Imports Snap, NXOpen
Imports Snap.UI.Block, Snap.Create
Imports ConstDef
Imports System
Imports System.Collections.Generic
'test to remove multiple bodies
Public Module MultipleBodies
Private theSession As NXOpen.Session
Private theUfSession As UF.UFSession
Private Matlab As Object
Public Sub Main()
' System.Diagnostics.Debugger.Launch()
theSession = NXOpen.Session.GetSession
theUfSession = NXOpen.UF.UFSession.GetUFSession
Dim workPart As Part = theSession.Parts.Work
Dim displayPart As Part = theSession.Parts.Display
Dim lw As ListingWindow = theSession.ListingWindow
lw.Open()
Dim solidBodies As New List(Of Body)
For Each theBody As Body In workPart.Bodies
solidBodies.Add(theBody)
Next
lw.WriteFullline(solidBodies.ToArray.Length.ToString)
lw.WriteFullline(workPart.Bodies.ToArray.Length.ToString)
solidBodies.RemoveRange(1, (solidBodies.ToArray.Length - 1))
Dim markId1 As Session.UndoMarkId
markId1 = theSession.SetUndoMark(Session.MarkVisibility.Visible, "prova")
theSession.UpdateManager.DoUpdate(markId1)
lw.WriteFullline("Number of bodies inside SolidBodies:")
lw.WriteFullline(solidBodies.ToArray.Length.ToString)
lw.WriteFullline("Number of bodies in workpart.bodies.toarray.length.tostring")
lw.WriteFullline(workPart.Bodies.ToArray.Length.ToString)
End Sub
End Module