.NET

.NET

Reply
Valued Contributor
sszabo
Posts: 86
Registered: ‎09-05-2012
Message 11 of 29 (492 Views)

Re: How to capture double click event in AutoCAD using VB.NET

11-28-2012 06:48 AM in reply to: mindofcat

On a second thought: I just recreated what you describe by replacing this line:

Dim prmtSel As PromptSelectionResult = activeDoc.Editor.GetSelection()

 

with this:

 

Dim prmtSel As PromptSelectionResult = acDoc.Editor.GetSelection()

 

So you probably have the wrong document obj.  Unfortunately I am not familiar with ACAD 2010 and have't worked with ACAD before 2013.  You will have to ask somebody to point you to the correct way to return the ThisDrawing object for your version.  I think your code should work so I am not sure why it doesn't.

 

try this too if you like:

 

First make sure you can see messages from eventDoubleClick().  If you don't the problem is your document object.  Make sure you have this: 

Dim activeDoc As Document = Application.DocumentManager.MdiActiveDocument

 

I am also assuming you loaded a valid drawing before you ran your mst command.  To verify this:

 

        Private Sub callback_DoubleClick(ByVal PickPoint As Object)

            Dim prmtSel As PromptSelectionResult = activeDoc.Editor.GetSelection()

            Dim msg As String = ""

 

            msg = String.Format("doc: {0} prmtSel:{1}", activeDoc.Name, prmtSel.Value.ToString)

            ed.WriteMessage(vbLf + msg)

 

 

This should give you:

doc: C:\mydrawing.DWG prmtSel:smileysad:((8796087866032),PickPoint,114,))

 

 

 

 

Valued Mentor
jeff
Posts: 338
Registered: ‎05-12-2009
Message 12 of 29 (478 Views)

Re: How to capture double click event in AutoCAD using VB.NET

11-28-2012 11:36 AM in reply to: sszabo

Confused why you even try using AcadDocument object among other things.

 

I would start over and forget about blockreferences or blocks and focus on showing a blank form for a double-click event.

Thats it.

Will help you along but for now

 

So you need a blank form

A command to register event handler.

 

And showing the form .

 

Once you get a understanding of that then move to next steps and improving approach. 

 

You can also find your answers @ TheSwamp
Valued Contributor
mindofcat
Posts: 55
Registered: ‎05-14-2012
Message 13 of 29 (470 Views)

Re: How to capture double click event in AutoCAD using VB.NET

11-28-2012 03:11 PM in reply to: sszabo

Thanks sszabo,

 

I deeply appreciate all the help you've given me. Let me try out the suggestion you just made, and see where it gets me. Yes I totally understand about CAD 2013, unfortunately, my work is based on 2010 (eventually the company will upgrade to 2013) but for now, all the work is on 2010 so I have a lot of research to do on the ThisDrawing and document objects. Seems that's where my problem is originating...

 

 

Thanks for everything

Valued Mentor
jeff
Posts: 338
Registered: ‎05-12-2009
Message 14 of 29 (457 Views)

Re: How to capture double click event in AutoCAD using VB.NET

11-29-2012 08:28 AM in reply to: mindofcat

mindofcat wrote:

And as well, I have also been to http://adndevblog.typepad.com/autocad/2012/09/displaying-entity-details-on-double-click.html many days ago; I translated the code to dot net, and executed it. When I go to AutoCAD and type cui in the command to pull up the cui editor, I see that my new double click action has been created alright, but I still don't know how to attach it to block references, or how to modify the macro string to open my vb.net form.

 

The macro string in the article runs thus:

 

C^C^myForm

 

How does this get modified to pop up a vb.net form named frmMassStraight which I would normally open using application.showModalDialog(formInstance)

 

Thanks all, for your help, but I'm still floundering in the dark, trying so hard to see the light which I know exists at the end of this dark tunnel...



Have you tried adding a command myForm?

<Command("myForm")...>

Sub

 Dim formInstance As New frmMassStraight

application.showModalDialog(formInstance)

End Sub

You can also find your answers @ TheSwamp
Valued Contributor
mindofcat
Posts: 55
Registered: ‎05-14-2012
Message 15 of 29 (442 Views)

Re: How to capture double click event in AutoCAD using VB.NET

11-29-2012 07:27 PM in reply to: jeff

Yes, I have tried

<Command("myForm")...>

Sub

 Dim formInstance As New frmMassStraight

application.showModalDialog(formInstance)

End Sub

 

That's how I had things set up in the first place. And this calls my form alright, but I still don't know how to tie in the doubleclick override, or how to build a functional doubleclick override in the first place.

 

You've seen my code? Any idea what I'm doing wrong, or what I'm missing? Many have told me that my code seems alright, and works for them. But unfortunately, I still doubleclick on my frmMassStraight block references and the default AutoCAD doubleclick behavior kicks in, instead of my frmMassStraight form popping up...

ADN Support Specialist
Balaji_Ram
Posts: 749
Registered: ‎03-21-2011
Message 16 of 29 (416 Views)

Re: How to capture double click event in AutoCAD using VB.NET

12-06-2012 10:49 AM in reply to: mindofcat

Hello,

 

Maybe this is causing the problem : In the finally block, the system variable "DBLCLKEDIT" is set to 1 again ?

 

I have attached the dropbox link to a sample project that is mostly from your code and a recording of the steps that I tried.

https://www.dropbox.com/sh/xzp9iiq6sc7e1bm/MBhZ6B7evG

 

It works ok on AutoCAD 2011 and on double-clicking a block reference the modal form displays the block name.

 

Hope this provides some hint to resolve the issue with your sample project.

 

 

 

 



Balaji
Developer Technical Services
Autodesk Developer Network

Valued Contributor
mindofcat
Posts: 55
Registered: ‎05-14-2012
Message 17 of 29 (412 Views)

Re: How to capture double click event in AutoCAD using VB.NET

12-06-2012 10:58 AM in reply to: Balaji_Ram

Thanks very much, this helped immensely. Truly grateful for the help.

Valued Mentor
jeff
Posts: 338
Registered: ‎05-12-2009
Message 18 of 29 (401 Views)

Re: How to capture double click event in AutoCAD using VB.NET

12-06-2012 06:14 PM in reply to: Balaji_Ram

By getting the current selection set would'nt that clear it and no other doubleclick actions would be called?

 

I thought the DBLCLICK variable had to do with DoubleClickActions in CUI and nothing to do with Application.BeginDoubleClick event?

 

What if you wanted it to show for certain blocks but not all?

 

 

You can also find your answers @ TheSwamp
Valued Contributor
mindofcat
Posts: 55
Registered: ‎05-14-2012
Message 19 of 29 (392 Views)

Re: How to capture double click event in AutoCAD using VB.NET

12-06-2012 06:54 PM in reply to: jeff

I ended up NOT going down the Application.BeginDoubleClick event route anymore. What I ended up doing was creating a custom doubleclick action to which I attached the macro that calls my edit form.

 

And then, in the myCommands.vb file, I call the moethod that registers this custom doubleclick action in the initialize() method.

 

Which means that, upon AutoCAD load, the AutoCAD cuix file is iterated thru, my custom doubleclick action (which targets attribute blocks) is removed, and then recreated.

 

As well, in order to ensure that I target only specific blocks, in the method that executes the selectImplied() pickset, I cast the picked entity as a block reference, and then check its name. IF the name falls under the category of blocks I need, then I pop up the edit form; else I use acDoc.SendStringToExecute() to execute the eattedit command macro.

 

The only downside I suffered was that it now takes 3 clicks (instead of 2) to pop up the eattedit editor for attribute blocks other than the ones I need to edit. Still, considering how almost impossible it was to get this problem resolved, I am honestly satisfied with the outcome.

ADN Support Specialist
Balaji_Ram
Posts: 749
Registered: ‎03-21-2011
Message 20 of 29 (384 Views)

Re: How to capture double click event in AutoCAD using VB.NET

12-06-2012 10:05 PM in reply to: jeff

Hi Jeff,

 

That is a valid point.

 

I was only looking into getting the originally posted code to work. It does have its limitations such as showing our dialog for all the blocks without being selective.

 

I dont see that the "DBLCLKEDIT" system variable can get reset without our code doing it. This system variable controls the customization of double click that is done using the CUI. So switching it off will ensure that we are allowed to show our dialog without the macro specified in the CUI customization of bloc edit interfering in it.

 

To do double click customization selectively, using the CUI approach is the right way. But I still dont get why 3 clicks are needed for blocks for which the custom dialog need not be shown.

 

Here is a sample code that worked ok. It changes the macro for the block double click to invoke a custom command called "mybedit". Inside the "mybedit" command, we can check if the block is one that we are interested in. If yes, we do our custom action such as showing our dialog. If not we set the pick first selection and then invoke the AutoCAD "bedit".

 

public class Test : IExtensionApplication
{
    static CustomizationSection cs;

	[CommandMethod("mybedit", CommandFlags.UsePickSet)]
	static public void MyBeditCommand()
	{
		Document activeDoc = Application.DocumentManager.MdiActiveDocument;
		Editor ed = activeDoc.Editor;

		PromptSelectionResult result = Application.DocumentManager.MdiActiveDocument.Editor.GetSelection();
		if (result.Status == PromptStatus.OK)
		{
			SelectionSet ss = result.Value;
			foreach (SelectedObject so in ss)
			{
				ed.WriteMessage(so.ObjectId.Handle.ToString());

				// Some check here to identify if we need to show our dialog
				if (so.ObjectId.Handle.ToString().Equals("1BB"))
				{
					// Show our dialog
				}
				else
				{
					// Let AutoCAD do the block edit.

	                ObjectId[] ids = ss.GetObjectIds();

					// Set the implied selection to what it was before our command was called
					ed.SetImpliedSelection(ids);

					// call "bedit" command
					activeDoc.SendStringToExecute("_BEDIT ", false, false, false);
				}
			}
		}
	}
	
    [CommandMethod("MacroCUI")]
    static public void ModifyMacroCUI()
    {
        Document activeDoc = Application.DocumentManager.MdiActiveDocument;
        Editor ed = activeDoc.Editor;

        DoubleClickAction blockDoubleClickAction = null;
        foreach (DoubleClickAction dca in cs.MenuGroup.DoubleClickActions)
        {
            ed.WriteMessage("\n" + dca.Name);
            if (dca.Name.Equals("Block"))
            {
                blockDoubleClickAction = dca;
                break;
            }
        }
        if (blockDoubleClickAction != null)
        {
            blockDoubleClickAction.DoubleClickCmd.MenuMacroReference.macro.Command = "$M=$(if,$(and,$(>,$(getvar,blockeditlock),0)),^C^C_properties,^C^C_mybedit)";

            if (cs.IsModified)
              cs.Save();
        }
    }

    void IExtensionApplication.Initialize()
    {
        Document activeDoc = Application.DocumentManager.MdiActiveDocument;
        Database db = activeDoc.Database;
        Editor ed = activeDoc.Editor;

        // retrieve the location of, and open the ACAD Main CUI File
        string mainCuiFile = (string)Application.GetSystemVariable("MENUNAME");
        mainCuiFile += ".cuix";
        cs = new CustomizationSection(mainCuiFile);
    }

    void IExtensionApplication.Terminate()
    {
    }
}

 

In the code, I have made a check on the block reference handle, which you can change to any other condition to identify your block reference (ex : XData )

 

The "MacroCUI" command changes the macro for block double click action after which you can try the double click.

 

 

 

 



Balaji
Developer Technical Services
Autodesk Developer Network

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.