Imports Autodesk.AutoCAD.Runtime
Imports Autodesk.AutoCAD.DatabaseServices
Imports Autodesk.AutoCAD.ApplicationServices
Imports AcApp = Autodesk.AutoCAD.ApplicationServices.Application
Imports Autodesk.AutoCAD.EditorInput
<Assembly: ExtensionApplication(GetType(VbExtApp))>
Public Class VbExtApp
Implements Autodesk.AutoCAD.Runtime.IExtensionApplication
Private DocMan As DocumentCollection
'Initialize sub
Public Sub Initialize() Implements Autodesk.AutoCAD.Runtime.IExtensionApplication.Initialize
DocMan = AcApp.DocumentManager
AddHandler DocMan.DocumentCreated, AddressOf callback_documentCreated
AddHandler DocMan.DocumentActivated, AddressOf callback_documentActivated
Dim doc As Document
For Each doc In DocMan
Dim db As Database = doc.Database
Dim ed As Editor = doc.Editor
AddHandler db.ObjectModified, AddressOf callback_ObjectModified
AddHandler db.ObjectAppended, AddressOf callback_ObjectAppended
AddHandler db.ObjectErased, AddressOf callback_ObjectErased
AddHandler ed.SelectionAdded, AddressOf callback_SelectionAdded
' AddHandler ed.SelectionRemoved, AddressOf callback_SelectionRemoved
Next
'Import Blocks
ImportBlocks("D:\My Documents\Visual Studio Projects\Detailer\Blocks.dwg")
'Load Palette
Loading = True
pal = New Palette()
pal.LoadPalette()
Loading = False
'Initialise Thumbnail Class
Dim thumb As ThumbNailClass
thumb = New ThumbNailClass
End Sub
'SelectionAdded
Public Sub callback_SelectionAdded(ByVal sender As System.Object, ByVal e As Autodesk.AutoCAD.EditorInput.SelectionAddedEventArgs)
'MsgBox("Selection Made")
For Each objid As ObjectId In e.AddedObjects.GetObjectIds
ID = objid
ReDim Preserve ObjectCollection(0)
ReDim Preserve ObjectCollection(0).Set_(0)
ReDim Preserve ObjectCollection(0).Set_(0).View(0)
ReDim Preserve ObjectCollection(0).Set_(0).Range(0)
ReDim Preserve ObjectCollection(0).Set_(0).Label(0)
NoViews = 0 : NoRanges = 0 : NoLabels = 0
ObjectsSelected()
Next
End Sub
'Terminate sub
Public Sub Terminate() Implements Autodesk.AutoCAD.Runtime.IExtensionApplication.Terminate
RemoveHandler DocMan.DocumentCreated, AddressOf callback_documentCreated
End Sub
Public Shared Sub callback_ObjectModified(ByVal sender As System.Object, ByVal e As Autodesk.AutoCAD.DatabaseServices.ObjectEventArgs)
'MsgBox("Something was modified")
ID = e.DBObject.ObjectId
ModifyEventHander()
End Sub
Public Shared Sub callback_ObjectAppended(ByVal sender As System.Object, ByVal e As Autodesk.AutoCAD.DatabaseServices.ObjectEventArgs)
'MsgBox("Something was Appended")
End Sub
Public Shared Sub callback_ObjectErased(ByVal sender As System.Object, ByVal e As Autodesk.AutoCAD.DatabaseServices.ObjectErasedEventArgs)
'MsgBox("Something was Erased")
ID = e.DBObject.ObjectId
DeleteEventHandler()
End Sub
Private Sub callback_documentCreated(ByVal sender As Object, ByVal e As DocumentCollectionEventArgs)
If e.Document = Nothing Then
Exit Sub
Else
' MsgBox("Document Created")
End If
End Sub
Private Sub callback_documentActivated(ByVal sender As Object, ByVal e As DocumentCollectionEventArgs)
If e.Document = Nothing Then
Exit Sub
Else
' MsgBox("Document Active")
End If
End Sub
End Class