Continue to Site

Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

  • Congratulations waross on being selected by the Eng-Tips community for having the most helpful posts in the forums last week. Way to Go!

Looking for macro to traverse configurations 2

Status
Not open for further replies.

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?
 
Replies continue below

Recommended for you

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.

Code:
'--------------------------------------

' 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

'--------------------------------------

That may give you a start.

I'm sure someone posted a complete macro a long time ago, but have had no luck finding it yet.



[cheers]
 
Thanks, CBL.

Actualy I've already found that example and modified it o my needs.
 
So do you now have a fully working macro?

Can you post for future reference? This comes up occasionally.

[cheers]
 
Here you go:
Code:
' 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
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor