Hi,
Hope somebody can help me with this problem:
I have a Macro running that I found online to update te design tables of multiple parts in an assembly. Which works great to drive an assembly from an external Excel file.
In a few of the sub-assemblies there are also a few Equations driven from the design tables, which should ideally be updated when te design tables are updated.
I noticed just opening the Equation Manager by hand does the job, but I thought a smarter and quicker way to do it would be to incorporate the opening and closing of the Equation Manager (i.e. updating) in the running Macro just after the opening and closing of the Design Table in that particular part. I just don't know how..
Any ideas? Thanks a lot in advance!
This is the Macro 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 all 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
SolidworksApi macros