Hi,
I am facing a couple of parts with >100 bodies. I want to save these bodies as part and make an assembly with the "Save Bodies" feature.
Before this, I'd like to rename all bodies so they have a unique name. I'm looking to do this with a macro.
I now have this: but the renaming part is not working...
Option Explicit
Sub main()
Dim swApp As SldWorks.SldWorks
Dim swModel As SldWorks.ModelDoc2
Dim swPart As SldWorks.PartDoc
Dim vBodyArr As Variant
Set swApp = Application.SldWorks
Set swModel = swApp.ActiveDoc
Set swPart = swModel
swModel.ClearSelection2 True
vBodyArr = swPart.GetBodies2(0, False)
RenameBodies swModel, vBodyArr
End Sub
Sub RenameBodies(swModel As SldWorks.ModelDoc2, vBodyArr As Variant)
Dim swBody As SldWorks.Body2
Dim prefixName As String
Dim bodycount As Integer
bodycount = 1
If IsEmpty(vBodyArr) Then Exit Sub
prefixName = "Projectnumber"
For Each vBody In vBodyArr
vBody.Name = prefixName + bodycount '<-- error is here....
bodycount = bodycount + 1
Next vBody
swModel.Rebuild
End Sub
Any tips on how to rename the bodies?
Thanks in advance!