Define custom action for double click on a block of a particular name

Define custom action for double click on a block of a particular name

lpr8PZGA
Enthusiast Enthusiast
508 Views
4 Replies
Message 1 of 5

Define custom action for double click on a block of a particular name

lpr8PZGA
Enthusiast
Enthusiast

Hello,

suppose having a block named MyBlock.

Is there a way to define a special action (command) to be performed on double-click on the block named MyBlock?

- ObjectARX (C, C++).

TIA.

Lukas

0 Likes
509 Views
4 Replies
Replies (4)
Message 2 of 5

daniel_cadext
Advisor
Advisor

It’s a bit of a hassle because you have to remove the ATTBLOCKREF double click action from the CUI  

 

class BlockRefDoubleClickEdit : public AcDbDoubleClickEdit
{
public:
    BlockRefDoubleClickEdit(void) = default;;
    virtual ~BlockRefDoubleClickEdit(void) override = default;

    void finishEdit(void) override
    {
        acutPrintf(_T("\nYou did it"));
    }

    void startEdit(AcDbEntity* pEnt, AcGePoint3d pt) override
    {
        AcApDocument* pDoc = acDocManager->curDocument();
        acDocManager->lockDocument(pDoc, AcAp::kWrite);
        if (pEnt->isA() == AcDbBlockReference::desc())
            acutPrintf(_T("\nYAY"));
        acDocManager->unlockDocument(pDoc);
    }
};

 

then

 

class ArxTemplate : public AcRxArxApp
{
    BlockRefDoubleClickEdit m_pEdit;
public:
    ArxTemplate() : AcRxArxApp()
    {
    }

    virtual AcRx::AppRetCode On_kInitAppMsg(void* pkt)
    {
        AcRx::AppRetCode retCode = AcRxArxApp::On_kInitAppMsg(pkt);
        AcDbBlockReference::desc()->addX(AcDbDoubleClickEdit::desc(), &m_pEdit);
        return (retCode);
    }

    virtual AcRx::AppRetCode On_kUnloadAppMsg(void* pkt)
    {
        AcRx::AppRetCode retCode = AcRxArxApp::On_kUnloadAppMsg(pkt);
        AcDbBlockReference::desc()->delX(AcDbDoubleClickEdit::desc());
        return (retCode);
    }
     ....
};
Python for AutoCAD, Python wrappers for ARX https://github.com/CEXT-Dan/PyRx
0 Likes
Message 3 of 5

lpr8PZGA
Enthusiast
Enthusiast

Hello,

I understand the code, but where is a kind of checking for the block name - here "MyBlock"?

And how do I perform a "default" action for non-"MyBlock" blocks?

Best regards,

Lukas

0 Likes
Message 4 of 5

daniel_cadext
Advisor
Advisor

You can check the name from getting the block record, if the names don’t match, you would have to forward the call to eattedit via send string to execute or something, that is, if the block has attributes. It’s a pretty messy kludge,

 

 void startEdit(AcDbEntity* pEnt, AcGePoint3d pt) override
 {
     AcApDocument* pDoc = acDocManager->curDocument();
     acDocManager->lockDocument(pDoc, AcAp::kWrite);
     if (pEnt->isA() == AcDbBlockReference::desc())
     {
         static AcString src=_T("GRA");
         AcDbBlockReference* pRef = static_cast<AcDbBlockReference*>(pEnt);
         AcDbBlockTableRecordPointer pBlock(pRef->blockTableRecord());
         AcString name;
         if (auto es = pBlock->getName(name); es == eOk && name.compareNoCase(src) == 0)
         {
             acutPrintf(_T("\nYAY"));
             return;
         }
     }
     acDocManager->sendStringToExecute(pDoc, _T("_.EATTEDIT "));
     acDocManager->unlockDocument(pDoc);
 }

 

maybe there’s a better way. Too bad there’s no AcDbDoubleClickOverrule

 

Python for AutoCAD, Python wrappers for ARX https://github.com/CEXT-Dan/PyRx
0 Likes
Message 5 of 5

anuj_abhiwan
Contributor
Contributor
To add a double-click action on a block by name:

js
Copy
Edit
document.querySelector('[name="blockName"]').ondblclick = () => {
  // custom action here
};
0 Likes