I am trying to open drawing documents using vb.net OpenDoc6 command. This is a snippet of my code where i try to traverse through all the files and try to open drawings.
Whenever it tries to open the file, it gives me a nullreferenceexception. I am not able to pin this down on one particular thing. It could be the parameters that i am trying to pass when calling OpenDoc.
Imports EPDM.Interop.epdm
Imports SldWorks
Imports SolidWorks.Interop
Imports SolidWorks.Interop.sldworks
Imports SolidWorks.Interop.swconst
Imports SolidWorks.Interop.sldworks
Imports SolidWorks.Interop.swconst
Imports System.Runtime.InteropServices
Imports System
Imports System.Diagnostics
Public Class TraverseFilesFolders
Dim swApp As SldWorks.SldWorks
Dim swDraw As SldWorks.DrawingDoc
Dim swSheet As SldWorks.Sheet
Dim swModDoc As SldWorks.ModelDoc2
Dim longstatus As Integer = 0
Dim longwarning As Integer = 0
Dim vault As IEdmVault17
Public Sub TraverseFilesFolders_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Try
Dim Views() As EdmViewInfo = Nothing
Dim vault5 As IEdmVault5 = New EdmVault5()
vault = DirectCast(vault5, IEdmVault17)
vault.GetVaultViews(Views, False)
VaultsComboBox.Items.Clear()
For Each View As EdmViewInfo In Views
VaultsComboBox.Items.Add(View.mbsVaultName)
Next
If VaultsComboBox.Items.Count > 0 Then
VaultsComboBox.Text = VaultsComboBox.Items(0)
End If
Catch ex As Runtime.InteropServices.COMException
MessageBox.Show("HRESULT = 0x" + ex.ErrorCode.ToString("X") + vbCrLf + ex.Message)
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
End Sub
Public Sub TraverseFoldersButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TraverseFoldersButton.Click
Try
'Log into selected vault as the current user
vault.LoginAuto(VaultsComboBox.Text, Me.Handle.ToInt32())
MessageBox.Show(vault.GetVaultType().ToString(), "Vault type")
Dim log As String = Nothing
vault.GetClientLog(log)
'TextBox1.Text = log
TraverseFolder(vault.RootFolder)
Catch ex As Runtime.InteropServices.COMException
MessageBox.Show("HRESULT = 0x" + ex.ErrorCode.ToString("X") + vbCrLf + ex.Message)
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
End Sub
Public Sub TraverseFolder(ByVal CurFolder As IEdmFolder5)
Try
'Enumerate the files in the folder
Dim FilePos As IEdmPos5
FilePos = CurFolder.GetFirstFilePosition
Dim file As IEdmFile5
While Not FilePos.IsNull
file = CurFolder.GetNextFile(FilePos)
'Get its checked out status
If file.IsLocked Then
ListBox2.Items.Add(file.LockPath)
ElseIf Not file.IsLocked And file.GetLocalPath(CurFolder.ID).ToString.Contains("SLDDRW") Then
MessageBox.Show(file.GetLocalPath(CurFolder.ID).ToString)
Try
swModDoc = swApp.OpenDoc6(file.GetLocalPath(CurFolder.ID).ToString, 3, 0, "", longstatus, longwarning)
Catch ex As NullReferenceException
MessageBox.Show(ex.ToString)
End Try
End If
End While
'Enumerate the subfolders in the folder
Dim FolderPos As IEdmPos5
FolderPos = CurFolder.GetFirstSubFolderPosition
While Not FolderPos.IsNull
Dim SubFolder As IEdmFolder5
SubFolder = CurFolder.GetNextSubFolder(FolderPos)
TraverseFolder(SubFolder)
End While
Catch ex As Runtime.InteropServices.COMException
MessageBox.Show("HRESULT = 0x" + ex.ErrorCode.ToString("X") + vbCrLf + ex.Message)
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
End Sub
End Class