Ok, I think I figured out a solution for this! I hope I'm not too late. The code might be a little messy and its not commented. I figured alot of this out through trial and error.
This code will only work with a multi-body part file.
the code will export a step file for each solid body in the part file to the same directory that the part.ipt file was opened from.
open the step file
calculate the mass, area and volume
print the properties to a text file
save the text file to the part.ipt root directory
then close all step files and text file.
you will be left with a folder containing
root part.ipt file
.stp file for each solid body
.txt file with each solids properties.
Option Explicit
Sub Props2TxtFile()
Dim partDoc As PartDocument
Set partDoc = ThisApplication.ActiveDocument
Dim partDef As PartComponentDefinition
Set partDef = partDoc.ComponentDefinition
Dim fso As Object
Set fso = CreateObject("Scripting.FileSystemObject")
Dim oFile As Object
Set oFile = fso.CreateTextFile(ThisApplication.ActiveDocument.FullFileName & "Properties.txt")
Dim body As SurfaceBody
For Each body In partDoc.ComponentDefinition.SurfaceBodies
If body.Visible Then
body.Visible = False
End If
Next
For Each body In partDoc.ComponentDefinition.SurfaceBodies
Call SaveAsSTP(body)
Call OpenSTP(body, fso, oFile)
Next
For Each body In partDoc.ComponentDefinition.SurfaceBodies
If Not body.Visible Then
body.Visible = True
End If
Next
oFile.Close
Set fso = Nothing
Set oFile = Nothing
MsgBox "Complete!"
End Sub
Private Sub OpenSTP(body As SurfaceBody, fso As Object, oFile As Object)
Dim partDef As PartComponentDefinition
Dim dblMass As Double
Dim dblGrams As Double
Dim dblVolume As Double
Dim dblArea As Double
Dim oInv As Document
Set oInv = ThisApplication.Documents.Open(ThisApplication.ActiveDocument.FullFileName & body.Name & ".stp")
Dim oCommandMgr As CommandManager
Set oCommandMgr = ThisApplication.CommandManager
Dim oControlDef As ControlDefinition
Set oControlDef = oCommandMgr.ControlDefinitions.Item("AppLocalUpdateCmd")
Call oControlDef.Execute
Set partDef = ThisApplication.ActiveDocument.ComponentDefinition
dblMass = partDef.MassProperties.Mass
dblGrams = dblMass * 1000
dblVolume = partDef.MassProperties.Volume
dblArea = partDef.MassProperties.Area
oFile.WriteLine "Body: " & body.Name & " - Mass: " & CStr(dblGrams * 0.00220462) & " lbs" & " | Volume: " & CStr(dblVolume * 0.061024) & " in^3" & " | Area: " & CStr(dblArea * 0.15500031) & " in^2"
ThisApplication.ActiveDocument.Close (True)
End Sub
Sub SaveAsSTP(body As SurfaceBody)
Dim partDoc As Document
Set partDoc = ThisApplication.ActiveDocument
body.Visible = True
Call partDoc.SaveAs(partDoc.FullFileName & body.Name & ".stp", True)
body.Visible = False
End Sub