Solid bodies

Solid bodies

Stephgbleu
Explorer Explorer
1,875 Views
4 Replies
Message 1 of 5

Solid bodies

Stephgbleu
Explorer
Explorer

 

Maybe one of you would share with us an example of illogic or VBA rules to export automatically a list (like txt or csv formats) containing all the solids of a part and their respective physical properties (mass, volumes,…).

Many thanks in advance for your help.

 

Best Regards.

0 Likes
Accepted solutions (1)
1,876 Views
4 Replies
Replies (4)
Message 2 of 5

Jon.Dean
Alumni
Alumni

Hi Stephan,

I suggest you look to the following Blog pages, many examples there.

Manufacturing DevBlog.

Jon.



Jon Dean

0 Likes
Message 3 of 5

Anonymous
Not applicable

Based on my research there is not a way to get the mass properties of a single body in a multibody part file through the API.

See the link below. There are a couple of work arounds suggested in that post. I messed around with this for a little while trying to find you a solution and the only place the mass properties are available through the API is at the PartComponentDefinition Level.

 

Reference Link:

http://forums.autodesk.com/t5/inventor-customization/surfacebody-properties-via-api/td-p/4853851

0 Likes
Message 4 of 5

Anonymous
Not applicable
Accepted solution

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

 

Message 5 of 5

Jon.Dean
Alumni
Alumni

Hi Ken,

That is a great solution, I'm sure Stephan will be really please.

Impressive.

Jon.



Jon Dean

0 Likes