How to rebuild all configurations?

Discussion created by Guest on Nov 21, 2006
Since I didn't get a response to my post, I went ahead and came up with this VBA macro to rebuild all part configurations for the given part name.
Enjoy
John H
Big Tex Trailers

' ******************************************************************************
' Macro to activate ans rebuild all part configurations by John H 11/21/06
' SW 2006 X64 SP5.0
' MS Windows XP64 Professional
'
' Conditions (1) Solidworks is open and running
' (2) change path and filename below to point to yout part file
' (3) no error handling, provided as is
' ******************************************************************************

Dim swApp As Object
Dim Part As Object
Dim boolstatus As Boolean
Dim longstatus As Long, longwarnings As Long
Dim swConfig As SldWorks.Configuration
Dim swModel As SldWorks.ModelDoc2
Dim vConfigName As Variant
Dim sConfigName As String
Dim sFileName As String
Dim sFilePath As String
Dim sFilePathName As String
Dim i As Long



Sub main()

Set swApp = Application.SldWorks

'change FilePath and FileName to point to your file name and location
sFileName = "FileName.SLDPRT"
sFilePath = "C:\FilePath\"
sFilePathName = sFilePath + sFileName

Set Part = swApp.OpenDoc6(sFilePathName, 1, 0, "", longstatus, longwarnings)
Set Part = swApp.ActivateDoc2(sFileName, False, longstatus)

swApp.ActiveDoc.ActiveView.FrameLeft = 0
swApp.ActiveDoc.ActiveView.FrameTop = 0
swApp.ActiveDoc.ActiveView.FrameState = 1
swApp.ActiveDoc.ActiveView.FrameState = 1
boolstatus = Part.Extension.SelectByID2(sFileName, "COMPONENT", 0, 0, 0, False, 0, Nothing, 0)
boolstatus = Part.EditRebuild3
Part.ClearSelection2 True
Part.ForceRebuild

Set swModel = swApp.ActiveDoc

vConfigName = swModel.GetConfigurationNames

For i = 0 To UBound(vConfigName)
sConfigName = vConfigName(i)
Set swConfig = swModel.GetConfigurationByName(sConfigName)
boolstatus = Part.Extension.SelectByID2(sConfigName, "CONFIGURATIONS", 0, 0, 0, False, 0, Nothing, 0)
Part.ShowConfiguration sConfigName
boolstatus = Part.EditRebuild3
Part.ForceRebuild
Next i

Part.Save2 False
Set Part = Nothing
swApp.CloseDoc swModel.GetTitle
End Sub

Outcomes