Message 1 of 4

Not applicable
10-12-2010
08:32 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hi all,
I'm trying to do what I consider a simple task (at least it's simple in VBA, but I'm trying to move away from VBA since it's no longer supported): Create a new, blank DWG file, save it to a specified directory and have it become the active file inside the ACAD UI for further editing.
I've been able to cobble together several variations of code that adds a new document to the UI, and even saves it out to the proper location'/filename, but even when it accomplishes this successfully, ACAD dies when I close it down with: "FATAL ERROR: Unhandled Access Violation Reading 0x0041 Exception at 3f892986h".
For background, I'm running ACAD2011 (plain) on Windows 7, 64-bit. The code that I've used with best results is a brute-force, stuff-the-command-line setup as follows (with thanks to Kean Walmsley of "Through the Interface"):
Imports Autodesk.AutoCAD.Interop
Imports Autodesk.AutoCAD.Interop.Common
Imports Autodesk.AutoCAD.ApplicationServices
Imports Autodesk.AutoCAD.Runtime
<CommandMethod("bmiFileNew", CommandFlags.Modal)> _
Public Sub bmiFileNew()
Dim ufn As New ufFileNew
Dim drResult As System.Windows.Forms.DialogResult
Dim dwgActive As Document
Dim sPrototypeDwg As String
Dim sNewFilename As String
Dim sLispCommand As String
NewFile = ""
Try
drResult = Application.ShowModalDialog(ufn)
If NewFile <> "" Then
sPrototypeDwg = "C:\TEMP\Template2011"
sNewFilename = "C:\TEMP\" & NewFile
Dim acDocMgr As DocumentCollection = Application.DocumentManager
dwgActive = acDocMgr.Add(sPrototypeDwg)
sNewFilename = Replace(sNewFilename, "\", "/")
Dim ocmd As Object = Application.GetSystemVariable("CMDECHO")
sLispCommand = "(setvar ""CMDECHO"" 1) " & _
"(command ""_.SAVEAS"" ""2010"" """ & sNewFilename & """) " & _
"(setvar ""CMDECHO"" " & ocmd.ToString & ") " & _
"(princ) "
dwgActive.SendStringToExecute(sLispCommand, _
True, _
False, _
True)
acDocMgr.MdiActiveDocument = dwgActive
End If
Catch ex As Exception
MsgBox(ex.Message.ToString)
End Try
End Sub
I've also tried using Database.Saveas() and Document.SaveAs() alternatives with less success than this and still I have the fatal error when exiting ACAD. Any assistance would be much appreciated.
Thanks,
Dave
I'm trying to do what I consider a simple task (at least it's simple in VBA, but I'm trying to move away from VBA since it's no longer supported): Create a new, blank DWG file, save it to a specified directory and have it become the active file inside the ACAD UI for further editing.
I've been able to cobble together several variations of code that adds a new document to the UI, and even saves it out to the proper location'/filename, but even when it accomplishes this successfully, ACAD dies when I close it down with: "FATAL ERROR: Unhandled Access Violation Reading 0x0041 Exception at 3f892986h".
For background, I'm running ACAD2011 (plain) on Windows 7, 64-bit. The code that I've used with best results is a brute-force, stuff-the-command-line setup as follows (with thanks to Kean Walmsley of "Through the Interface"):
Imports Autodesk.AutoCAD.Interop
Imports Autodesk.AutoCAD.Interop.Common
Imports Autodesk.AutoCAD.ApplicationServices
Imports Autodesk.AutoCAD.Runtime
<CommandMethod("bmiFileNew", CommandFlags.Modal)> _
Public Sub bmiFileNew()
Dim ufn As New ufFileNew
Dim drResult As System.Windows.Forms.DialogResult
Dim dwgActive As Document
Dim sPrototypeDwg As String
Dim sNewFilename As String
Dim sLispCommand As String
NewFile = ""
Try
drResult = Application.ShowModalDialog(ufn)
If NewFile <> "" Then
sPrototypeDwg = "C:\TEMP\Template2011"
sNewFilename = "C:\TEMP\" & NewFile
Dim acDocMgr As DocumentCollection = Application.DocumentManager
dwgActive = acDocMgr.Add(sPrototypeDwg)
sNewFilename = Replace(sNewFilename, "\", "/")
Dim ocmd As Object = Application.GetSystemVariable("CMDECHO")
sLispCommand = "(setvar ""CMDECHO"" 1) " & _
"(command ""_.SAVEAS"" ""2010"" """ & sNewFilename & """) " & _
"(setvar ""CMDECHO"" " & ocmd.ToString & ") " & _
"(princ) "
dwgActive.SendStringToExecute(sLispCommand, _
True, _
False, _
True)
acDocMgr.MdiActiveDocument = dwgActive
End If
Catch ex As Exception
MsgBox(ex.Message.ToString)
End Try
End Sub
I've also tried using Database.Saveas() and Document.SaveAs() alternatives with less success than this and still I have the fatal error when exiting ACAD. Any assistance would be much appreciated.
Thanks,
Dave
Solved! Go to Solution.