.NET
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic to the Top
- Bookmark
- Subscribe
- Printer Friendly Page
Display VB.Net form when block reference is double-cli cked
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
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
Re: Display VB.Net form when block reference is double-cli cked
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
I think the following article will be interesting for you:
C6309D9E0751D165D0934D0621DFF27919
Re: Display VB.Net form when block reference is double-cli cked
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
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
Re: Display VB.Net form when block reference is double-cli cked
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
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.Doc umentManager.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.W riteMessage("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:\n Handle: {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
Re: Display VB.Net form when block reference is double-cli cked
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
Thanks, Hallex... Imma try it out right away and see how it goes.
Re: Display VB.Net form when block reference is double-cli cked
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
Hmm, perhaps you need to convert this code on VB.NET
let me know...
C6309D9E0751D165D0934D0621DFF27919
Re: Display VB.Net form when block reference is double-cli cked
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
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.
Re: Display VB.Net form when block reference is double-cli cked
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
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.Wri teMessage("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("BlockReferenc e:" & 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
Re: Display VB.Net form when block reference is double-cli cked
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
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?
Re: Display VB.Net form when block reference is double-cli cked
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
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


