×
INTELLIGENT WORK FORUMS
FOR ENGINEERING PROFESSIONALS

Log In

Come Join Us!

Are you an
Engineering professional?
Join Eng-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Eng-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Bodycollection - more than one body?

Bodycollection - more than one body?

Bodycollection - more than one body?

(OP)
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:

CODE --> VB

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 --> VB

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 

RE: Bodycollection - more than one body?

Sheet bodies also show up in the .Bodies collection.

The "delete body" command will remove the body from the display, but it will remain in the .Bodies collection.

Some commands create special geometry that is sometimes hidden from the user. This "system created" geometry is usually put on a special layer (such as layer 0 or 257); you might be able to check the layer of the body and exclude those not on the usual layers of 1-256.

www.nxjournaling.com

RE: Bodycollection - more than one body?

(OP)
Mh, that's a very good tip. Sadly i never worked with layers.

You said that the delete body command (i guess removeRange works in the same way) only removes from display. Which commands should i use to remove the entities from the body collection? I'm fairly certain that only the first body is the one that I need. Could I use some other command to remove the others without using the layers?

Thanks a lot, this is very interesting.




RE: Bodycollection - more than one body?

The NX "delete body" command and VB's .RemoveRange method are 2 different things.

Is it possible that you can upload an example file (with none of your IP included) that has these "ghost" bodies?

www.nxjournaling.com

RE: Bodycollection - more than one body?

Hi Frank -

I can help you...Almost sure you will be a happy user....
It is exactly what Cowski mentions regarding the sytems layers and the system bodies...
NX provides layers for users between 1 & 256..But NX uses some other layers in the background, which is not visible for the users.
Also not the system objects is visible on these layers (<1 & >256..
An example could be if you create a simple tab with a flange in SheetMetal app. Try create a FlatPattern feature...
Now the NX part contains 3 bodies...But you can only see and handle the original body...your body you created with the tab and the flange..
But NX needs two extra bodies in the background , to be able to create the FlatPattern feature...

I have edited your code - everything works like a dream - from my point of view....
Give this a try....

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
            If theBody.IsSolidBody Then 'added lklo - try tempoary comment this line out
            If theBody.Layer <= 256 Then 'added lklo - try tempoary comment this line out
            If theBody.Layer >= 1 Then 'added lklo - try tempoary comment this line out
            ' now we are ready to put only Solid Bodies on layers between =>1 & <=256 into the list
            solidBodies.Add(theBody)
            End If 'added lklo - try tempoary comment this line out
            End If 'added lklo - try tempoary comment this line out
            End If 'added lklo - try tempoary comment this line out
        Next

        Dim markId1 As Session.UndoMarkId
        markId1 = theSession.SetUndoMark(Session.MarkVisibility.Visible, "prova")
        theSession.UpdateManager.DoUpdate(markId1)


        lw.WriteFullline("Number of bodies in the entire part: " & workPart.Bodies.ToArray.Length) 'edited lklo

        lw.WriteFullline("") 'added lklo

        lw.WriteFullline("Number of bodies in the List ""solidBodies"": " & solidBodies.Count) 'edited lklo
        lw.WriteFullline("=============================================") 'added lklo
    End Sub

End Module 

1.Try create a sheetmetal part which also contains a flatpattern feature...
2.Run the code
3.Result: 3 solidBodies in workpart , 1 solidBody in the List "solidBodies"
Now you are ready to continue your work, by using the List "solidBodies"...

And a small test for your own testing - just to see the difference...
4. Try comment out the six lines I have suggested in the code.
5.Run the code
6.3.Result: 3 solidBodies in workpart , 3 solidBodies in the List "solidBodies"

regards lklo


Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Eng-Tips Forums free from inappropriate posts.
The Eng-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Eng-Tips forums is a member-only feature.

Click Here to join Eng-Tips and talk with other members! Already a Member? Login


Resources

Solutions Brief - Protecting and Rescuing On-Ground Personnel
Keeping our warfighters safe and delivering them a competitive advantage is a key goal of departments of defense around the world. It’s a goal shared by embedded computing manufacturers like Abaco: we never forget who we serve.This case study describes how a major international contractor integrated an Abaco single board computer at the heart of its CAS/CSAR solution. Download Now
Datasheet - Top Enhancements Creo 7.0
PTC's Creo 7.0 has breakthrough innovations in the areas of generative design, real-time simulation, multibody design, additive manufacturing, and more! With Creo 7.0, you will be able to design the most innovative products faster than ever before, keeping you on the cutting edge of product design and ahead of your competition. Download Now

Close Box

Join Eng-Tips® Today!

Join your peers on the Internet's largest technical engineering professional community.
It's easy to join and it's free.

Here's Why Members Love Eng-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close