Continue to Site

Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

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

Update Design Table for All Open Documents

API and Macros

Update Design Table for All Open Documents

by  handleman  Posted    (Edited  )
Here's a handy little macro that will update design tables for all open documents. This includes documents that are open but not visible, such as all parts/subassemblies of an open assembly.

It takes a while to run if you have a lot of design tables due to the fact that each table has to open Excel, etc.

Each document will be activated (made visible) by the macro for the update to occur, but all documents will be returned to their original visibility during macro execution.

Lightweight documents will not be found by this macro as they are not fully open, so resolve any components you wish to be found prior to running the macro.

Enjoy!

Code:
Sub DesTblUpdate()
Dim swDoc As SldWorks.ModelDoc2
Dim swDocXt As SldWorks.ModelDocExtension
Dim DesTbl As SldWorks.DesignTable
Dim swAllDocs As EnumDocuments2
Dim FirstDoc As SldWorks.ModelDoc2
Dim dummy As Boolean
Dim NumDocsReturned As Long
Dim DocCount As Long
Dim DesTblCount As Long
Dim i As Long
Dim DoTheUpdate As Long
Dim sMsg As String
Dim swApp As SldWorks.SldWorks
Dim bDocWasVisible As Boolean

Set swApp = Application.SldWorks
Set swAllDocs = swApp.EnumDocuments2
Set FirstDoc = swApp.ActiveDoc

DocCount = 0
DesTblCount = 0
swAllDocs.Next 1, swDoc, NumDocsReturned
While NumDocsReturned <> 0
    Set swDocXt = swDoc.Extension
    If swDocXt.HasDesignTable Then
        DesTblCount = DesTblCount + 1
    End If
    swAllDocs.Next 1, swDoc, NumDocsReturned
    DocCount = DocCount + 1
Wend

sMsg = DocCount & " Documents, " & DesTblCount & " of which had design tables"
sMsg = sMsg & vbCrLf & vbCrLf & "Do you want to update these tables?"
DoTheUpdate = MsgBox(sMsg, vbYesNo, "Update Design Tables?")
If DoTheUpdate = vbNo Then
    Exit Sub
End If

DocCount = 0
DesTblCount = 0
swAllDocs.Reset
swAllDocs.Next 1, swDoc, NumDocsReturned
While NumDocsReturned <> 0
    Set swDocXt = swDoc.Extension
    If swDocXt.HasDesignTable Then
        DesTblCount = DesTblCount + 1
        bDocWasVisible = swDoc.Visible
        swApp.ActivateDoc swDoc.GetPathName
        Set DesTbl = swDoc.GetDesignTable
        dummy = DesTbl.Attach
        dummy = DesTbl.UpdateTable(swDesignTableUpdateOptions_e.swUpdateDesignTableAll, True)
        DesTbl.Detach
        swDoc.Visible = bDocWasVisible
    End If
    swAllDocs.Next 1, swDoc, NumDocsReturned
    DocCount = DocCount + 1
Wend

swApp.ActivateDoc FirstDoc.GetPathName
End Sub
Register to rate this FAQ  : BAD 1 2 3 4 5 6 7 8 9 10 GOOD
Please Note: 1 is Bad, 10 is Good :-)

Part and Inventory Search