I have an assembly which is derived from a multibody part. In the multibody part each component was designed as a sheet metal part. When I export bodies as a new assembly I would simply like to convert all these new components to be sheet metal components as that feature is no longer paired.
Using this thread and this forum, I have created a macro that can convert an open part to a sheet metal component without selecting a face. Next I want to select a component from the design tree of an open assembly and have it convert it to a sheet metal. If I can figure that out I'd also like to have the macro run a loop for multiple components if selected. NOTE: I can see the "insertconverttosheetmetal2" function working (via debug.print), but it doesn't seem to save.
Code:
Option Explicit
Dim Part As Object
Dim boolstatus As Boolean
Dim longstatus As Long, longwarnings As Long
Sub main()
Dim swApp As SldWorks.SldWorks
Dim swModel As SldWorks.ModelDoc2
Dim swCompModel As SldWorks.ModelDoc2
Dim swSelMgr As SldWorks.SelectionMgr
Dim swComp As SldWorks.Component2
Dim swFace As SldWorks.Face2
Dim swFeature As SldWorks.Feature
Dim swFeaturedata As Object
Dim vBodies As Variant
Dim swBody As SldWorks.Body2
Set swApp = Application.SldWorks
Set swModel = swApp.ActiveDoc
Set swSelMgr = swModel.SelectionManager
Set swComp = swSelMgr.GetSelectedObjectsComponent4(1, 0)
Set swCompModel = swComp.GetModelDoc2
vBodies = swCompModel.GetBodies2(swBodyType_e.swSolidBody, False)
Set swBody = vBodies(0)
Set swFace = swBody.GetFirstFace
Dim Area As Double
While Not swFace Is Nothing
If swFace.GetArea > Area Then
swFace.Select2 False, -1
Area = swFace.GetArea
End If
Set swFace = swFace.GetNextFace
Wend
Debug.Print Area
'value = instance.InsertConvertToSheetMetal2(Thickness, ReverseThickDir, FindBends, Radius, Gap, ReliefType, ReliefRatio, OverlapType, OverlapRatio, KeepBody)
boolstatus = swCompModel.FeatureManager.InsertConvertToSheetMetal2(0.0359, False, True, 0.0359, 0.003, 2, 0.5, 0, 0, False)
Debug.Print boolstatus
End Sub
SolidworksApi/macros