I need help with a SolidWorks macro to export the hole table from a drawing sheet into a CSV or Excel file. The exported file name should be based on the configuration-specific property of the associated part.
Requirements:
Extract the hole table from a SolidWorks drawing sheet.
Export the hole table data (hole size, type, position, etc.) to a CSV or Excel file.
The file name should be dynamically set using a configuration-specific property from the associated part.
Thank you for your quick support.
This code is working fine, I need help regarding the exported CSV file name I want configuration properties instead of file names for the exported file name.
Something like,
Dim Length As String
Dim PartNumber As String
Dim FileName As String
PartNumber = swModel.GetCustomInfoValue(“Default”, “V_Name”)
Length= swModel.GetCustomInfoValue(“Default”, “Length”)
FileName = Left(swDraw.GetPathName, InStrRev(swDraw.GetPathName, "")) & PartNumber & Length
Currently, it is taking the drawing file name as a CSV file name.
Function GetExportFilePath(pathTemplate As String, model As SldWorks.ModelDoc2, tableAnn As SldWorks.TableAnnotation) As String
Const FILE_NAME_TOKEN As String = “<FileName>”
Const TABLE_NAME_TOKEN As String = “<TableName>”
Const SHEET_NAME_TOKEN As String = “<SheetName>”
Dim path As String
path = pathTemplate
If InStr(path, FILE_NAME_TOKEN) > 0 Then
path = Replace(pathTemplate, FILE_NAME_TOKEN, GetFileNameWithoutExtension(model.GetPathName()))
End If
If InStr(path, SHEET_NAME_TOKEN) > 0 Then
Dim swSheet As SldWorks.Sheet
Set swSheet = GetSheetFromTableAnnotation(model, tableAnn)
path = Replace(path, SHEET_NAME_TOKEN, swSheet.GetName())
End If
If InStr(path, TABLE_NAME_TOKEN) > 0 Then
Dim swTableFeat As SldWorks.Feature
Set swTableFeat = GetFeatureFromTableAnnotation(tableAnn)
path = Replace(path, TABLE_NAME_TOKEN, swTableFeat.Name)
End If
Please show us what you have tried, which line gets an error, and what the error is. That way you can learn. If I just write the code for you the benefit is greatly reduced.
Thank you for not providing a direct solution, in a few days I learned so much!
I just took reference from Export SOLIDWORKS table to CSV using VBA macro.swp (51.5 KB)
and
Export Open Drawings as PDF_DWG (SW2019) (1).zip
by Deepak Gupta. I merged both into one as per my basic understanding.
It’s now working perfectly when only a single drawing document is open. I attempted to add a second macro as a function, but I was unsuccessful. Instead, I called the second macro and used its output as the file name.
V.1 My next step is to update the code so that it runs only for the active drawing document. Alternatively, if multiple drawings are open in SolidWorks, it should export the table from all open drawings.
V.2 If I run the macro while the main assembly is open, it should open the drawing for each part, check if the table is available, and if so, export the table and close the drawing.
Are you saying that because it looks like gibberish characters? You’re such a racist…
Dhruv is (based on a Google search) not an uncommon Indian name. Mfg is, of course, manufacturing. BPP would by my guess for an abbreviation of a company name.
That is exactly why haha, your explanation makes total sense. I don’t often see Mfg for Manufacturing which is why it didn’t really ring as an acronym to me.
It’s probably fairly common in english and in the industrial world but being in Quebec limits my english to these forums and the internet pretty much. If I were to have to pass orders and things of that nature I’d most likely be more accustomed to it.