.NET

Reply
*Expert Elite*
norman.yuan
Posts: 993
Registered: ‎04-27-2009
Message 11 of 20 (467 Views)

Re: Run command on double click block with specific name?

03-14-2013 12:42 PM 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

 

 

Valued Contributor
RPeter
Posts: 88
Registered: ‎01-09-2009
Message 12 of 20 (459 Views)

Re: Run command on double click block with specific name?

03-15-2013 12:30 AM 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 :smileyfrustrated: )

 

***EDIT

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

***END EDIT

 

Regards

 

Peter

Moderator
Alexander.Rivilis
Posts: 1,412
Registered: ‎04-09-2008
Message 13 of 20 (442 Views)

Re: Run command on double click block with specific name?

03-15-2013 03:13 AM in reply to: norman.yuan

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.


Пожалуйста не забывайте про Утвердить в качестве решения! Утвердить в качестве решения и Give Kudos!Баллы
Please remember to Accept Solution! Accept as Solution and Give Kudos!Kudos

Valued Contributor
RPeter
Posts: 88
Registered: ‎01-09-2009
Message 14 of 20 (436 Views)

Re: Run command on double click block with specific name?

03-15-2013 04:30 AM 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.

Moderator
Alexander.Rivilis
Posts: 1,412
Registered: ‎04-09-2008
Message 15 of 20 (432 Views)

Re: Run command on double click block with specific name?

03-15-2013 04:58 AM 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?


Пожалуйста не забывайте про Утвердить в качестве решения! Утвердить в качестве решения и Give Kudos!Баллы
Please remember to Accept Solution! Accept as Solution and Give Kudos!Kudos

Valued Contributor
RPeter
Posts: 88
Registered: ‎01-09-2009
Message 16 of 20 (429 Views)

Re: Run command on double click block with specific name?

03-15-2013 05:01 AM 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.

Moderator
Alexander.Rivilis
Posts: 1,412
Registered: ‎04-09-2008
Message 17 of 20 (425 Views)

Re: Run command on double click block with specific name?

03-15-2013 05:12 AM 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();
  }
}

 


Пожалуйста не забывайте про Утвердить в качестве решения! Утвердить в качестве решения и Give Kudos!Баллы
Please remember to Accept Solution! Accept as Solution and Give Kudos!Kudos

Valued Contributor
RPeter
Posts: 88
Registered: ‎01-09-2009
Message 18 of 20 (421 Views)

Re: Run command on double click block with specific name?

03-15-2013 05:46 AM 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)

 

*Expert Elite*
norman.yuan
Posts: 993
Registered: ‎04-27-2009
Message 19 of 20 (417 Views)

Re: Run command on double click block with specific name?

03-15-2013 07:45 AM in reply to: Alexander.Rivilis

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

Active Member
DECH0002
Posts: 7
Registered: ‎03-13-2008
Message 20 of 20 (330 Views)

Re: Run command on double click block with specific name?

07-17-2013 02:49 PM 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

Announcements
Are you familiar with the Autodesk Expert Elites? The Expert Elite program is made up of customers that help other customers by sharing knowledge and exemplifying an engaging style of collaboration. To learn more, please visit our Expert Elite website.
Need installation help?

Start with some of our most frequented solutions or visit the Installation and Licensing Forum to get help installing your software.