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