Maybe my wording of the subject isn't to precise but I'll try to describe the problem.
I made a custom app that relies on a particular part having only 1 body under a working layer. The app works fine except in few instances. This few instances have in common that the "DELETE BODY" feature was used. The problem is visible if I make a sub to loop through the bodies of the working part where it will find more than I body even though you can't see them.
I have recreated the problem on a simple part and the result is the same and it's that delete body feature doesn't delete all the body data.
I have a few workarounds but I would like to know if this is an issue as in undesired behaviour or an error on my part.
Has anyone encountered this or if possible can try to recreate the problem on their own machine. (Simple sub to cycle through the bodies of a working part and count them will do. )
Solved! Go to Solution.
The "delete body" command creates a feature in the part navigator; it cannot completely delete the body information from the file or else you would not be able to get the body back when you suppress or delete the "delete body" feature. The "delete body" is more like "super hide body". Check the layer of the deleted body, it may be on a system layer (such as layer 0 or layer 257, etc). Here is a thread where someone ran into a similar issue.
Thanks for answer. I looked at the thread and I understand the issue. What I was supprised is that I collect the bodies even though I'm doing the loop through the layer 1 and when I check no other layer contains any objects.
I tested the theory in another way and before deleting the bodies I placed them under a different layer. Then it worked aka there were no bodies under layer 1.
Conclusion: After using "Delete bodies" feature, deleted bodies are still under layer 1 in a sense they can be picked by a journal that cycles through workpart/layer bodies, unless they have been placed in another layer prior to deletion.
I ran into a similar issue a couple of years ago. Below is a small journal that I wrote when I was exploring the issue. There is probably a better way to identify a deleted body, but this is what I have for now. The code just finds all solid bodies and puts them into a list; then it searches the features for "delete body" features and removes the bodies referenced by any delete body features found.
Option Strict Off Imports System Imports System.Collections.Generic Imports NXOpen Imports NXOpen.UF Module Module27 Sub Main() Dim theSession As Session = Session.GetSession() Dim workPart As Part = theSession.Parts.Work Dim displayPart As Part = theSession.Parts.Display Dim ufs As UFSession = UFSession.GetUFSession() Dim lw As ListingWindow = theSession.ListingWindow lw.Open() Dim solidBodies As New List(Of Body) For Each theBody As Body In workPart.Bodies 'lw.WriteLine("IsSheetBody: " & theBody.IsSheetBody.ToString) 'lw.WriteLine("IsSolidBody: " & theBody.IsSolidBody.ToString) If theBody.IsSolidBody Then solidBodies.Add(theBody) End If Next For Each theFeature As Features.Feature In workPart.Features If TypeOf (theFeature) Is NXOpen.Features.DeleteBody Then Dim delBodyFeat As Features.DeleteBody = theFeature Dim delBodies() As Body = delBodyFeat.GetBodies For Each delBody As Body In delBodies If solidBodies.Contains(delBody) Then solidBodies.Remove(delBody) End If Next End If Next lw.WriteLine("work part contains: " & solidBodies.Count.ToString & " solid bodies that have not been deleted") End Sub End Module
Thanks for the journal. I would have gone the other way around, going through for all the bodies than asking it's parent features but your way is efficient/better
I will modify it to fit my purpose.