• Industries
  • Products
  • Buy
  • Services & Support
  • Communities
  • Discussion Groups

    .NET

    Reply
    Active Contributor
    Posts: 41
    Registered: ‎05-14-2012

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

    471 Views, 19 Replies
    11-12-2012 08:15 PM

    Hi all,

     

    I'm in the process of converting existing VBA code to VB.NET using AutoCAD 2010 and MS Visual Studio Professional, and I just hit a major snag.

     

    In AutoCAD 2010, double-clicking a block will display its attributes in the attributes editor; I would like instead to be able to display my own custom vb.net form showing some of the block's attributes, IF AND ONLY IF the block was created by my dot net form (the block would have certain identifiable characters in its name).

     

    So far, I have not been able to find anything to help, but I have discovered that this may have something to do with the cuix customization file, as well as setting the system variable DBLCLICKEDIT.

     

    At this point I am so confused as to how this problem can be resolved. Does anyone have any helpful hints or concise code blocks that might help? Or at the most point me in the right direction?

     

    Thanks in advance,

     

    Cat

    Please use plain text.
    *Expert Elite*
    Hallex
    Posts: 1,334
    Registered: ‎10-08-2008

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

    11-13-2012 12:34 AM in reply to: mindofcat

    I think the following article will be interesting for you:

    http://through-the-interface.typepad.com/through_the_interface/2009/07/providing-information-on-auto...

    _____________________________________
    C6309D9E0751D165D0934D0621DFF27919
    Please use plain text.
    Active Contributor
    Posts: 41
    Registered: ‎05-14-2012

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

    11-13-2012 09:14 AM in reply to: mindofcat

    Thanks for the article... It's quite interesting, and will definitely come in handy for later use. For the issue at hand, however, the article describes the use of selection set to identify entities, but I'm looking for information on how to replace the CAD double-click event for blocks with my custom VB.Net form. And this is only for blocks created by said form...

     

    Any ideas? Guidelines? Similar articles?

     

    Thanks in advance

    Please use plain text.
    *Expert Elite*
    Hallex
    Posts: 1,334
    Registered: ‎10-08-2008

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

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

    Try this code written some time for double click event on polyline objects,

    just change object type to double click on blockreference within the code

     

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    //acad
    using Autodesk.AutoCAD.DatabaseServices;
    using Autodesk.AutoCAD.ApplicationServices;
    using Autodesk.AutoCAD.Runtime;
    using Autodesk.AutoCAD.EditorInput;
    using Autodesk.AutoCAD.ComponentModel;
    //acad application
    using AcadApp = Autodesk.AutoCAD.ApplicationServices.Application;
    //acad interop
    using Autodesk.AutoCAD.Interop;
    using Autodesk.AutoCAD.Interop.Common;
    
    // tested on A2010
    // This line is not mandatory, but improves loading performances
    [assembly: CommandClass(typeof(AutoCAD_CSharp_plug_in1.ClickEventMgd))]
    namespace AutoCAD_CSharp_plug_in1
    {
       public class ClickEventMgd
        {
            Autodesk.AutoCAD.Interop.AcadDocument m_doc;
    
    
            [CommandMethod("DBL")]
            public void TestDoubleClick()
            {
                if (m_doc == null)
                {
                    m_doc = (Autodesk.AutoCAD.Interop.AcadDocument)AcadApp.DocumentManager.MdiActiveDocument.AcadDocument;
    
                    m_doc.BeginDoubleClick += new _DAcadDocumentEvents_BeginDoubleClickEventHandler(m_doc_BeginDoubleClick);
    
                }
                else
                {
                    AcadApp.SetSystemVariable("DBLCLKEDIT", 1);
                    m_doc.BeginDoubleClick -= new _DAcadDocumentEvents_BeginDoubleClickEventHandler(m_doc_BeginDoubleClick);
                    m_doc = null;
    
                }
    
            }
    
            #region "Events"
            private void m_doc_BeginDoubleClick(object adoc)
            {
                Document activeDoc = AcadApp.DocumentManager.MdiActiveDocument;
                Editor ed = activeDoc.Editor;
                AcadApp.DocumentManager.MdiActiveDocument.Editor.WriteMessage("Double click event is now hooked.");
    
                //get the object that the user has selected
                PromptSelectionResult res = activeDoc.Editor.SelectImplied();
                if (res.Status != PromptStatus.OK)
                    return;
                if (res.Value.Count != 1)
                {
                    //if more then 1 selected before double click dispaly message
                    AcadApp.ShowAlertDialog("Must be selected just one object only\nHit Esc button to refresh");
                    // might be Sendcommand instead but I don't like it
                    return; //we don't handle multiple selected objects
                }
                ObjectId idSel = res.Value[0].ObjectId;
                
                using (Transaction trans = activeDoc.TransactionManager.StartTransaction())
                {
                    Entity obj = (Entity)trans.GetObject(idSel, OpenMode.ForRead);
                    if (idSel.ObjectClass != RXClass.GetClass(typeof(Polyline)))
                    {
                        // for all other objects add usual way
                        AcadApp.SetSystemVariable("DBLCLKEDIT", 1);
                        return;
                    }
                    m_doc.SendCommand("\x03\x03");
                    AcadApp.SetSystemVariable("DBLCLKEDIT", 0);
                    Polyline pline = (Polyline)obj as Polyline;
    
    
                    TestPlineCommand(pline);
                 
    
                    trans.Commit();
                }
             
            }
            #endregion
    
            #region "Commands"
           // change calling  command here
            public void TestPlineCommand(Polyline pline)
            {
                AcadApp.ShowAlertDialog(string.Format("Polyline:\nHandle: {0}\nArea: {1}\nLength: {2}\nLayer: {3}", pline.Handle.Value, pline.Area, pline.Length, pline.Layer));
            }
            #endregion
        }
    }

    I think you need to store block names you've created from form

    in list of string as member of your form,

    then compare if this list contains a block name

    _____________________________________
    C6309D9E0751D165D0934D0621DFF27919
    Please use plain text.
    Active Contributor
    Posts: 41
    Registered: ‎05-14-2012

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

    11-13-2012 11:12 AM in reply to: mindofcat

    Thanks, Hallex... Imma try it out right away and see how it goes.

    Please use plain text.
    *Expert Elite*
    Hallex
    Posts: 1,334
    Registered: ‎10-08-2008

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

    11-13-2012 11:16 AM in reply to: mindofcat

    Hmm, perhaps you need to convert this code on VB.NET

    let me know...

    _____________________________________
    C6309D9E0751D165D0934D0621DFF27919
    Please use plain text.
    Active Contributor
    Posts: 41
    Registered: ‎05-14-2012

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

    11-13-2012 11:19 AM in reply to: Hallex

    You're right there... I'm already covnerting to VB.Net. I'm curious to see what would happen when I change the polyline ent to blockref.

     

    I shall let you know once I finish converting and testing.

     

    I deeply appreciate your help.

    Please use plain text.
    *Expert Elite*
    Hallex
    Posts: 1,334
    Registered: ‎10-08-2008

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

    11-13-2012 12:03 PM in reply to: mindofcat

    Here is quick convertion very limited tested

     

    Imports System
    Imports System.Collections.Generic
    Imports System.Linq
    Imports System.Text
    'acad
    Imports Autodesk.AutoCAD.DatabaseServices
    Imports Autodesk.AutoCAD.ApplicationServices
    Imports Autodesk.AutoCAD.Runtime
    Imports Autodesk.AutoCAD.EditorInput
    Imports Autodesk.AutoCAD.ComponentModel
    'acad application
    Imports AcApp = Autodesk.AutoCAD.ApplicationServices.Application
    'acad interop
    Imports Autodesk.AutoCAD.Interop
    Imports Autodesk.AutoCAD.Interop.Common
    
    ' tested on A2010
    ' This line is not mandatory, but improves loading performances
    <Assembly: CommandClass(GetType(AutoCAD_CSharp_plug_in1.ClickEventMgd))> 
    Namespace AutoCAD_CSharp_plug_in1
        Public Class ClickEventMgd
            Private m_doc As Autodesk.AutoCAD.Interop.AcadDocument
    
    
            <CommandMethod("DBLK")> _
            Public Sub TestDoubleClick()
                If m_doc Is Nothing Then
                    m_doc = DirectCast(AcApp.DocumentManager.MdiActiveDocument.AcadDocument, Autodesk.AutoCAD.Interop.AcadDocument)
    
                    AddHandler m_doc.BeginDoubleClick, AddressOf m_doc_BeginDoubleClick
                Else
                    AcApp.SetSystemVariable("DBLCLKEDIT", 1)
                    RemoveHandler m_doc.BeginDoubleClick, AddressOf m_doc_BeginDoubleClick
    
                    m_doc = Nothing
    
                End If
    
            End Sub
    
    #Region "Events"
            Private Sub m_doc_BeginDoubleClick(adoc As Object)
                Dim activeDoc As Document = AcApp.DocumentManager.MdiActiveDocument
                Dim ed As Editor = activeDoc.Editor
                AcApp.DocumentManager.MdiActiveDocument.Editor.WriteMessage("Double click event is now hooked.")
    
                'get the object that the user has selected
                Dim res As PromptSelectionResult = activeDoc.Editor.SelectImplied()
                If res.Status <> PromptStatus.OK Then
                    Return
                End If
                If res.Value.Count <> 1 Then
                    'if more then 1 selected before double click dispaly message
                    AcApp.ShowAlertDialog("Must be selected just one object only" & vbLf & "Hit Esc button to refresh")
                    ' might be Sendcommand instead but I don't like it
                    'we don't handle multiple selected objects
                    Return
                End If
                Dim idSel As ObjectId = res.Value(0).ObjectId
    
                Using trans As Transaction = activeDoc.TransactionManager.StartTransaction()
                    Dim obj As Entity = DirectCast(trans.GetObject(idSel, OpenMode.ForRead), Entity)
                    If idSel.ObjectClass <> RXClass.GetClass(GetType(BlockReference)) Then
                        ' for all other objects add usual way
                        AcApp.SetSystemVariable("DBLCLKEDIT", 1)
                        Return
                    End If
                    m_doc.SendCommand(ChrW(3) & ChrW(3))
                    AcApp.SetSystemVariable("DBLCLKEDIT", 0)
                    Dim bref As BlockReference = TryCast(DirectCast(obj, BlockReference), BlockReference)
    
    
                    TestBlockCommand(bref)
    
    
                    trans.Commit()
                End Using
    
            End Sub
    #End Region
    
    #Region "Commands"
            ' change calling  command here
            Public Sub TestBlockCommand(bref As BlockReference)
                AcApp.ShowAlertDialog(String.Format("BlockReference:" & vbLf & "Name: {0}" & vbLf & "Handle: {1}" & vbLf & "Layer: {2}" & vbLf & "Position: {3:f3}", bref.Name, bref.Handle.Value, bref.Layer, bref.Position))
            End Sub
    #End Region
        End Class
    End Namespace

     

    _____________________________________
    C6309D9E0751D165D0934D0621DFF27919
    Please use plain text.
    Active Contributor
    Posts: 41
    Registered: ‎05-14-2012

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

    11-13-2012 12:21 PM in reply to: Hallex

    Sir,

     

    Thanks for the dot net conversion... The code seems to be flawless and makes perfect sense. However, after I implemented it into my existing namespace and executed the code by typing the command; but it doesn't seem to have the desired effect, 'cos I doubleclick on a block created by my form, and the EATTEDIT command still runs, popping up the block's attributes.

     

    Isn't the code supposed to overwrite this behavior by now?

    Please use plain text.
    *Expert Elite*
    Hallex
    Posts: 1,334
    Registered: ‎10-08-2008

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

    11-14-2012 02:28 AM in reply to: mindofcat

    Oops, sorry I didn't test this code from form

    if your form is modeless maybe you could use

    Editor.StartUserInteraction(Me), I haven't have a time

    on this work...

    _____________________________________
    C6309D9E0751D165D0934D0621DFF27919
    Please use plain text.