Hi SW Community, Keith Rice, Deepak Gupta
Does anyone know how to insert design table in 2D Drawing?
or does SolidWorks API have the function on how to insert design table in 2D drawing?
Thank you in advance.
Inserting Design Table in Drawing.
2017 SOLIDWORKS API Help - InsertFamilyTableNew Method (IModelDoc2)
swDoc.Extension.SelectByID2("DrawingView1", "DRAWINGVIEW", 0, 0, 0, false, 0, null, 0);
Not sure on API but here is ho you can insert DT manually in drawing. You need to select the view first.
Thanks but I know how to insert it in manual operation but
i can't find function for API on how to insert it.
I think this is currently not possible and SPR #:777264 is already in place. Check and vote.
As Deepak explained, you need to select the view to insert the design table. Also, you can only insert the design table if the part or assembly in the view has a design table.
Cannot find any API to insert Design Table in a drawing.
Get the IModelDoc2 object from the view and use IModelDoc2.GetDesignTable to get the design table. Then you could get the data from Design Table and copy them into a General Table. Use IDrawingDoc.InsertTableAnnotation2 method to insert General Table.
Unfortunately, data in the General table won't be para-metrically linked to Design Table.
I will give it a try and let you know.
I can only get the design table and delete it but
i can't find API function on how to insert it.
Thanks in advance.
Try following codes. As I explained earlier, it gets the data from design table from part or assembly (referenced in the drawing view) and copies then back to General Table . The data are not para-metrically linked. The drawing view must be selected before running the macro. Not sure if this is what you want.
Dim swApp As SldWorks.SldWorks
Dim swModel As SldWorks.ModelDoc2
Dim swViewModel As SldWorks.ModelDoc2
Dim swDraw As SldWorks.DrawingDoc
Dim swSelMgr As SldWorks.SelectionMgr
Dim swView As SldWorks.View
Dim swDesignTable As SldWorks.DesignTable
Dim swTableAnn As SldWorks.TableAnnotation
Dim docName As String
Dim i As Long
Dim j As Long
Dim totalRow As Integer
Dim totalColumn As Integer
Dim lErrors As Long
Dim lWarnings As Long
Set swApp = Application.SldWorks
Set swModel = swApp.ActiveDoc
If swModel Is Nothing Then
swApp.SendMsgToUser2 "No document is open. Open a drawing document.", swMessageBoxIcon_e.swMbStop, swMessageBoxBtn_e.swMbOk
If swModel.GetType <> swDocumentTypes_e.swDocDRAWING Then
swApp.SendMsgToUser2 "Active document is not a drawing document. Open a drawing document.", swMessageBoxIcon_e.swMbStop, swMessageBoxBtn_e.swMbOk
Set swDraw = swModel
Set swSelMgr = swModel.SelectionManager
Set swView = swSelMgr.GetSelectedObjectsDrawingView2(1, -1)
If swView Is Nothing Then
swApp.SendMsgToUser2 "No drawing view is selected. Select a drawing view.", swMessageBoxIcon_e.swMbStop, swMessageBoxBtn_e.swMbOk
Set swViewModel = swView.ReferencedDocument
docName = swViewModel.GetPathName
docName = Right(docName, Len(docName) - InStrRev(docName, "\"))
If swViewModel.Extension.HasDesignTable = False Then
swApp.SendMsgToUser2 "Referenced document '" & docName & "' in the drawing view '" & swView.Name & "' does not contain a design table.", swMessageBoxIcon_e.swMbStop, swMessageBoxBtn_e.swMbOk
Set swDesignTable = swViewModel.GetDesignTable
swApp.ActivateDoc3 swViewModel.GetPathName, False, swRebuildOnActivation_e.swDontRebuildActiveDoc, lErrors
If swDesignTable.Attach = False Then
swApp.SendMsgToUser2 "Error: Failed to attach design table.", swMessageBoxIcon_e.swMbStop, swMessageBoxBtn_e.swMbOk
totalRow = swDesignTable.GetTotalRowCount
totalColumn = swDesignTable.GetTotalColumnCount
Set swTableAnn = swDraw.InsertTableAnnotation2(True, 0, 0, swBOMConfigurationAnchorType_e.swBOMConfigurationAnchor_TopLeft, "", totalRow + 1, totalColumn + 1)
For i = 0 To totalRow
For j = 0 To totalColumn
swTableAnn.Text(i, j) = swDesignTable.GetEntryValue(i, j)
If swModel.Save3(swSaveAsOptions_e.swSaveAsOptions_Silent, lErrors, lWarnings) = False Then
swApp.SendMsgToUser2 "Error: Failed to save active drawing document.", swMessageBoxIcon_e.swMbStop, swMessageBoxBtn_e.swMbOk
I needed the design table from part model to be inserted in the drawing
so that if I'm going to update the data in the design table in the part model
it automatically updates the design table in the drawing.
Anyways thanks for this work around you made but I already found out
how to insert the design table from part model.
I used this function InsertFamilyTableNew.
Thank you so much.
No wonder nobody could find that function with a name like that. Thanks for sharing the solution
I did found it but got deceived with this line and didn't checked the remarks below. I've submitted a feedback for correcting this.
The macro recorder doesn't record anything while inserting a design table, unfortunately. I couldn't find anything in the API help either.
I did notice however that the table gets treated like an OLE object. Maybe you can use InsertObjectFromFile to insert the excel document?
2015 SOLIDWORKS API Help - InsertObjectFromFile Method (IModelDocExtension)
Retrieving data ...