HI ,
I got a problem to open a dxf file. If I use command method then I can easily do that. But I want to open that file by clicking a button from my windows form. I did the coding for that specified button like below:
Private Sub Button6_Click(sender As System.Object, e As System.EventArgs) Handles Button6.Click
Dim strFileName AsString
LoadDXF.InitialDirectory = "C:\"
LoadDXF.Title = "Open DXF File"
LoadDXF.Filter = "DXF Files|*.dxf"
LoadDXF.ShowDialog()
strFileName = LoadDXF.FileName
Dim acDocMgr AsDocumentCollection = Application.DocumentManager
If (File.Exists(strFileName)) Then
acDocMgr.Open(strFileName, False)
Else
acDocMgr.MdiActiveDocument.Editor.WriteMessage( "File" & strFileName & "does not exist.")
EndIf
EndSub
After invoke that button I got a error like below:
I have searched to solve this problem in the forum. But did not get any productive answer. Can anybody help me in this regards. How can I open the drawing without commandFlags.session? I want to use the button of my form to open that dxf file. Please give me a details hints because I am pretty new in programming.
Thanks in advance.
Zakir
Solved! Go to Solution.
Try something like this. I haven't tried but I think it should work. Let me know if it doesn't and please next time post the full text from the exception detail. (FYI: I had to correct my original response!)
Dim LoadDXF As New System.Windows.Forms.OpenFileDialog
LoadDXF.InitialDirectory = "C:\"
LoadDXF.Title = "Open DXF File"
LoadDXF.Filter = "DXF Files|*.dxf"
Dim acDocMgr As DocumentCollection = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager
Try
If LoadDXF.ShowDialog() = System.Windows.Forms.DialogResult.OK Then
Dim files() As String = LoadDXF.FileNames
For Each _file In files
If (File.Exists(_file)) Then
Dim acDoc As Document = DocumentCollectionExtension.Add(acDocMgr, _file)
acDocMgr.MdiActiveDocument = acDoc
Else
acDocMgr.MdiActiveDocument.Editor.WriteMessage("File " & _file & " does not exist.")
End If
Next
End If
Catch
acDocMgr.MdiActiveDocument.Editor.WriteMessage("ERROR: " & Err.Description)
End Try
Another important piece of Info that's needed here is what version of ACAD are we talking about?! I assumed the latest (2013). If not opening the Document object is going to be slightly different:
Thanks for your reply. I am sorry that I did not mention my ACAD version and VB version. I am using ACAD 2011 and VB2010 (premium). I am also sorry that I did not understand one of your sentence "please next time post the full text from the exception detail". Actually I do not know how to post from exception detail.
I try to write according you show. But when I try to write the line below
Dim acDoc As Document = DocumentCollectionExtension, it tells me that DocumentCollectionExtension is not declared.
my code is now look like below:
If you have time please let me share your suggestion. Thanks anyway
Ok, that's great.
You can find the original ACAD .NET exception in the dialog box you captured and posted with your question if you just push the "Details" button.
Also, the "For Each _file In files" loop only makes sense if you allow the user to select multiple files. I just noticed that later but if you do that you wil need some additional acad code to make it work so you can probably just lose the loop and go with the original idea of allowing only 1 file to be selected and simply assigning _file to LoadDXF.FileName instead of LoadDXF.FileNames.
Can't find what you're looking for? Ask the community or share your knowledge.