How to obtain config names for unopened files?

Discussion in 'SolidWorks' started by plh, Dec 16, 2004.

  1. plh

    plh Guest

    Here is what I want to do:
    Using VB in Excel,

    1) Find a directory and obtain a list of the Solidworks files in it
    - this I can do.

    2) Run down the list of files and query the configuration name list for each
    one(without having to open each one & set a model object)
    - this I don't know how to do. However, I do have the SW references working in
    Excel. The question is, does a method exist for doing this.

    3) Display the resulting lists in Excel - no problem there.

    Does anyone have any suggestions for number 2? Is it possible?
    Thanx,
    -plh
     
    plh, Dec 16, 2004
    #1
  2. plh

    CS Guest

    vConfName as Variant
    vConfName = swApp.GetConfigurationNames(FileNameandPath)

    I use this all the time works great.
     
    CS, Dec 16, 2004
    #2
  3. plh

    plh Guest

    Tried it.
    Just what the doctor ordered!
    Thank You!
    -plh
     
    plh, Dec 16, 2004
    #3
  4. I am very much interested by this program.

    Is there any way I could have a copy of it?

    Thanks in advance

    JM Brun


    Replace " _arobace/at_ " by @
     
    Jean Marc BRUN, Dec 17, 2004
    #4
  5. plh

    plh Guest

    It turns out it was not rocket science.
    This is the code I have in an Excel Spread sheet.
    Note that I used a literal string for "fs.lookin".
    Anyone using it would have to change this according to their needs.
    If you have a lot of files to go through, this thing can take a while.
    You need to make column B in Excel of type "text" so that you can
    order by that column & have them come out in a nice logical order,
    that is, without all the numbers coming first.
    You also have to add the Sldworks 2004 Type Library in Excel VBA.

    Depending on how many files you have, this can take a while to run.

    Sub FindConfigs()
    '
    Dim i As Long
    Dim j As Long
    Dim k As Long

    Dim Begin
    Dim fs As Object
    Dim swApp As SldWorks.SldWorks
    Dim vConfName As Variant
    Dim strAllFiles() As String
    Dim strSelFiles() As String
    Dim lngConfigCount As Long

    Set swApp = CreateObject("SldWorks.Application")
    ReDim strAllFiles(256)
    Set fs = Application.FileSearch
    With fs
    .LookIn = "N:\ENGINEERING\00 - VAULT\Solidworks Files\"
    .SearchSubFolders = True
    .Filename = "*.sldprt;*.sldasm;*.prt;*.asm"
    If .Execute() > 0 Then
    For i = 1 To .FoundFiles.Count
    If i > UBound(strAllFiles) Then
    ReDim Preserve strAllFiles(UBound(strAllFiles) + 256)
    End If
    strAllFiles(i) = .FoundFiles(i)
    Next i
    Else
    MsgBox "There were no files found."
    End If

    End With

    j = 1
    For i = 1 To UBound(strAllFiles)
    Debug.Print strAllFiles(i)
    If InStr(strAllFiles(i), "~$") = 0 Then
    'excludes "those" files
    ReDim Preserve strSelFiles(j)
    strSelFiles(j) = strAllFiles(i)
    j = j + 1
    End If
    Next i
    k = 2
    'leaves the 1st row empty for titles in Excel Spreadsheet
    For i = 1 To UBound(strSelFiles)
    lngConfigCount = swApp.GetConfigurationCount(strSelFiles(i))
    If lngConfigCount > 1 Then
    'ignore files with only one configuration
    vConfName = swApp.GetConfigurationNames(strSelFiles(i))
    For j = 0 To UBound(vConfName)
    If vConfName(j) <> "Default" Then
    'don't list "Default" configurations
    Range("A" & k).Value = strSelFiles(i)
    Range("B" & k).Value = vConfName(j)
    k = k + 1
    End If
    Next j
    End If
    Next i

    End Sub

    -plh
     
    plh, Dec 20, 2004
    #5
  6. Thanks a bunch, I will try to make it run.

     
    Jean Marc BRUN, Dec 21, 2004
    #6
  7. plh

    plh Guest

     
    plh, Jan 29, 2005
    #7
Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.