We want to increase efficiency, speed, and productivity by automating repetitive tasks and eliminating manual errors in my team.
And I believe these will help you increase your and your team's as well.
Access our user-friendly platform, download the macros that suit your needs, and integrate them seamlessly into your design Solidworks software.
Join us on this journey to unlock your full potential, streamline processes, and achieve exceptional results. Elevate your productivity today with our free macros.
Create Automatic Drawings from a Solidworks Part
Sub main()
Dim swapp As SldWorks.SldWorks
Dim swmodel As SldWorks.ModelDoc2
Set swapp = Application.SldWorks
Dim retval As String
Dim swdraw As SldWorks.DrawingDoc
Dim swDrawing As SldWorks.DrawingDoc
Dim annotations As Variant
' Rebuild the document
Set swmodel = swapp.ActiveDoc
swmodel.ForceRebuild3 True
' Save the document
swmodel.Save3 swSaveAsOptions_Silent, Empty, Empty
' Get Model Path
Dim strModelPath As String
strModelPath = swmodel.GetPathName
' Create Drawing
retval = swapp.GetUserPreferenceStringValue(swDefaultTemplateDrawing)
Set swdraw = swapp.NewDocument(retval, 0, 0, 0)
' Create Drawing Views
Set swDrawing = swdraw
swDrawing.Create3rdAngleViews2 strModelPath
' Insert the annotations marked for the drawing
annotations = swDrawing.InsertModelAnnotations3(0, swInsertDimensionsMarkedForDrawing, True, False, False, False)
' Save the drawing file with the same name as the part
Dim swModelDocExt As SldWorks.ModelDocExtension
Set swModelDocExt = swmodel.Extension
Dim lErrors As Long
Dim lWarnings As Long
Dim opt As Long
Dim partName As String
Dim drawingPath As String
partName = Left(swmodel.GetPathName, InStrRev(swmodel.GetPathName, ".") - 1)
drawingPath = Left(strModelPath, InStrRev(strModelPath, "\")) & partName & ".slddrw"
swModelDocExt.SaveAs2 drawingPath, 0, opt, Nothing, "_Suff", False, lErrors, lWarnings
End Sub
Convert Solidworks Drawing to PDF
Dim FileName As String
Dim swExportPDFData As SldWorks.ExportPdfData
Dim swModel As SldWorks.ModelDoc2
Dim swApp As SldWorks.SldWorks
Sub main()
Set swApp = Application.SldWorks
Set swModel = swApp.ActiveDoc
'Save Drawing
swModel.Save3 0, 0, 0
'Checks to make sure current file is a drawing
If swModel.GetType = swDocDRAWING Then
'Gets current file name and path
FileName = swModel.GetPathName
'strips solidworks extension off name and replaces with pdf
FileName = Left(FileName, Len(FileName) - 6) & "pdf"
'message box line used to confirm modified file name
'MsgBox FileName
'sets current pdf export options
Set swExportPDFData = swApp.GetExportFileData(1)
'saves drawing as pdf
swModel.Extension.SaveAs FileName, 0, 0, swExportPDFData, 0, 0
Else
MsgBox "Current File is not a Drawing"
End
End If
End Sub
Comments