×
INTELLIGENT WORK FORUMS
FOR ENGINEERING PROFESSIONALS

Log In

Come Join Us!

Are you an
Engineering professional?
Join Eng-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Eng-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Jobs

Looking for macro to traverse configurations
2

Looking for macro to traverse configurations

Looking for macro to traverse configurations

(OP)
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?

RE: Looking for macro to traverse configurations

Quote:

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

RE: Looking for macro to traverse configurations

(OP)
Thanks, CBL.

Actualy I've already found that example and modified it o my needs.

RE: Looking for macro to traverse configurations

So do you now have a fully working macro?

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

cheers

RE: Looking for macro to traverse configurations

(OP)
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

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Eng-Tips Forums free from inappropriate posts.
The Eng-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Eng-Tips forums is a member-only feature.

Click Here to join Eng-Tips and talk with other members!


Resources