.NET

Reply
Valued Contributor
mindofcat
Posts: 55
Registered: ‎05-14-2012
Message 11 of 20 (553 Views)

Re: Display VB.Net form when block reference is double-clicked

11-14-2012 12:37 PM in reply to: Hallex

That's OK... I am truly appreciative of the time you have put into this. So the thing is, my form is modal. I would netload, then type in the command to run my form, which generates a block. Then I would type in the command to run the doubleclick event you so kindly provided.

 

At this point, I would expect to double-click on the block I just created, and have the default doubleclick event overridden, but no, that still doesn't happen.

 

What I'm trying to understand is this: When exactly is the default doubleclick event for block reference supposed to be overridden? 'Cos like I mentioned in my last post, the logic of the code you provided seems flawless, but I simply can't understand why I stil don't have the desired effect...

 

I trash around online quite a bit searching for more solutions, and many a time I keep getting the referral to do something with the CAD cuix file. Do you think this is feasible? And if so, can this be done from code, as opposed to typing cuix in the command line and pulling up the AutoCAD cui customization interface?

Valued Contributor
mindofcat
Posts: 55
Registered: ‎05-14-2012
Message 12 of 20 (541 Views)

Re: Display VB.Net form when block reference is double-clicked

11-14-2012 07:35 PM in reply to: mindofcat

Here is the module I am using to accomplish doubleclick event handling:

 

 

' 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

 

 

To execute, I start AutoCAD 2010, and type 'mst' into the command bar to run the command which both launches my form and as well 'supposedly' applies doubleclick handler.

 

After form execution has drawn a block, I doubleclick on the block and the AutoCAD block Attributes Editor still appears.


Really frustrating, isn't it? No end in sight, still hoping for some insight as to why the module isn't doing what it's supposed to do, override the default AutoCAD doubleclick event for blocks (with attributes)...

ADN Support Specialist
Balaji_Ram
Posts: 733
Registered: ‎03-21-2011
Message 13 of 20 (511 Views)

Re: Display VB.Net form when block reference is double-clicked

11-21-2012 09:21 AM in reply to: mindofcat

Hello,

 

I have attached two screenshots showing the double click actions responsible for block and attribute editing.

 

You may try editing the macro for the attribute edit double click action to include your command that displays the form.

 

I havent tried the sample code yet. Please let me know if modifying the double click action in cuix does not help. I will debug through the code that you already provided.

 



Balaji
Developer Technical Services
Autodesk Developer Network

Valued Contributor
mindofcat
Posts: 55
Registered: ‎05-14-2012
Message 14 of 20 (496 Views)

Re: Display VB.Net form when block reference is double-clicked

11-21-2012 09:58 AM in reply to: Balaji_Ram

Thank you very much, let me check out your screenshots and see how it helps...

 

Quick word though, I would be slightly skeptical about making adjustments directly in the cuix, since this would affect ALL DOUBLE-CLICKED BLOCK REFERENCES, right?

 

But I am only interested in affecting double-clicked block references which were created by my form (the block name has certain identifiable substrings), while therest of the block references in the drawing would continue to exhibit the default AutoCAD double-click behavior...

 

Still, let me take a look at your screenshots and investigate my cuix.

 

Thanks for your help, much appreciated!

 

Further suggestions/pointers/advice still welcome.

 

 

Valued Contributor
mindofcat
Posts: 55
Registered: ‎05-14-2012
Message 15 of 20 (493 Views)

Re: Display VB.Net form when block reference is double-clicked

11-21-2012 10:01 AM in reply to: Balaji_Ram

Any idea how to write the macro string for opening a vb.net form in the cuix double-click macro field?

 

In regular vb.net code, this would be acApp.ShowModalDialog(cForm), but in macro?

*Expert Elite*
Hallex
Posts: 1,569
Registered: ‎10-08-2008
Message 16 of 20 (480 Views)

Re: Display VB.Net form when block reference is double-clicked

11-21-2012 11:40 AM in reply to: mindofcat

Perhaps, something like

^C^C_netload "C:/Tem/myAutoCADForm.dll" ;

 

_____________________________________
C6309D9E0751D165D0934D0621DFF27919
Valued Contributor
mindofcat
Posts: 55
Registered: ‎05-14-2012
Message 17 of 20 (477 Views)

Re: Display VB.Net form when block reference is double-clicked

11-21-2012 12:24 PM in reply to: mindofcat

Thanks...

 

I checked out the cuix screenshots; unfortunately, I need to be able to accomplish this double-click action programmatically, as I feel that's the only way I shall be able to apply my custom double-click action to only specific block references, instead of ALL block references.

 

All the research I have done online enabled me to compile the module I posted here, and the code's logic seems sensible, but unfortunately, after I run the command, double-clicking blocks still pulls up the default autocad double-click action (attredit)

 

DO you have any idea how this can be made to work?

 

Many thanks in advance...

 

Cat

ADN Support Specialist
Virupaksha.aithal
Posts: 101
Registered: ‎06-15-2011
Message 18 of 20 (462 Views)

Re: Display VB.Net form when block reference is double-clicked

11-22-2012 03:44 AM in reply to: mindofcat

Hi,

 

 You can try using IMessageFilter to avoid double click message going to AutoCAD. Refer DevBlog http://adndevblog.typepad.com/autocad/2012/05/how-to-combine-a-net-jig-and-messagefilter-to-catch-us... which shows the use of IMessageFilter and blocking of right click reaching AutoCAD

 

 



Virupaksha Aithal KM
Developer Technical Services
Autodesk Developer Network

Valued Contributor
mindofcat
Posts: 55
Registered: ‎05-14-2012
Message 19 of 20 (447 Views)

Re: Display VB.Net form when block reference is double-clicked

11-22-2012 07:26 PM in reply to: Virupaksha.aithal

Hi,

 

Thanks for the posted link... I'm still trying to figure out how to customize that JigMsgFilter class to suit my needs. I am still relatively new to AutoCAD VB.Net customization, and so many things out there are still confusing for me, but I am finding my way thru gradually.

 

I am currently attempting to fingure out how the class in your post can be customized for doubleclick action... 

ADN Support Specialist
Virupaksha.aithal
Posts: 101
Registered: ‎06-15-2011
Message 20 of 20 (398 Views)

Re: Display VB.Net form when block reference is double-clicked

12-07-2012 02:38 AM in reply to: mindofcat

Hi ,

 

also take look at the new post on similar issue http://forums.autodesk.com/t5/NET/How-to-capture-double-click-event-in-AutoCAD-using-VB-NET/td-p/371...



Virupaksha Aithal KM
Developer Technical Services
Autodesk Developer Network

Post to the Community

Have questions about Autodesk products? Ask the community.

New Post
Announcements
Are You Going To Be @ AU 2014? Feel free to drop by our AU topic post and share your plans, plug a class that you're teaching, or simply check out who else from the community might be in attendance. Ohh and don't forgot to stop by the Autodesk Help | Learn | Collaborate booths in the Exhibit Hall and meet our community team if you get a chance!