.NET

Reply
Active Contributor
dancalgary
Posts: 46
Registered: ‎05-18-2007
Message 1 of 2 (223 Views)

Double Click capture

223 Views, 1 Replies
08-22-2013 03:40 PM

Hi

I am trying to build a code without using CUI editing

when I doubleclick a  block called Block_text to display a custom form 

but also I do not want to take out the double click behaviour from autocad when I click on another objects

 

Can you point me to the right path?

I do not want to run "mst" command when I want to display the form

 

So far I gathered  the following code:

 

' System

Imports System

Imports System.Collections.Generic

Imports System.Linq

Imports System.Text

Imports System.Linq.Expressions

 

' AutoCAD

Imports Autodesk.AutoCAD.DatabaseServices

Imports Autodesk.AutoCAD.ApplicationServices

Imports Autodesk.AutoCAD.Runtime

Imports acApp = Autodesk.AutoCAD.ApplicationServices.Application

Imports Autodesk.AutoCAD.EditorInput

 

' AutoCAD Interop

Imports acOp = Autodesk.AutoCAD.Interop

Imports acOpCom = Autodesk.AutoCAD.Interop.Common

 

 

 

Namespace Test1

 

    PublicClassCommands

        Public db AsDatabase = HostApplicationServices.WorkingDatabase

        Public ActiveDoc_vb_net AsDocument = acApp.DocumentManager.MdiActiveDocument

        Public ed AsEditor = ActiveDoc_vb_net.Editor

 

        Private acDoc As acOp.AcadDocument

        Private handlerAdded AsBoolean = False

        Private Forma1 AsNewdouble_click_form' I created a form, and I added a Textbox1 to it

 

 

        PublicFunction ThisDrawing()

            ReturnacApp.DocumentManager.MdiActiveDocument.AcadDocument

        EndFunction

 

        PublicSub eventDoubleClick()

 

            Try

 

 

                If handlerAdded = FalseThen

 

                    acApp.SetSystemVariable("DBLCLKEDIT", 0)

                    acDoc = CType(ThisDrawing(), Autodesk.AutoCAD.Interop.AcadDocument)

                    AddHandler acDoc.BeginDoubleClick, AddressOf callback_DoubleClick

 

                    handlerAdded = True

                Else

 

                EndIf

 

            Catch ex As Autodesk.AutoCAD.Runtime.Exception

                MsgBox(ex.Message, MsgBoxStyle.Critical)

 

            Finally

                acApp.SetSystemVariable("DBLCLKEDIT", 1)

            EndTry

 

        EndSub

 

 

 

        PrivateSub callback_DoubleClick(ByVal pickPoint AsObject)

            Dim PromptSelectionResult1 AsPromptSelectionResult = ActiveDoc_vb_net.Editor.GetSelection()

            Dim msg AsString = ""

 

            Using docLock AsDocumentLock = ActiveDoc_vb_net.LockDocument()

                If PromptSelectionResult1.Status <> PromptStatus.OK Then

 

                EndIf

 

                If PromptSelectionResult1.Value.Count <> 1 Then

 

                EndIf

 

                Dim id As Autodesk.AutoCAD.DatabaseServices.ObjectId = PromptSelectionResult1.Value(0).ObjectId

                Try

                    Using acTrans As Autodesk.AutoCAD.DatabaseServices.Transaction = _

                        ActiveDoc_vb_net.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)

 

                        Forma1.Text = ent.GetType().ToString()

 

 

 

                        If ent IsNothingThen

 

                            Exit Sub

                        Else

                            Dim blockRef As Autodesk.AutoCAD.DatabaseServices.BlockReference = _

                                TryCast(ent, Autodesk.AutoCAD.DatabaseServices.BlockReference)

 

 

                            If blockRef IsNothingThen

 

                                acDoc = CType(ThisDrawing(), Autodesk.AutoCAD.Interop.AcadDocument)

                                RemoveHandler acDoc.BeginDoubleClick, AddressOf callback_DoubleClick

 

 

 

                                Exit Sub

                            Else

                                ActiveDoc_vb_net.Editor.WriteMessage(blockRef.BlockName)

                                acApp.ShowModalDialog(Forma1)

                            EndIf

                        EndIf

                        acTrans.Commit()

 

                    EndUsing

                Catch ex As Autodesk.AutoCAD.Runtime.Exception

                    Dim msgStr AsString = String.Format("EX: '{0}'", ex.ToString)

 

 

                Catch

                    Dim msgStr AsString = String.Format("ERR: '{0}", Err.Description)

 

                EndTry

 

            EndUsing

 

 

        EndSub

 

 

        <CommandMethod("mst")> _

        PublicSub massStraight()

            Try

                ' Call this to override the default block dblclk event handler

                eventDoubleClick()

 

            Catch ex As Autodesk.AutoCAD.Runtime.Exception

                MsgBox(ex.Message, MsgBoxStyle.Critical)

 

            EndTry

        EndSub

 

    EndClass

EndNamespace

 

*Expert Elite*
norman.yuan
Posts: 1,064
Registered: ‎04-27-2009
Message 2 of 2 (198 Views)

Re: Double Click capture

08-23-2013 06:38 AM in reply to: dancalgary

If you are not using Acad2009 or earlier, you do not have to use AcadDocument.BeginDoubleClick event from COM API, you can use Application.BeginDoubleClick in ,NET API, in conjunction with other more controls mechnism provided by .NET API.

 

There was a lengthy discussion in this forum and that inspired me wrinte 2 articles on this topic:

 

http://drive-cad-with-code.blogspot.ca/2012/12/custom-double-click-action-using.html

http://drive-cad-with-code.blogspot.ca/2013/03/update-custom-double-click-action-using.html

 

It might be a bit helpful.

 

Post to the Community

Have questions about Autodesk products? Ask the community.

New Post
Announcements
Do you have 60 seconds to spare? The Autodesk Community Team is revamping our site ranking system and we want your feedback! Please click here to launch the 5 question survey. As always your input is greatly appreciated.