Detect number of bodies

Dear all,

Thanks to you all, I created a journal some time ago to export a pdf of the drawing and a STEP of the model. I have been using this journal extensively and it is absolutely awesome. With one exception.

Sometimes parts have multiple bodies. The STEP export journal exports all bodies to the STEP file. This is not always desireble. However, the user doesn't know all the bodies are exported to STEP because some bodies are hidden and therefore not that visible. It is easy to make this mistake.

I would like to add a bit of code which can detect the amount of bodies in a part and warn the user that he is going to export a multiple body STEP.
Multiple bodies can occur within the part itself but also because the part contains another part (like an assembly). Both should be detected.

Until now I was able to write my own journals with the help of the record function. However, this is not possible with this problem.

Any help with this challenge will be greatly appreciated. Writing this code is near impossible for me to do.

Frank

We also had a similar problem with this and decided to remove the not desired solids from the reference set "MODEL" and export only all bodies within the reference set. The

Here you also can see how we cycle through all bodies to check. Just add a counter with your warning.

Hope this helps, best regards

Public Function checkRefset

Const RefSet As String = "MODEL"
Dim i As Integer
Dim stateArray1(0) As Layer.StateInfo
Dim myReferenceSets As ReferenceSet()
myReferenceSets = workPart.GetAllReferenceSets()
Dim theReferenceSet As ReferenceSet = Nothing
'Dim lw As ListingWindow = theSession.ListingWindow
Dim mypart As Part
nxSelectedObjects.Clear()

For Each myRefSet As ReferenceSet In myReferenceSets
If myRefSet.Name.ToUpper() = RefSet Then
theReferenceSet = myRefSet
refMembers = myRefSet.AskAllDirectMembers()
' msgbox((myRefSet.AskAllDirectMembers()).toString)
'lw.Open()
For Each myObject As DisplayableObject In refMembers

'lw.WriteFullline("object type: " & myObject.GetType.ToString)
If TypeOf myObject Is NXOpen.Body Then
Dim myBody As NXOpen.Body = myObject
nxSelectedObjects.Add(myBody)
ElseIf TypeOf myObject Is NXOpen.Assemblies.Component Then
nxSelectedObjects.Clear()
myPart=(myObject.OwningPart)
'lw.WriteFullline("OwningPart: " & myPart.ToString)
For Each mySolid As NXOpen.Body In AskAllBodies(myPart)
nxSelectedObjects.Add(mySolid)
Next
Exit For
End If
Next
'lw.Close()
End If
Next

'Step Export

Sub STP_Export_AV(ByVal outputFile As String, ByVal inputFile As String, settings As String, _
stpSelectedObjects As List(Of NXOpen.Body))

Dim stepCreator1 As NXOpen.StepCreator = Nothing
stepCreator1 = theSession.DexManager.CreateStepCreator()

stepCreator1.ExportAs = NXOpen.StepCreator.ExportAsOption.Ap214
stepCreator1.ObjectTypes.Solids = True
stepCreator1.SettingsFile = settings

If Not IO.File.Exists(stepCreator1.SettingsFile) Then
MessageBox.Show(String.Format("Datei: (ugstep214.def) nicht gefunden." & _
"{0}Stp-Export abgebrochen", vbNewLine))
Exit Sub
End If

stepCreator1.InputFile = "@DB/" & inputFile
stepCreator1.OutputFile = outputFile
stepCreator1.ExportSelectionBlock.SelectionScope = NXOpen.ObjectSelector.Scope.SelectedObjects

Dim added1 As Boolean = Nothing
added1 = stepCreator1.ExportSelectionBlock.SelectionComp.Add(stpSelectedObjects.ToArray)

stepCreator1.FileSaveFlag = False
stepCreator1.LayerMask = "1-256"

Dim nXObject1 As NXOpen.NXObject = Nothing
nXObject1 = stepCreator1.Commit()

stepCreator1.Destroy()

Dear Robse-ponte
Thank you so much for your reply!
Sadly enough I am to busy at the moment to give your repsonse the attention that it diserves. I am working on a project with a a tight deadline. I will defenetely come back to you when the I have some more time.