open part/assembly from list

Programming and macros
jdawgsk1
Posts: 1
Joined: Thu Jun 08, 2023 9:44 am
Answers: 0

open part/assembly from list

Unread post by jdawgsk1 »

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
User avatar
josh
Posts: 249
Joined: Thu Mar 11, 2021 1:05 pm
Answers: 11
x 19
x 440

Re: open part/assembly from list

Unread post by josh »

You're just going to have to debug it. Simplify it down until you get it to work. Or start at the bottom. Write a sub with just OpenDoc6 and a hard coded path and see if it works. Work your way out from there.

Or post enough stuff here (sample files, etc) so we can recreate your issue. Make it as easy as possible for someone to replicate your efforts. (during this process, you may find your bug btw)
Post Reply