open part/assembly from list
Posted: Thu Jun 08, 2023 11:41 am
I'm creating a spreadsheet to save jpegs of Solidworks files. the current issue I am having is the ability to open the files from the list.
I'm trying to use opendoc6 but keep getting an error that the file is corrupted and cannot be repaired.
here is the code
Option Explicit
Dim swApp As SldWorks.SldWorks
Dim swModel As SldWorks.ModelDoc2
Dim swModelDocExt As SldWorks.ModelDocExtension
Dim swExportPDFData As SldWorks.ExportPdfData
Dim boolstatus As Boolean
Dim FileName As String
Dim filePath As String
Dim lErrors As Long
Dim lWarnings As Long
Dim nDocType As Long
Dim longstatus As Long, longwarnings As Long
Dim bRbld As Boolean
Sub jpgsw(PARTNUMBER, path, config)
'sValue = ActiveSheet.Names("MyNamedRange").Value
filePath = Range("SAVE").Value
' Path to which to save PDF file of drawing
FileName = filePath & "\" & PARTNUMBER & ".JPG"
Set swApp = CreateObject("SldWorks.Application") 'activates solidworks
swApp.Visible = True
' Determine type of SOLIDWORKS file based on file extension
If InStr(LCase(path), "sldprt") > 0 Then
nDocType = swDocPART
ElseIf InStr(LCase(path), "sldasm") > 0 Then
nDocType = swDocASSEMBLY
End If
' Open specified model
Set swModel = swApp.OpenDoc6(path, nDocType, swOpenDocOptions_ReadOnly, config, lErrors, lWarnings)
' bRbld = swModel.ForceRebuild3(False)
' While bRbld = False
' Application.Wait (Now + TimeValue("00:00:05"))
Wend
swModel.ShowNamedView2 "*Isometric", -1
swModel.ViewZoomtofit2
longstatus = swModel.SaveAs3(FileName, 0, 0)
' swApp.CloseDoc swModel.GetTitle
End Sub
thanks
I'm trying to use opendoc6 but keep getting an error that the file is corrupted and cannot be repaired.
here is the code
Option Explicit
Dim swApp As SldWorks.SldWorks
Dim swModel As SldWorks.ModelDoc2
Dim swModelDocExt As SldWorks.ModelDocExtension
Dim swExportPDFData As SldWorks.ExportPdfData
Dim boolstatus As Boolean
Dim FileName As String
Dim filePath As String
Dim lErrors As Long
Dim lWarnings As Long
Dim nDocType As Long
Dim longstatus As Long, longwarnings As Long
Dim bRbld As Boolean
Sub jpgsw(PARTNUMBER, path, config)
'sValue = ActiveSheet.Names("MyNamedRange").Value
filePath = Range("SAVE").Value
' Path to which to save PDF file of drawing
FileName = filePath & "\" & PARTNUMBER & ".JPG"
Set swApp = CreateObject("SldWorks.Application") 'activates solidworks
swApp.Visible = True
' Determine type of SOLIDWORKS file based on file extension
If InStr(LCase(path), "sldprt") > 0 Then
nDocType = swDocPART
ElseIf InStr(LCase(path), "sldasm") > 0 Then
nDocType = swDocASSEMBLY
End If
' Open specified model
Set swModel = swApp.OpenDoc6(path, nDocType, swOpenDocOptions_ReadOnly, config, lErrors, lWarnings)
' bRbld = swModel.ForceRebuild3(False)
' While bRbld = False
' Application.Wait (Now + TimeValue("00:00:05"))
Wend
swModel.ShowNamedView2 "*Isometric", -1
swModel.ViewZoomtofit2
longstatus = swModel.SaveAs3(FileName, 0, 0)
' swApp.CloseDoc swModel.GetTitle
End Sub
thanks