Skip to content

Commit b2bc0d1

Browse files
committed
Fixed the split cut-list to configurations macro to exclude empty cut-lists
Added the progress bar to split cut-list to configurations macro Added the option to find tables from active sheet only for the export table to csv Added option to 3D PDF export for the multi format export macro
1 parent a059187 commit b2bc0d1

File tree

7 files changed

+101
-34
lines changed

7 files changed

+101
-34
lines changed

solidworks-api/document/cut-lists/split-to-configurations/Macro.vba

Lines changed: 30 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,16 @@ Dim swApp As SldWorks.SldWorks
44

55
Sub main()
66

7+
Dim swProgressBar As SldWorks.UserProgressBar
8+
79
try_:
810

911
On Error GoTo catch_
1012

1113
Set swApp = Application.SldWorks
1214

15+
swApp.GetUserProgressBar swProgressBar
16+
1317
Dim swModel As SldWorks.ModelDoc2
1418

1519
Set swModel = swApp.ActiveDoc
@@ -21,6 +25,8 @@ try_:
2125
Dim vCutLists As Variant
2226
vCutLists = GetCutLists(swModel)
2327

28+
swProgressBar.Start 0, UBound(vCutLists), "Creating configurations for cut-lists"
29+
2430
Dim i As Integer
2531

2632
For i = 0 To UBound(vCutLists)
@@ -31,17 +37,30 @@ try_:
3137
Dim swCutListFolder As SldWorks.BodyFolder
3238
Set swCutListFolder = swCutList.GetSpecificFeature2
3339

34-
Dim vBodies As Variant
40+
Dim vCutListBodies As Variant
41+
vCutListBodies = swCutListFolder.GetBodies()
42+
43+
If Not IsEmpty(vCutListBodies) Then
44+
45+
Dim vBodies As Variant
46+
47+
If KEEP_ALL_CUT_LIST_BODIES Then
48+
vBodies = vCutListBodies
49+
Else
50+
Dim swBody(0) As SldWorks.Body2
51+
Set swBody(0) = vCutListBodies(0)
52+
vBodies = swBody
53+
End If
54+
55+
Debug.Print "Creating configuration for " & swCutList.Name
56+
57+
CreateConfigurationForBodies swModel, vBodies, swCutList.Name
3558

36-
If KEEP_ALL_CUT_LIST_BODIES Then
37-
vBodies = swCutListFolder.GetBodies
3859
Else
39-
Dim swBody(0) As SldWorks.Body2
40-
Set swBody(0) = swCutListFolder.GetBodies()(0)
41-
vBodies = swBody
60+
Debug.Print swCutList.Name & " has no bodies"
4261
End If
4362

44-
CreateConfigurationForBodies swModel, vBodies, swCutList.Name
63+
swProgressBar.UpdateProgress i + 1
4564

4665
Next
4766

@@ -57,6 +76,10 @@ try_:
5776
catch_:
5877
MsgBox Err.Description, vbCritical
5978
finally_:
79+
80+
If Not swProgressBar Is Nothing Then
81+
swProgressBar.End
82+
End If
6083

6184
End Sub
6285

solidworks-api/document/cut-lists/split-to-configurations/index.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,12 @@ Macro will create as many configurations as cut-lists feature in the document an
1616

1717
Macro will name the configuration after the cut-list name.
1818

19+
Macro will display the progress bar in the SOLIDWORKS icon:
20+
21+
![Progress of the operation](progress-bar.png)
22+
23+
## Configuration
24+
1925
**KEEP_ALL_CUT_LIST_BODIES** constant allows to control should the macro isolate all cut-list bodies or only keep a single unique body.
2026

2127
~~~ vb
7.12 KB
Loading

solidworks-api/document/tables/export-table-csv/Macro.vba

Lines changed: 38 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22

33
Const OUT_FILE_PATH_TEMPLATE As String = "<_FileName_>-<_TableName_>.csv" 'ouput file path template
44
Const INCLUDE_HEADER As Boolean = True
5-
Const TABLE_TYPE As Integer = -1 '-1 to use selected table or table type as defined in swTableAnnotationType_e
5+
Const TABLE_TYPE As Integer = -1 '-1 to use selected table or table type as defined in swTableAnnotationType_e
6+
Const ALL_SHEETS As Boolean = True 'True to export from all sheets (if TABLE_TYPE is not -1), False to export from active sheet only
67

78
Const MERGE As Boolean = False
89

@@ -71,7 +72,18 @@ try_:
7172
Err.Raise vbError, "", "Only drawing document is supported"
7273
End If
7374

74-
vTables = FindTables(swModel, tableType)
75+
Dim swDraw As SldWorks.DrawingDoc
76+
Set swDraw = swModel
77+
78+
Dim sheetName As String
79+
80+
If ALL_SHEETS Then
81+
sheetName = ""
82+
Else
83+
sheetName = swDraw.GetCurrentSheet().GetName
84+
End If
85+
86+
vTables = FindTables(swDraw, tableType, sheetName)
7587

7688
End If
7789

@@ -180,7 +192,7 @@ Function GetTableData(tableAnn As SldWorks.TableAnnotation, includeHeader As Boo
180192

181193
End Function
182194

183-
Function FindTables(draw As SldWorks.DrawingDoc, filter As swTableAnnotationType_e) As Variant
195+
Function FindTables(draw As SldWorks.DrawingDoc, filter As swTableAnnotationType_e, sheetName As String) As Variant
184196

185197
Dim swTables() As SldWorks.TableAnnotation
186198
Dim isInit As Boolean
@@ -200,33 +212,37 @@ Function FindTables(draw As SldWorks.DrawingDoc, filter As swTableAnnotationType
200212
Dim swSheetView As SldWorks.View
201213
Set swSheetView = vViews(0)
202214

203-
Dim vTableAnns As Variant
204-
vTableAnns = swSheetView.GetTableAnnotations
215+
If sheetName = "" Or LCase(sheetName) = LCase(swSheetView.Name) Then
205216

206-
If Not IsEmpty(vTableAnns) Then
207-
208-
Dim j As Integer
217+
Dim vTableAnns As Variant
218+
vTableAnns = swSheetView.GetTableAnnotations
209219

210-
For j = 0 To UBound(vTableAnns)
220+
If Not IsEmpty(vTableAnns) Then
211221

212-
Dim swTableAnn As SldWorks.TableAnnotation
213-
Set swTableAnn = vTableAnns(j)
222+
Dim j As Integer
214223

215-
If swTableAnn.Type = filter Then
224+
For j = 0 To UBound(vTableAnns)
216225

217-
If isInit Then
218-
ReDim Preserve swTables(UBound(swTables) + 1)
219-
Else
220-
ReDim swTables(0)
221-
isInit = True
222-
End If
226+
Dim swTableAnn As SldWorks.TableAnnotation
227+
Set swTableAnn = vTableAnns(j)
223228

224-
Set swTables(UBound(swTables)) = swTableAnn
229+
If swTableAnn.Type = filter Then
230+
231+
If isInit Then
232+
ReDim Preserve swTables(UBound(swTables) + 1)
233+
Else
234+
ReDim swTables(0)
235+
isInit = True
236+
End If
237+
238+
Set swTables(UBound(swTables)) = swTableAnn
239+
240+
End If
225241

226-
End If
242+
Next
227243

228-
Next
229-
244+
End If
245+
230246
End If
231247

232248
Next

solidworks-api/document/tables/export-table-csv/index.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ Macro can be configured by modifying the value of the constants
3939
Const OUT_FILE_PATH_TEMPLATE As String = "<_FileName_>-<_TableName_>.csv" 'empty string to save in the model's folder
4040
Const INCLUDE_HEADER As Boolean = True 'True to include the table header, False to only include data
4141
Const TABLE_TYPE As Integer = swTableAnnotationType_e.swTableAnnotation_BillOfMaterials '-1 to use selected table or table type as defined in swTableAnnotationType_e (e.g. swTableAnnotationType_e.swTableAnnotation_BillOfMaterials to export all BOM tables)
42+
Const ALL_SHEETS As Boolean = False 'False to export from active sheet only
4243

4344
Const MERGE As Boolean = False 'True to merge all tables into a single file
4445
~~~

solidworks-api/import-export/export-multi-formats/Macro.vba

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
Const ALL_CONFIGS As Boolean = False
22
Const OUT_FOLDER As String = ""
33
Const STEP_VERSION As Long = 214 '203 or 214
4+
Const PDF_3D As Boolean = False 'True to export 3D PDF
45

56
Dim OUT_NAME_TEMPLATES As Variant
67

@@ -115,8 +116,20 @@ Sub ExportFile(model As SldWorks.ModelDoc2, vOutNameTemplates As Variant, allCon
115116
outDir = Left(outFilePath, InStrRev(outFilePath, "\"))
116117

117118
CreateDirectories outDir
118-
119-
If False = model.Extension.SaveAs(outFilePath, swSaveAsVersion_e.swSaveAsCurrentVersion, swSaveAsOptions_e.swSaveAsOptions_Silent, Nothing, errs, warns) Then
119+
120+
Dim swExportData As Object
121+
122+
If LCase(GetExtension(outFilePath)) = LCase("pdf") Then
123+
Dim swExportPdfData As SldWorks.ExportPdfData
124+
Set swExportPdfData = swApp.GetExportFileData(swExportDataFileType_e.swExportPdfData)
125+
swExportPdfData.ViewPdfAfterSaving = False
126+
swExportPdfData.ExportAs3D = PDF_3D
127+
Set swExportData = swExportPdfData
128+
Else
129+
Set swExportData = Nothing
130+
End If
131+
132+
If False = model.Extension.SaveAs(outFilePath, swSaveAsVersion_e.swSaveAsCurrentVersion, swSaveAsOptions_e.swSaveAsOptions_Silent, swExportData, errs, warns) Then
120133
Err.Raise vberrror, "", "Failed to export to " & outFilePath
121134
End If
122135

@@ -226,9 +239,11 @@ Function ResolveToken(token As String, model As SldWorks.ModelDoc2) As String
226239
End Function
227240

228241
Function GetFileNameWithoutExtension(path As String) As String
229-
230242
GetFileNameWithoutExtension = Mid(path, InStrRev(path, "\") + 1, InStrRev(path, ".") - InStrRev(path, "\") - 1)
231-
243+
End Function
244+
245+
Function GetExtension(path As String) As String
246+
GetExtension = Right(path, Len(path) - InStrRev(path, "."))
232247
End Function
233248

234249
Function FileExists(filePath As String) As Boolean

solidworks-api/import-export/export-multi-formats/index.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,12 +53,18 @@ Sub main()
5353

5454
### Export Options
5555

56-
Export options for STEP format can be configured by changing the value of the **STEP_VERSION** variable. Set it to **214** for **AP214** format or to **203** to **AP203** format.
56+
Export options for STEP format can be configured by changing the value of the **STEP_VERSION** constant. Set it to **214** for **AP214** format or to **203** to **AP203** format.
5757

5858
~~~ vb
5959
Const STEP_VERSION As Long = 214 '203 or 214
6060
~~~
6161

62+
To export 3D PDF set the **PDF_3D** constant to **True**
63+
64+
~~~ vb
65+
Const PDF_3D As Boolean = True
66+
~~~
67+
6268
### Include Component Quantity Into File Name
6369

6470
If this macro is run for all components of the assembly, it might be required to include the BOM quantity into the file name. Use the [Write component quantity in the SOLIDWORKS assembly to custom property

0 commit comments

Comments
 (0)