dogarila
Mechanical
- Oct 28, 2001
- 594
I am looking for a macro to go from configuration to configuration and save a snapshot (jpeg) of each one. Is anyone aware of something like this?
Follow along with the video below to see how to install our site as a web app on your home screen.
Note: This feature may not be available in some browsers.
SolidWorks API Help
Iterate Through All Configurations Example (VB6)
This example shows how to iterate through all of the configurations in a document and forcibly rebuild each one. It assumed that you have an active document.
'--------------------------------------
' Forcibly rebuild each configuration
Option Explicit
Sub main()
Dim swApp As SldWorks.SldWorks
Dim swModel As SldWorks.ModelDoc2
Dim vConfNameArr As Variant
Dim sConfigName As String
Dim nStart As Single
Dim i As Long
Dim bShowConfig As Boolean
Dim bRebuild As Boolean
Dim bRet As Boolean
Set swApp = CreateObject("SldWorks.Application")
Set swModel = swApp.ActiveDoc
Debug.Print "File = " + swModel.GetPathName
vConfNameArr = swModel.GetConfigurationNames
For i = 0 To UBound(vConfNameArr)
sConfigName = vConfNameArr(i)
bShowConfig = swModel.ShowConfiguration2(sConfigName)
nStart = Timer
bRebuild = swModel.ForceRebuild3(False)
Debug.Print " Config = " & sConfigName
Debug.Print " ShowConfig = " & bShowConfig
Debug.Print " Rebuild = " & bRebuild
Debug.Print " Time = " & Timer - nStart & " s"
Next i
End Sub
'--------------------------------------
' Save each configuration as JPG
' It assumes a model is open and active.
Option Explicit
Sub main()
Dim swApp As SldWorks.SldWorks
Dim swModel As SldWorks.ModelDoc2
Dim vConfNameArr As Variant
Dim sConfigName As String
Dim sFileName As String
Dim sPathName As String
Dim nStart As Single
Dim i As Long
Dim bShowConfig As Boolean
Dim bRebuild As Boolean
Dim bRet As Boolean
Dim longstatus As Long
Set swApp = Application.SldWorks
Set swModel = swApp.ActiveDoc
vConfNameArr = swModel.GetConfigurationNames
sPathName = "G:\Working\Design\JPG\" 'change sPathName as per your needs
For i = 0 To UBound(vConfNameArr)
sConfigName = vConfNameArr(i)
bShowConfig = swModel.ShowConfiguration2(sConfigName)
nStart = Timer
'bRebuild = swModel.ForceRebuild3(False) 'Forcing the rebuild will slow down the process
sFileName = sPathName & "A" & sConfigName & ".JPG" 'Use A, B, C, ... to save in different views
longstatus = swModel.SaveAs3(sFileName, 0, 0)
Next i
End Sub