Reply

How to get solid bodies from part file in solid edge through API

I have a part file that have three solid bodies(Extrude).

I need this solid body count from part file through API.

Currently i am trying to get this count through vb but unable to get that.

 

Please help me to get this solid/surface bodies count from part file.

 

Thanks in advance.

 

5 REPLIES

Re: How to get solid bodies from part file in solid edge through API

You have to distinguish between three cases, if you need to get the bodies in your part file:

 

1) You created a single extrusion with multiple disjoint and closed profile, e.g. 3 non-overlapping circles resulting in 3 cylinder bodies

=> You don't have direct access to each body. You need to iterate through all Models and get its body. This body has the IsSolid property set and has multiple closed, non-void Shells.

 

2) You created each feature in a multi-body design by using the AddBody command

=> Each body is stored in its own Model object, just retrieve its Body property

 

3) You created a solid construction body, by using the Extruded surface command with closed ends.

=> Each of these bodies are stored in the Body property of the ConstructionModel object, which can be found in the Constructions collection of the part document

 

The following code counts the total number of solid bodies in the active part document:

'----------------------------------------------------------------------
' PAR: Count the total number of solid bodies in the active part document.
'----------------------------------------------------------------------
Dim nSolidBodies As Integer = 0
Dim objDoc As SolidEdgePart.PartDocument = objApp.ActiveDocument
Dim objBody As Body = Nothing

' Check for solid design bodies
For Each objModel As SolidEdgePart.Model In objDoc.Models
  objBody = objModel.Body
  If objBody.IsSolid Then
    For Each objShell As Shell In objBody.Shells
      If objShell.IsClosed AndAlso Not objShell.IsVoid Then
        nSolidBodies += 1
      End If
    Next
  End If
Next

' Check for solid construction bodies
For Each objConsModel As ConstructionModel In objDoc.Constructions
  objBody = objConsModel.Body
  If objBody.IsSolid Then
    nSolidBodies += 1
  End If
Next

Re: How to get solid bodies from part file in solid edge through API

Thank you so much for the code. 

Re: How to get solid bodies from part file in solid edge through API

Thanks for the sample Martin. I created ReportSolidBodies sample on GitHub and gave you credit in the readme.

Jason Newell
Applications Architect
www.jasonnewell.net

Re: How to get solid bodies from part file in solid edge through API

Jason,

Thank you for doing so.

I was already thinking in the past about adding one or the other code to your code samples on GitHub, but it would have taken me much more time than you as I am (not yet) familiar with GitHub.

I will continue posting code samples here, if possible ;-)

Re: How to get solid bodies from part file in solid edge through API

Yeah, I'd say keep doing what you're doing and I'll follow up with the samples. If and when you get time to learn GitHub, give me a shout and we'll do a Skype session or something.

Jason Newell
Applications Architect
www.jasonnewell.net