Fifi Riri

Convert to Bodies Addon

Discussion created by Fifi Riri on Feb 4, 2020

Following this forum thread: Convert to Bodies 


Since there isn't currently any API function for this, here is a program (with sources included) to convert a part to bodies.

This program will open the menu, fill the save path and click on the required controls.

See code example below on how to call it.


Please note that the part must be saved and rebuild before running this program, otherwise SolidWorks popup messages will disrupt its execution.



Option Explicit
Sub main()
Dim retVal As Integer
Dim wsh As Object
Dim sArgs(0 To 5) As String

' program path (Required)
sArgs(0) = """D:\Download\ConvertToBodies.exe"""

' save path (Required)
sArgs(1) = """D:\Download\dd.sldprt"""

' Save As selection (Optional default: 2)
' 0: No change (Save As)
' 1: Save As
' 2: Save as Copy and Continue
' 3: Save as Copy and Open
sArgs(2) = 2

' replace file (Optional default: 1)
' 0: Don't replace
' 1: Replace
sArgs(3) = 1

' Preserve reference geometry and sketches checkbox (Optional: default 1)
' 0: unchecked
' 1: checked
sArgs(4) = 1

' Ok button (Optional default: 1)
' 0: don't click
' 1: click button
sArgs(5) = 1

Set wsh = VBA.CreateObject("WScript.Shell")
retVal = wsh.Run(Join(sArgs, " "), 0, True)

Debug.Print "Convert to: " & sArgs(1)
Select Case retVal
Case 0
Debug.Print "Converted successfully"
Case -1
Debug.Print "Error: No arguments specified"
Case -2
Debug.Print "No conversion: File already exists"
Case -3
Debug.Print "Error: Can not find Solidworks window"
Case -4
Debug.Print "Error: Can not find 'Convert to Bodies' window or no part opened"
End Select
End Sub