
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hi all,
I`m still trying to find a solution to my previous post, displaying a vb.net form when an autocad block reference is double-clicked. Unfortunately, I still don`t know how to capture the double-click event for a block reference from code. I have gone down the IMessageFilter path, still no success.
I have tried the addHandler for application using code supplied to me in my previous post, still no luck. I really need to be able to capture the doubleclick event for a block reference in autocad, without overwriting the default autocad double-click behavior.
I wish to be able to double-click a block reference, capture its name, and, if the name is same as blocks created by my form, then I`d simply have my dot net form pop up, displaying a few of the block`s properties.
Does anyone have any ideas on how this might be accomplishedÉ
Below is the code module I am using, which isn`t working ofr me:
' System
Imports Microsoft.Win32
Imports System.Reflection
' AutoCAD
Imports Autodesk.AutoCAD.ApplicationServices
Imports Autodesk.AutoCAD.Runtime
Imports acApp = Autodesk.AutoCAD.ApplicationServices.Application
Imports Autodesk.AutoCAD.DatabaseServices
Imports Autodesk.AutoCAD.EditorInput
' AutoCAD Interop
Imports acOp = Autodesk.AutoCAD.Interop
Imports acOpCom = Autodesk.AutoCAD.Interop.Common
Module ModDoubleClick
Private acDoc As acOp.AcadDocument
Private handlerAdded As Boolean = False
Public Sub eventDoubleClick()
Try
If handlerAdded = False Then
acApp.SetSystemVariable("DBLCLKEDIT", 0)
If acDoc Is Nothing Then
acDoc = CType(acApp.DocumentManager.MdiActiveDocument.AcadDocument, _
Autodesk.AutoCAD.Interop.AcadDocument)
AddHandler acDoc.BeginDoubleClick, AddressOf callback_DoubleClick
End If
handlerAdded = True
End If
Catch ex As Autodesk.AutoCAD.Runtime.Exception
MsgBox(ex.Message, MsgBoxStyle.Critical)
Finally
acApp.SetSystemVariable("DBLCLKEDIT", 1)
End Try
End Sub
Private Sub callback_DoubleClick(ByVal PickPoint As Object)
Dim activeDoc As Document = acApp.DocumentManager.MdiActiveDocument
Dim prmtSel As PromptSelectionResult = activeDoc.Editor.GetSelection()
Using docLock As DocumentLock = activeDoc.LockDocument()
If prmtSel.Status <> PromptStatus.OK Then Return
If prmtSel.Value.Count <> 1 Then Return
Dim id As Autodesk.AutoCAD.DatabaseServices.ObjectId = _
prmtSel.Value(0).ObjectId
Using acTrans As Autodesk.AutoCAD.DatabaseServices.Transaction = _
activeDoc.TransactionManager.StartTransaction()
Dim dbObj As Autodesk.AutoCAD.DatabaseServices.DBObject = _
acTrans.GetObject(id, Autodesk.AutoCAD.DatabaseServices.OpenMode.ForWrite)
Dim ent As Autodesk.AutoCAD.DatabaseServices.Entity = _
TryCast(dbObj, Autodesk.AutoCAD.DatabaseServices.Entity)
If ent Is Nothing Then
Return
Else
Dim blockRef As Autodesk.AutoCAD.DatabaseServices.BlockReference = _
TryCast(ent, Autodesk.AutoCAD.DatabaseServices.BlockReference)
If blockRef Is Nothing Then
Return
Else
activeDoc.Editor.WriteMessage(blockRef.Name)
End If
End If
acTrans.Commit()
End Using
End Using
End Sub
End Module
And the Commands class, from which my vb.net form is generated, as well as where the ModDoubleClick.eventDoubleClick() method is called:
Public Class Commands
' Component for displaying the Mass Straight Conveyor form
<CommandMethod("mst")> _
Public Shared Sub massStraight()
Try
' Call this to override default block dblclk event handler
ModDoubleClick.eventDoubleClick()
' Display the mass straight form
Dim cForm As New frmMassStraight
acApp.ShowModalDialog(cForm)
Catch ex As Autodesk.AutoCAD.Runtime.Exception
MsgBox(ex.Message, MsgBoxStyle.Critical)
End Try
End Sub
End Class
Any help is greatly appreciated!
Many thanks...
Cat
Solved! Go to Solution.