Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

Design Table Help!

Status
Not open for further replies.

XtremeBen

Mechanical
Apr 11, 2006
8
0
0
US
Hello everyone,

Our team here at HUFCOR has been working with Solidworks Design Tables for the past few months, in an attempt to integrate them into our product design and structure. Right now we are in the middle of a large-scale product consolidation and are converting our entire product line over from AutoCAD to Solidworks models. Most of our products require the use of a design table to create multiple configurations for variable height and width. This also plays into the product assemblies, as they too need to have the capability to vary the height and width.

Although the design tables have been working great for us, it seems that Solidworks has left something out. What we would like to be able to do is vary our design table calculations from one master “Deduct” Table. For example lets say we have a frame that is variable in height and width based on a deduct number that is set in our master table. Then say for a special job we need to change that deduct number, and want it to change all the part design tables, and in turn change our assemblies. We have figured out how to change the part design tables just fine. What we are going to do is save all the part design tables externally from Solidworks in one directory. Then in the master directory we will save our “Deduct” master table, which will control the calculations of all the part tables. We will then use an excel macro to open all the part design tables, save the changes, and close the file. We have tested this and it works just fine. The problem comes in with how Solidworks updates the part and assembly files. In order to see the updates to the design table, we have to open the part, then open the design table, save the design table, and then close the part. Only then we see the changes to the part. What makes it worse is that most of the time, we only will be opening the assemblies, not the part files, thus we would never see the changes made to the design table without opening each part file and going through the whole procedure.

Our questions are:
1.)Are we approaching this correctly? Is there a better way to update all of our parts with one master file?

2.)Is there a way to update our assemblies without opening all of the part files?

3.)If not to the above, is there a way to open all the part files and update them automatically?

4.)Has anyone written a macro or VB code that would do something like this and would be willing to share it with us?

Any help would be greatly appreciated. Thanks a lot!
 
Replies continue below

Recommended for you

What you are doing sounds similar to what neilc78 is doing in thread559-151791.

[cheers]
Helpful SW websites FAQ559-520
How to get answers to your SW questions FAQ559-1091
 
Option #4:
This code checks every document open in SW for design tables and updates them. It'll take care of what you want to do if you have your assembly open and then run the macro. Not sure how it would work if there are lightweight parts. I use this as part of my BOM sorting routine when I'm ready to print my final assembly as high-quality, so lightweight never really comes up. There's some extra stuff in there that gives the option of only updating design tables of files with the string "Misumi" somewhere in custom properties. I wrote it mainly because I use a lot of highly customizable parts from Misumi in my design. The part number is basically a string of letters and numbers for dimensions, so I use a design table to generate the part number. If I don't make sure the table is updated I can order a part incorrectly. I think this should work for your purposes as-is or you can tweak it.

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 CustPropString As String
Dim aCustPropNames As Variant
Dim DoTheUpdate As Long
Dim sMsg As String
Dim Filter As String


If MsgBox("Check for Misumi tables only?", vbYesNo) = vbYes Then
    Filter = "Misumi"
Else
    Filter = ""
End If

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
        aCustPropNames = swDoc.GetCustomInfoNames2("")
        CustPropString = ""
        For i = 0 To UBound(aCustPropNames)
            CustPropString = CustPropString & swDoc.CustomInfo2("", aCustPropNames(i))
        Next
        If VBA.InStr(1, CustPropString, Filter, vbTextCompare) <> 0 Then
            DesTblCount = DesTblCount + 1
        End If
    End If
    swAllDocs.Next 1, swDoc, NumDocsReturned
    DocCount = DocCount + 1
Wend

sMsg = DocCount & " Documents, " & DesTblCount & " of which had " & Filter & " 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
        aCustPropNames = swDoc.GetCustomInfoNames2("")
        CustPropString = ""
        For i = 0 To UBound(aCustPropNames)
            CustPropString = CustPropString & swDoc.CustomInfo2("", aCustPropNames(i))
        Next
        If VBA.InStr(1, CustPropString, Filter, vbTextCompare) <> 0 Then
            DesTblCount = DesTblCount + 1
            swApp.ActivateDoc swDoc.GetPathName
            Set DesTbl = swDoc.GetDesignTable
            dummy = DesTbl.Attach
            dummy = DesTbl.UpdateTable(swDesignTableUpdateOptions_e.swUpdateDesignTableAll, True)
            DesTbl.Detach
        End If
    End If
    swAllDocs.Next 1, swDoc, NumDocsReturned
    DocCount = DocCount + 1
Wend

swApp.ActivateDoc FirstDoc.GetPathName
End Sub
 
handleman Thanks for the code!

I do have some questions though, as I have try to run the code and I get a few errors. Are you running this as a standalone application, or a macro witin Solidworks? I have tryed to run it as a macro within solidworks and I get a "User defined type not defined" error. We are running SW05, I'm not sure if you have an older/newer version and maybe some of the commands have changed.

Thanks a lot!
 
It is a macro within SW, but it's a subroutine from a larger macro. Just looking at it, it appears that swApp is not declared as a variable. It's probably in my global variables for the larger macro. Up in the "Dim" statements, add

Dim swApp as SldWorks.SldWorks

It works as a standalone macro on my machine with that addition. Without it I also get an error, although not the one you mentioned. If this line doesn't fix it, hit "Debug" when you get the error and let me know which line it doesn't like. Also, go to Tools->References in the VBA editor and make sure that "SolidWorks 2005 Constant Type Library" is checked.
 
That did help, we can get it to run now, but it is not finding all of the parts with design tables. For example when I run it on an assembly with about 60 parts (30 of which have design tables), it only finds 1 to have a design table. I think the problem may exhist in the line where you call out "aCustPropNames = swDoc.GetCustomInfoNames2("")" We are using DBWorks to set all the properties for our files (parts and Assemblies). We dont use any of the property setting directly through Solidworks.
 
Below I've removed all code relating to custom properties. If you have a lot of design tables then the macro will take a while to do the actual update. I left the counting section and the confirmation message in there so that if you accidentally run the macro you won't have to sit there while 50 or so design tables update.

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

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
        swApp.ActivateDoc swDoc.GetPathName
        Set DesTbl = swDoc.GetDesignTable
        dummy = DesTbl.Attach
        dummy = DesTbl.UpdateTable(swDesignTableUpdateOptions_e.swUpdateDesignTableAll, True)
        DesTbl.Detach
    End If
    swAllDocs.Next 1, swDoc, NumDocsReturned
    DocCount = DocCount + 1
Wend

swApp.ActivateDoc FirstDoc.GetPathName
End Sub
 
That did it!

I hate to keep bothering you but is there anyway to close the part files after they have been updated? Thanks a lot!
 
You know what, we were able to figure it out.

Thank you very much for all your help, this will make things a whole lot easier here.

Thanks again! :)
 
I assume you want to make them invisible again rather than closing them. After they're invisible, all you have to do to close them is close the assembly that references them. You'll have the opportunity to save parts that were modified as usual.

This version will return any invisible but open docs to invisible again after the design table update. Docs visible at time of macro start will remain visible.

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
 
Xtremeben.

We seem to be approaching this issue in a similar method to you. I'll just go over again what we are doing. We make conveyor systems. We have 6/7 standard types for example straight ones, Curved ones, elevators... What we decided to do was to build a variable model for each of these. By variable I mean the designer could enter a set of variables such as length, height etc. We also built in provision for things like Motor position on RHS or LHS. In essence we would position motors on both sides and suppress one depending what was required. I have numerous patterns (eg for legs) which vary with lengh too. I needed complex equation solving so I went with a DT approach. Like you I needed the same information to update each parts DT in the assembly so I used a 'master' spreadsheet external from the SW models.

In each part I had then an embedded DT who's cells linked back to the master. The problem does arise on how to update the parts once the master has been updated. We used a macro to do this which is lauched from within the Assembly file. The master Spreadsheet must be open when updating. The macro first opens the Assembly DT and closes it. It then prompts for the user to Select multiple files within the assembly. It will then open the part, open its DT, close its DT, save the part and then move to the next part. This is the macro used...

********************************************
Option Explicit

Public swApp As SldWorks.SldWorks
Public swModel As SldWorks.ModelDoc2
Public swSelMgr As SldWorks.SelectionMgr
Public swComponent As SldWorks.Component2
Public strCompName As String
Public j As Integer
Public swCompModel As SldWorks.ModelDoc2
Public lngRetVal As Long
Dim blnStatus As Boolean

Sub main()

Set swApp = GetObject("", "Sldworks.Application")
Set swModel = swApp.ActiveDoc
Set swSelMgr = swModel.SelectionManager

If swModel.GetType <> 2 Then
swApp.SendMsgToUser ("Please open an assembly")
End
End If

blnStatus = swModel.Extension.SelectByID2("Design Table", "DESIGNTABLE", 0, 0, 0, False, 0, Nothing, 0)

If blnStatus = False Then
End
Else
swModel.InsertFamilyTableEdit
swModel.CloseFamilyTable
End If

frmSelect.Show vbModeless

End Sub

Public Sub UpdateDTables()
Dim lngErrors As Long
Dim lngWarnings As Long
Dim intCount As Integer
Dim i As Integer
Dim varComps As Variant
Dim strCompPath() As String

intCount = swSelMgr.GetSelectedObjectCount

ReDim strCompPath(intCount)

For i = 1 To intCount
Set swComponent = swSelMgr.GetSelectedObjectsComponent(i)
Set swCompModel = swComponent.GetModelDoc
strCompPath(i) = swCompModel.GetPathName
Next i

varComps = strCompPath

For i = 1 To intCount

Set swCompModel = swApp.ActivateDoc2((varComps(i)), True, lngRetVal)
Debug.Print varComps(i)
blnStatus = swCompModel.Extension.SelectByID2("Design Table", "DESIGNTABLE", 0, 0, 0, False, 0, Nothing, 0)


If blnStatus = False Then

swCompModel.Save3 swSaveAsOptions_Silent, lngErrors, lngWarnings
swApp.CloseDoc swCompModel.GetPathName
swCompModel.EditRebuild3

Else
j = j + 1
swCompModel.InsertFamilyTableEdit
swCompModel.CloseFamilyTable
swCompModel.EditRebuild3
swCompModel.Save3 swSaveAsOptions_Silent, lngErrors, lngWarnings
swApp.CloseDoc swCompModel.GetPathName

End If

blnStatus = False

Next i

swModel.EditRebuild3

swModel.ClearSelection2 (True)

frmUpdateFinished.Show

Set swApp = Nothing
Set swModel = Nothing
Set swSelMgr = Nothing
Set swComponent = Nothing
Set swCompModel = Nothing
Set varComps = Nothing
j = 0

End Sub

**************************************************

One other thing I did was to use PDM Works to store these models and the Master Spreadsheet too. This has the advantage of allowing you to be able to 'copy project'. Copy project allows you to copy the top level assembly, the Parts in the assembly and all the drawings of the parts and the assembly (SW explorer won't let you copy drawings.) When we are doing a new job we copy the standard project and add teh job number to the ends of each part name (i.e. standard model would copy to standard model-"job number") This allows us to avoid files with same names floating around. It does however add a problem in that since the master spreadsheet will also get appended with this job number the links will be broken to the masterspreadsheet. To fix this I added to cells to each Part DT. One was called 'job number' the other file path. I use the values in these cells to define the file name and path of the master spreadsheet. Then, the link in a typical cell is as follows...

=INDIRECT("'"&$AU13&"[Box Elevator Master Spreadsheet"&$AT13&".xls]sheet1'!"&B16)

AU13 = File Path Cell
AT13 = Job Number
B16 = the contains the cell number to read from in the Master Spreadsheet.

All this is working for me but I need to add something to the macro above which will populate the 'job number' and 'file path' cells with some user defined info.

I hope this helps and is understandable. If you have any questions just ask.
 
Thanks a lot for the Code neilc78,

We have had a whole lot of sucess with everyone's help. I do have one more problem. Is it possible to have this same macro open the "master" excel file and keep it open while SW updates the design tables, and then close the "master" file? We have had sucess opening the file, but then it closes it right away, before SW has a chance to open any of the part design tables. Any thoughts?

Thanks! [thumbsup2]
 
Just for clarification - the "master" file is Excel only, right (not the DT for the assembly)? This should work:

Dim xlApp as Excel.Application

Set xlApp = CreateObject("Excel.Application")
xlApp.Visible = True
xlApp.Workbooks.Open [Excel file path string]

Excel should stay open after the macro completes.
 
Status
Not open for further replies.
Back
Top