.NET
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Run command on double click block with specific name?

19 REPLIES 19
SOLVED
Reply
Message 1 of 20
RPeter
2743 Views, 19 Replies

Run command on double click block with specific name?

I wrote a couple of functions one of them creates a block with a Name let say "MyBlock".

I wrote a command "MyBlockEdit" where the selected block attribute data is displayed in a custom form to change some of the properties.

 

Now I want to add the folowing function:

When a block with the blockname "MyBlock" is doubleclicked the command "MyBlockEdit" is triggered in place of the attribute editor.

 

Can someone show me the way how to apply this?

19 REPLIES 19
Message 2 of 20
norman.yuan
in reply to: RPeter

This has been discussed recently and Balaji Remamoorthy has posted a solution:

 

http://forums.autodesk.com/t5/NET/How-to-capture-double-click-event-in-AutoCAD-using-VB-NET/td-p/371...

http://adndevblog.typepad.com/autocad/2012/12/customizing-double-click-on-block-reference.html

 

I also posted a solution in my blog, in which user do not have to modify DoubleClick action in CUI. see it here:

 

http://drive-cad-with-code.blogspot.ca/2012/12/custom-double-click-action-using.html

 

HTH.

 

 

 

Message 3 of 20
RPeter
in reply to: norman.yuan

Norman, thanks to you I established to trigger the doubleclick command. However I'm strugling with the select.implied.

I've added temprorary a editor msg with the count of the selected objects. When I use select.implied it always return 0.

 

In my other command MyBlockEdit I also use the select.implied, this however doesn't seem to give any problem.

 

I think (not sure of it) that when I double click the selection gets lost and there is nothing selected anymore.?

Message 4 of 20
norman.yuan
in reply to: RPeter

Are you saying that in the Application.BeginDoubleClick event handler, the Editor.SelectImplied() always return 0 count of selected?

 

When you double-click on an entity, does it get highlighted? Or is the pickbox (cursor) too small and no entity is actually selected when you double-click?

 

Could you show your code in the event handler?

Message 5 of 20
RPeter
in reply to: norman.yuan

Norman,

 

I'm out of office right now so can't copy the exact code, will do this first thing tomorrow.

The code looks like this:

Dim ed As Editor = Application.DocumentManager.MdiActiveDocument.Editor
ed.WriteMessage(vbCrLf & "Custom Double-Click action started.")
Dim res As PromptSelectionResult = ed.SelectImplied
If res.Status = PromptStatus.OK Then
    ed.WriteMessage(vbCrLf & res.Value.Count & " object(s) selected.")
    'some more code to check if the selection is the right Dynamic Block...
End If

 

I get the message that the double-click action is started.

The return of the selected object count is always 0.

ed.selectprevious or ed.selectlast returns 1 (or more) but is never the correct selected entity...

Message 6 of 20
Alexander.Rivilis
in reply to: RPeter

If your's code is a command it must have CommandFlags.UsePickSet attribute in order to use ed.SelectImplied

Відповідь корисна? Клікніть на "ВПОДОБАЙКУ" цім повідомленням! | Do you find the posts helpful? "LIKE" these posts!
Находите сообщения полезными? Поставьте "НРАВИТСЯ" этим сообщениям!
На ваше запитання відповіли? Натисніть кнопку "ПРИЙНЯТИ РІШЕННЯ" | Have your question been answered successfully? Click "ACCEPT SOLUTION" button.
На ваш вопрос успешно ответили? Нажмите кнопку "УТВЕРДИТЬ РЕШЕНИЕ"


Alexander Rivilis / Александр Ривилис / Олександр Рівіліс
Programmer & Teacher & Helper / Программист - Учитель - Помощник / Програміст - вчитель - помічник
Facebook | Twitter | LinkedIn
Expert Elite Member

Message 7 of 20
RPeter
in reply to: Alexander.Rivilis

Alexander,

 

It's not a command, its a Double-Click handler.

 

Norman,

 

Here is the code from my app:

Public Shared Sub MyDblClick(ByVal sender As Object, ByVal e As BeginDoubleClickEventArgs)
    Dim ed As Editor = Application.DocumentManager.MdiActiveDocument.Editor
    ed.WriteMessage(vbCrLf & "Custom Double-Click action started.")
    Dim res As PromptSelectionResult = ed.SelectImplied
    If res.Status = PromptStatus.OK Then
        ed.WriteMessage(vbCrLf & res.Value.Count & " object(s) selected.")
        'some more code to check if the selection is the right Dynamic Block...
    End If
End Sub

 I've tested some more with the code from above:

Double-Clicking on a Polyine, Rectangle,... it will return the number of the selected items.

Double-Clicking on a block (without attributes) = result of selected items.

Double-Clicking on a block (with attributes) = no result of the selected items.

 

How can I pass this problem?

Message 8 of 20
Alexander.Rivilis
in reply to: RPeter


@RPeter wrote:

Alexander,

 

Double-Clicking on a block (with attributes) = no result of the selected items.

 

How can I pass this problem?


It is look like a bug. But I think there is workaround: using PointMonitor event to monitor entity under cursor in moment of doubleclick.

Відповідь корисна? Клікніть на "ВПОДОБАЙКУ" цім повідомленням! | Do you find the posts helpful? "LIKE" these posts!
Находите сообщения полезными? Поставьте "НРАВИТСЯ" этим сообщениям!
На ваше запитання відповіли? Натисніть кнопку "ПРИЙНЯТИ РІШЕННЯ" | Have your question been answered successfully? Click "ACCEPT SOLUTION" button.
На ваш вопрос успешно ответили? Нажмите кнопку "УТВЕРДИТЬ РЕШЕНИЕ"


Alexander Rivilis / Александр Ривилис / Олександр Рівіліс
Programmer & Teacher & Helper / Программист - Учитель - Помощник / Програміст - вчитель - помічник
Facebook | Twitter | LinkedIn
Expert Elite Member

Message 9 of 20
norman.yuan
in reply to: RPeter

OK, I verified with this code:

 

private void Application_BeginDoubleClick(object sender, BeginDoubleClickEventArgs e)
        {
            Document dwg = Application.DocumentManager.MdiActiveDocument;
            Editor ed = dwg.Editor;

            PromptSelectionResult res = ed.SelectImplied();
            if (res.Status == PromptStatus.OK)
            {
                ed.WriteMessage("{0} entit{1} selected.", res.Value.Count, res.Value.Count > 1 ? "ies" : "y");
            }
            else
            {
                ed.WriteMessage("\nCannot select implied selection set.");
            }
        }

The Editor.SelectImplied() work with line, circle, arc, block WITHOUT attribute (e.g) PromptSelectionResult.Status returns OK). However, if we double-click a block that has attribute, the returned status is PromptStatus.Error. So, I am not sure if it is by design (probably not, because the built-in doubleclick action defined by the CUI works). It could be a bug as Alexander suggested. If so, it is serious blow to my double-click solution, because calling up custom dialog box on double-click would likely be used more often on editing block with attribute. I'll have to find workaround and updte my blog post.

 

I currently only have access to Acad2012, and hope this has already been fixed in Acad 2013, or upcoming Acad2014?

Message 10 of 20
RPeter
in reply to: norman.yuan

Norman,

 

The problem is still there in 2013 (+SP1), this is the version we use about 3 months now.

We have no plans to upgrade straight away to the 2014 when its available becouse where are in a Vault implementation process right now for all our Autodesk Software.

 

I'll try to search for a work arround, if I would find a solution I'll post it here.

Message 11 of 20
norman.yuan
in reply to: RPeter

I have finally found a bit time to work out an solution to the issue you have (or rather, the issue my posted solution has): Editor.SelectImplied() does not select a blockreference that has attributes. I would consider a bug.

 

My workaround is to drop using Editor.SelectImplied() in the Application_BeginDoubleClick event handler. I published a new article in my blog on the updated solution here:

 

http://drive-cad-with-code.blogspot.ca/2013/03/update-custom-double-click-action-using.html

 

 

Message 12 of 20
RPeter
in reply to: norman.yuan

Norman,

 

I've just read your new post.

However I can't access the ed.SelectAtPickbox()

'SelectAtPickbox' is not a member of 'Autodesk.Autocad.Editorinput.Editor'

 

I'm using VB.net 2010 (because my C# isn't so good Smiley Frustrated )

 

***EDIT

Looks like it was to early this morning, your solution was ok.

***END EDIT

 

Regards

 

Peter

Message 13 of 20

Hi, Norman!

Great job! Criticism is accepted? Not tested but (IMHO):

1. You have to convert points to UCS because SelectCrossingPolygon method use points in UCS.

2. Maybe using method Editor.GetNestedEntity with PromptNestedEntityOptions.UseNonInteractivePickPoint == true instead of SelectCrossingPolygon will be useful.

Відповідь корисна? Клікніть на "ВПОДОБАЙКУ" цім повідомленням! | Do you find the posts helpful? "LIKE" these posts!
Находите сообщения полезными? Поставьте "НРАВИТСЯ" этим сообщениям!
На ваше запитання відповіли? Натисніть кнопку "ПРИЙНЯТИ РІШЕННЯ" | Have your question been answered successfully? Click "ACCEPT SOLUTION" button.
На ваш вопрос успешно ответили? Нажмите кнопку "УТВЕРДИТЬ РЕШЕНИЕ"


Alexander Rivilis / Александр Ривилис / Олександр Рівіліс
Programmer & Teacher & Helper / Программист - Учитель - Помощник / Програміст - вчитель - помічник
Facebook | Twitter | LinkedIn
Expert Elite Member

Message 14 of 20
RPeter
in reply to: Alexander.Rivilis

Alexander,

 

I've tried your solution, but the selected entity is the modelspace entity and not the selected block.

 

@all,

 

Normaly when a attribute block is DoubleClicked it sends the EATTEDIT command followed by the block location (point3d)

 

Because we've vetoed the EATTEDIT command I would like to supress the following line:

Command: 281.959074,252.067108,0.000000 Unknown command "959074,252.067108,0.000000".  Press F1 for help.

Message 15 of 20
Alexander.Rivilis
in reply to: RPeter


@RPeter wrote:

Alexander,

 

I've tried your solution, but the selected entity is the modelspace entity and not the selected block.


What is the solution? You're talking about using Editor.GetNestedEntity?

Відповідь корисна? Клікніть на "ВПОДОБАЙКУ" цім повідомленням! | Do you find the posts helpful? "LIKE" these posts!
Находите сообщения полезными? Поставьте "НРАВИТСЯ" этим сообщениям!
На ваше запитання відповіли? Натисніть кнопку "ПРИЙНЯТИ РІШЕННЯ" | Have your question been answered successfully? Click "ACCEPT SOLUTION" button.
На ваш вопрос успешно ответили? Нажмите кнопку "УТВЕРДИТЬ РЕШЕНИЕ"


Alexander Rivilis / Александр Ривилис / Олександр Рівіліс
Programmer & Teacher & Helper / Программист - Учитель - Помощник / Програміст - вчитель - помічник
Facebook | Twitter | LinkedIn
Expert Elite Member

Message 16 of 20
RPeter
in reply to: Alexander.Rivilis

The solution is the ed.selectatpickbox method.

 

The method ed.getnestedentity returns the modelspace objectid so this is a no go for me.

Message 17 of 20
Alexander.Rivilis
in reply to: RPeter


@RPeter wrote:
... The method ed.getnestedentity returns the modelspace objectid so this is a no go for me...

Try this code to identify selected BlockReference:

 

[CommandMethod("TestSel")]
public static void TestSel()
{
  Document doc = Application.DocumentManager.MdiActiveDocument;
  Editor ed = doc.Editor;
  PromptPointResult ppr = ed.GetPoint("\nPick Point on entity: ");
  if (ppr.Status != PromptStatus.OK) return;
  PromptNestedEntityOptions pneo = new PromptNestedEntityOptions("");
  pneo.NonInteractivePickPoint = ppr.Value;
  pneo.UseNonInteractivePickPoint = true;
  PromptNestedEntityResult pner = ed.GetNestedEntity(pneo);
  if (pner.Status != PromptStatus.OK) return;
  ObjectId[] ids = pner.GetContainers();
  using (Transaction tr = doc.TransactionManager.StartTransaction()) {
    Entity ent = tr.GetObject(pner.ObjectId, OpenMode.ForRead) as Entity;
    ed.WriteMessage("\nSelected entity of class {0} with objectId = {1}", 
        ent.GetRXClass().Name, pner.ObjectId);
    if (ent is AttributeReference && ids.Length == 0) {
      AttributeReference attr = ent as AttributeReference;
      BlockReference bref = 
          tr.GetObject(attr.OwnerId, OpenMode.ForRead) as BlockReference;
      BlockTableRecord btr = 
          tr.GetObject(bref.BlockTableRecord, OpenMode.ForRead) as BlockTableRecord;
      ed.WriteMessage("\nin BlockReference of {0} with objectId = {1}", 
              btr.Name, bref.ObjectId);
    } else if (ids.Length > 0) {
        BlockReference bref = 
            tr.GetObject(ids[0], OpenMode.ForRead) as BlockReference;
        BlockTableRecord btr = 
            tr.GetObject(bref.BlockTableRecord, OpenMode.ForRead) as BlockTableRecord;
        ed.WriteMessage("\nBlockReference of {0} with objectId = {1}", 
            btr.Name, bref.ObjectId);
    } else {
        ed.WriteMessage("\nSelected not BlockReference!");
    }
    tr.Commit();
  }
}

 

Відповідь корисна? Клікніть на "ВПОДОБАЙКУ" цім повідомленням! | Do you find the posts helpful? "LIKE" these posts!
Находите сообщения полезными? Поставьте "НРАВИТСЯ" этим сообщениям!
На ваше запитання відповіли? Натисніть кнопку "ПРИЙНЯТИ РІШЕННЯ" | Have your question been answered successfully? Click "ACCEPT SOLUTION" button.
На ваш вопрос успешно ответили? Нажмите кнопку "УТВЕРДИТЬ РЕШЕНИЕ"


Alexander Rivilis / Александр Ривилис / Олександр Рівіліс
Programmer & Teacher & Helper / Программист - Учитель - Помощник / Програміст - вчитель - помічник
Facebook | Twitter | LinkedIn
Expert Elite Member

Message 18 of 20
RPeter
in reply to: Alexander.Rivilis

@Alexander,

 

Your code seems to work.

 

I've done it wrong I've stopped after setting the entity to pner.objectid and didn't go further to the bref and btr (and in my case a dbtr dynamicblocktablerecord to determine the real name)

 

Message 19 of 20

Thank you Alexander. Yes, I should have take into UCS into account. I'll update if I can manage a bit time for it.

Message 20 of 20
DECH0002
in reply to: norman.yuan

Hello

 

This runs fine with AutoCAD. With AutoCAD Mechanical, at least with Rel. 2012, the BeginDoubleClick event is only fired, if the double-click is run without any entity. Any idea?

 

Regards,

Martin

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk DevCon in Munich May 28-29th


Autodesk Design & Make Report

”Boost