.NET
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

How to capture double click event in AutoCAD using VB.NET

28 REPLIES 28
SOLVED
Reply
Message 1 of 29
mindofcat
6892 Views, 28 Replies

How to capture double click event in AutoCAD using VB.NET

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

28 REPLIES 28
Message 21 of 29
jeff
in reply to: Balaji_Ram

Thanks,

 

I was wondering about that and have not had time to test but setting it pick first selection then sending the command will work.

 

I was unsure about the 3 clicks but just guessing was sending the command without a active pickset and was getting a prompt to select an entity.

 

 

 

 

 

 

You can also find your answers @ TheSwamp
Message 22 of 29
mindofcat
in reply to: jeff

You are so right! The 3 clicks are as a result of sending the command without a active pickset and thereby getting a prompt to select an entity. I tried using the 'L' for last pickset in the eattedit command, but I didn't like what it was doing, it seemed to be malfunctioning in the context it was being used, always retaining the id of last picked object no matter what.

 

I strive for perfection, so ideally, I really don't want those 3 clicks, as I am sure it would eventually become a nuisance for the end user...

Message 23 of 29
mindofcat
in reply to: Balaji_Ram

Balaji,

 

I just implemented your solution, and it worked! I am truly grateful for the help. I do have a question though: the macro command

 

"$M=$(if,$(and,$(>,$(getvar,blockeditlock),0)),^C^C_properties,^C^C_mybedit)";

 

seems to be configured fro blocks; how do I configure it for attribute blocks? I already tried doing this:

 

"$M=$(if,$(and,$(>,$(getvar,blockeditlock),0)),^C^C_eattedit,^C^C_mybedit)";

 

but when I test the double click on an attribute block (not one that show show my form), the block properties editor pops up instead of the attributes editor.

 

Any ideas?

Message 24 of 29
Balaji_Ram
in reply to: mindofcat

Hello,

 

The double click action for an attribute block is different from the double click action for a block.

You can see these two actions using the CUI dialog as seen in the attachment.

 

To customize the double click for an attribute block, here are some changes to the code snippet that I posted earlier

 

1) Check for "dca.Name.Equals("Attribute Block"))" instead of "dca.Name.Equals("Block"))"

 

2) Change the double click macro to "^C^C_mybedit" instead of "$M=$(if,$(and,$(>,$(getvar,blockeditlock),0)),^C^C_properties,^C^C_mybedit)";"

 

3) Change the "SendStringToExecute" inside the "MyBedit" command to send the "eattedit" command if it not a block reference that you are interested in.

 

Please let me know if you have any issues in getting this to work.

 

 



Balaji
Developer Technical Services
Autodesk Developer Network

Message 25 of 29
mindofcat
in reply to: Balaji_Ram

Wow! That worked wonders! Thanks a million!

 

However, even after implementation, I'm still having 3 clicks for attribute blocks other than those being edited by my form. So I'm guessing the ed.SetImpliedSelection(ids) called before sendStringToExecute still is empty; if I double click on an attribute block not being edited by my form, the AutoCAD prompt says "select a block: " and then I have to click on the block once more in order for the eattedit editor to be displayed.

 

Any ideas on how to get that implied selection set to work so I don't have to click three times?

 

Thanks again for all the help.

 

Cat

Message 26 of 29
Balaji_Ram
in reply to: mindofcat

Hello,

 

I could reproduce the same behavior. It seems that AutoCAD was clearing the pickfirst selection before the eattedit command was executed.

 

Using "CommandFlags.UsePickSet | CommandFlags.Redraw" for the "mybedit" command resolves the issue.

 

Thanks to my colleague, Viru for suggesting this fix.

 

 

 

 

 

 



Balaji
Developer Technical Services
Autodesk Developer Network

Message 27 of 29
mindofcat
in reply to: Balaji_Ram

Worked like a charm! Now I can successfully double-click on an attribute block, and either display my form, or go straight to AutoCAD's eattedit command. The combined command flags successfully resolved the triple clicks issue as well. I am truly grateful for all the help accorded me in the successful resolution of this problem.

 

Thanks Balaji, thanks Jeff, thanks Viru, thanks Autodesk NET forum!

Message 28 of 29
Balaji_Ram
in reply to: mindofcat

I am glad you have resolved the issue.

Good luck.



Balaji
Developer Technical Services
Autodesk Developer Network

Message 29 of 29
cadheinz
in reply to: jeff

Hello mindofcat

Would you ask me about the program disposal.
Thank you

 

Hallo mindofcat

Würden Sie das Programm mir zu verfügung stellen.
Danke

 

DH

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk DevCon in Munich May 28-29th


Autodesk Design & Make Report

”Boost