INTELLIGENT WORK FORUMS
FOR ENGINEERING PROFESSIONALS

Member Login

HANDLE


PASSWORD
Remember Me
Forgot Password?

Come Join Us!

  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • Turn Off Ad Banners
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

E-mail*
Handle

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

Partner With Us!

"Best Of Breed" Forums Add Stickiness To Your Site
Partner Button
(Download This Button Today!)

Member Feedback

"...I have to add my thanks and appreciation for your wonderful site... People who frequent the site are the two best things - nice and smart..."

Geography

Where in the world do Eng-Tips members come from?

API and Macros

Update Design Table for All Open Documents
Posted: 11 Apr 06

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

Back to SolidWorks 3D CAD products FAQ Index
Back to SolidWorks 3D CAD products Forum
My FAQ Archive
Email This FAQ To A Friend

My Archive