Author Topic: BeginDoubleClick Event Handler selecting blocks  (Read 1883 times)

0 Members and 1 Guest are viewing this topic.

cannorth

  • Newt
  • Posts: 139
BeginDoubleClick Event Handler selecting blocks
« on: November 10, 2011, 03:51:12 pm »
Hello,

  I'm trying to double click a block and capture the event using the BeginDoubleClick reactor.  However, when the block is selected, my selection set has nothing in it.
Code: [Select]
    Public Sub CommandRun()
        If AcDoc Is Nothing Then
            AcDoc = CType(AcApv.DocumentManager.MdiActiveDocument.AcadDocument, Autodesk.AutoCAD.Interop.AcadDocument)
            AddHandler AcDoc.BeginDoubleClick, AddressOf acdoc_BeginDoubleClick
        End If
    End Sub

   Private Sub acdoc_BeginDoubleClick(ByVal PickPoint As Object)
        Dim MdiActiveDocument As Document = AcApv.DocumentManager.MdiActiveDocument
        Dim GetSelection As PromptSelectionResult = MdiActiveDocument.Editor.GetSelection()
        Dim str_path As String = ""


        Using DocumentLock As DocumentLock = MdiActiveDocument.LockDocument()
            If GetSelection.Status <> PromptStatus.OK Then Return
            If GetSelection.Value.Count <> 1 Then Return


   The GetSelection.Status is Cancelled after I double click the block.  How would I get my double click to work and select the block?

Thanks,

cannorth

n.yuan

  • Newt
  • Posts: 154
Re: BeginDoubleClick Event Handler selecting blocks
« Reply #1 on: November 10, 2011, 10:36:11 pm »
Is CommandRun() a command method (e.g. the method being decorated with <CommandMethod(....)> attribute)? In order for a command method to pick up "SelectFirst" entities, you need to decorate the command method with <CommandMethod("MyCommand",CommandFlags.UsePickSet)>.

Also, you'd better use Autodesk.AutoCAD.ApplicationServices.Application.BeginDoubleClick event instead of COM event. Here is some code example in C#, which is simple enough to be convert to VB.NET:

Code: [Select]
[CommandMethod("MyDbClick",CommandFlags.UsePickSet)]
public void MyDoubleClick()
{

    Application.BeginDoubleClick +=
        new BeginDoubleClickEventHandler(Application_BeginDoubleClick);
}

void Application_BeginDoubleClick(object sender, BeginDoubleClickEventArgs e)
{
    Document doc = Application.DocumentManager.MdiActiveDocument;
    Editor ed = doc.Editor;

    PromptSelectionResult res = ed.SelectImplied();

    if (res.Status == PromptStatus.OK)
    {
        if (res.Value.Count > 0)
        {
            ed.WriteMessage("\nSelected entity is {0}",
                res.Value.GetObjectIds()[0].ToString());
        }
        else
        {
            ed.WriteMessage("\nNo entity is selected");
        }
    }
    else
    {
        ed.WriteMessage("\nNo entity is selected");
    }
}

cannorth

  • Newt
  • Posts: 139
Re: BeginDoubleClick Event Handler selecting blocks
« Reply #2 on: November 11, 2011, 10:21:31 am »
How do I access Application.BeginDoubleClick?  Do I need a special imports for that?

Thanks,

cannorth

n.yuan

  • Newt
  • Posts: 154
Re: BeginDoubleClick Event Handler selecting blocks
« Reply #3 on: November 11, 2011, 11:51:25 am »
Application here is Autodesk.AutoCAD.ApplicationServices.Application, which is equivalent to "AcApv" in your code.

Thst is, instead of your code

Public Sub CommandRun()
        If AcDoc Is Nothing Then
            AcDoc = CType(AcApv.DocumentManager.MdiActiveDocument.AcadDocument, Autodesk.AutoCAD.Interop.AcadDocument)
            AddHandler AcDoc.BeginDoubleClick, AddressOf acdoc_BeginDoubleClick
        End If
    End Sub


You simply:

''In the class level, set a flag so that the BeginDoubleClick
''event handler will be only registered once per Acad
''session in your add-in
Private Shared _dblClickRegistered As Boolean=False

<CommandMethod("MyDblClick",CommandFlags.UsePciSet)> _
Public Shared Sub CommandRun()
    If Not _dblClickregistered Then   
        AddHandler Autodesk.AutoCAD.ApplicationServices.Application.BeginDoubleClick, Address Of app_BeginDoubleClick
        _dblClickRegistered=True
    End If
End Sub

Private Shared app_BeginDoubleClick(sender As Object, e As BeginDoubleClickEventArgs)
    ''Check if there is implied selectionset available
End Sub

cannorth

  • Newt
  • Posts: 139
Re: BeginDoubleClick Event Handler selecting blocks
« Reply #4 on: November 11, 2011, 12:17:14 pm »
I tried it and I get the same result.  It doesn't select the block when I double click.  The block has attributes so it shows me attribute editor dialog instead.

Thanks,

cannorth

n.yuan

  • Newt
  • Posts: 154
Re: BeginDoubleClick Event Handler selecting blocks
« Reply #5 on: November 13, 2011, 11:26:45 am »
Have you actually debugged your code by place a break point in the BeginDoublClick event handler? If you did, you would know whether your code is actually work or not. Attached is the picutre of running my code, where the selected entity's ObjectID is shown in command line. What I did is

1. Load the code I showed in previous reply;
2. draw a polyline
3. issue command "MyDbClick"
4. double-click the polyline

However, handling double-click in your code, does not stop AutoCAD from doing its own double-click action as configured (in your case, double-clicking an block's attribute opens attribute editing dialog box; in my case, double-clicking a polyline starts _pedit command), because your code just register a new doubl-clicking event handler, which does not affect any existing double-clicking event handlers.

If you want to change AutoCAD's doule-clicking behaviour and acts only according to your double-click behaviour, you need to change the DoubleClick action, defined in CUI. You can also use code to make this kind of changed. Simply handling BeginDoubleClick event will only add one more behaviour on top of existing behaviours, as we have already seen.

Or if you do not want AutoCAD's default DoubleClick action, you can simply go to Options->User Preferences and uncheck "Double Click Editing" in the risk of making many CAD users very angry unless your double-click actions satisfy your user better.


« Last Edit: November 14, 2011, 09:28:40 am by n.yuan »

fixo

  • Swamp Rat
  • Posts: 856
  • My location is not in the Hitleropa
Re: BeginDoubleClick Event Handler selecting blocks
« Reply #6 on: November 14, 2011, 03:51:07 am »
I tried it and I get the same result.  It doesn't select the block when I double click.  The block has attributes so it shows me attribute editor dialog instead.

Thanks,

cannorth

Try to set:
Code: [Select]
AcApv.SetSystemVariable("DBLCLKEDIT", 0)in your calling method
and restore it in 'finally' code block
\\\"Always drink upstream from the herd."\\\ - Will Rogers, was died in 1935 plane crash

--> Donate to TheSwamp <--

cannorth

  • Newt
  • Posts: 139
Re: BeginDoubleClick Event Handler selecting blocks
« Reply #7 on: November 14, 2011, 02:51:21 pm »
Thanks, setting that system variable DBLCLKEDIT did the trick! :)  Now, I have this set to 0 when I run my command.  However, I'd like to shut it off with another command.  When I try to turn it off, it still runs my app_BeginDoubleClick function when I double click on a block.  How can I have my viewoff command turn it off so it can show attributes from a block again when double clicked?

Code: [Select]
    <Autodesk.AutoCAD.Runtime.CommandMethod("view", CommandFlags.UsePickSet)> _
    Public Sub CommandRun()
        AcApv.SetSystemVariable("DBLCLKEDIT", 0)
        AddHandler Autodesk.AutoCAD.ApplicationServices.Application.BeginDoubleClick, AddressOf app_BeginDoubleClick
        'If AcDoc Is Nothing Then
        '    AcDoc = CType(AcApv.DocumentManager.MdiActiveDocument.AcadDocument, Autodesk.AutoCAD.Interop.AcadDocument)
        '    AddHandler AcDoc.BeginDoubleClick, AddressOf acdoc_BeginDoubleClick
        'End If
    End Sub
    <Autodesk.AutoCAD.Runtime.CommandMethod("viewoff", CommandFlags.UsePickSet)> _
    Public Sub CommandRun1()
        AcApv.SetSystemVariable("DBLCLKEDIT", 1)
        AddHandler Autodesk.AutoCAD.ApplicationServices.Application.BeginDoubleClick, AddressOf app_do_nothing
        '       AddHandler Autodesk.AutoCAD.ApplicationServices.Application.BeginDoubleClick, AddressOf app_BeginDoubleClick
        'If AcDoc Is Nothing Then
        '    AcDoc = CType(AcApv.DocumentManager.MdiActiveDocument.AcadDocument, Autodesk.AutoCAD.Interop.AcadDocument)
        '    AddHandler AcDoc.BeginDoubleClick, AddressOf acdoc_BeginDoubleClick
        'End If
    End Sub

cannorth

  • Newt
  • Posts: 139
Re: BeginDoubleClick Event Handler selecting blocks
« Reply #8 on: November 14, 2011, 03:04:46 pm »
Nevermind, I solved my own problem.  I simply remove the Handler with RemoveHandler.

Thanks,

cannorth