
Originally Posted by
amaser
Thanx, I'll try to play with that for a bit.
But than why would my code work perfectly for a lot of things, but not some particular files?
Try this Q&D code example for the quick test
then rewrite it to you needs:
Code:
Imports Autodesk.AutoCAD.Runtime
Imports Autodesk.AutoCAD.ApplicationServices
Imports Autodesk.AutoCAD.DatabaseServices
Imports Microsoft.Win32
Imports System.Diagnostics
Imports System.IO
Imports Autodesk.AutoCAD.EditorInput
Namespace Augi
Public Class ExportVersion
Implements Autodesk.AutoCAD.Runtime.IExtensionApplication
'declare variables as private if you need to declare as public
'then realize an accesss to variables using 'get' and 'set' properties
Private dm As DocumentCollection
Private doc As Document
Private db As Database
Private ed As Editor
Const m_Path As String = "c:\"
Private strPath As String
''' <summary>
''' initialize members
''' </summary>
Private Sub MyInitialize()
dm = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager
doc = dm.MdiActiveDocument
db = doc.Database
ed = doc.Editor
strPath = ""
End Sub
''' <summary>
''' method will start on loading
''' </summary>
Public Sub Initialize() Implements Autodesk.AutoCAD.Runtime.IExtensionApplication.Initialize
'initialize variables
Try
If dm Is Nothing Then
MyInitialize()
End If
ed.WriteMessage(vbLf & "Reactor loader started...")
'' here your code to build the path
'' I use dummy path for test ony
strPath = Path.Combine(m_Path, "Test\Boo")
strPath = Path.Combine(strPath, "bla_bla.dwg")
ed.WriteMessage(vbLf & "Possible Full Path: {0}", strPath)
''events register here:
'use simplified syntax to register events
AddHandler doc.BeginDocumentClose, AddressOf OnClosingDocument
Catch ex As Autodesk.AutoCAD.Runtime.Exception
ed.WriteMessage(vbLf & ex.Message & vbLf & ex.StackTrace)
Finally
End Try
ed.WriteMessage(vbLf & "Reactor loader ended..")
End Sub
''' <summary>
''' methods will start on closing document
''' </summary>
''' <remarks></remarks>
Public Sub Terminate() Implements Autodesk.AutoCAD.Runtime.IExtensionApplication.Terminate
Try
RemoveHandler doc.BeginDocumentClose, AddressOf OnClosingDocument
Catch
End Try
End Sub
Private Sub OnClosingDocument(ByVal sender As Object, ByVal e As Autodesk.AutoCAD.ApplicationServices.DocumentBeginCloseEventArgs)
Try
MsgBox(strPath)
db.SaveAs(strPath, False, DwgVersion.AC1021, db.SecurityParameters)
Catch ex As System.Exception
Finally
End Try
End Sub
End Class
End Namespace