AutoCAD: Add shortcut keys/right-click

Source: Internet
Author: User

Autodesk. AutoCAD. applicationservices. application supports two contextmenu extensions: defaultcontextmenu and objectcontextmenu.

Defaultcontextmenu: no shortcut menu is selected in the current context.

Objectcontextmenu: select the shortcut menu for the specified type of entity in the current context. For example:

 

# Region Addcontextmenu
///   <Summary>
/// Right-click menu
///   </Summary>
Private   Void Addcontextmenu ()
{
Try
{
// Defaultcontextmenu
Contextmenuextension defaultcontextmenu =   New Contextmenuextension ();
Defaultcontextmenu. Title =   " Mydefaconcontextmenu " ;
Autodesk. AutoCAD. Windows. menuitem defaultcontextmenu_item1 =   New Autodesk. AutoCAD. Windows. menuitem ( " Mydefaconcontextmenu_item1 " , ARX. UI. Resources. resource1.taobao );
Defaultcontextmenu_item1.click + =   New Eventhandler (defaultcontextmenu_onclick );
Defaultcontextmenu. menuitems. Add (defaultcontextmenu_item1 );
Arxapp. adddefaconcontextmenuextension (defaultcontextmenu );

// Objectcontextmenu
Contextmenuextension objcontextmenu =   New Contextmenuextension ();
Objcontextmenu. Title =   " Myobjectcontextmenu " ;
Objcontextmenu. Popup + =   New Eventhandler (objcontextmenu_popup );

Autodesk. AutoCAD. Windows. menuitem objcontextmenu_item1 =   New Autodesk. AutoCAD. Windows. menuitem ( " Go to Baidu " , ARX. UI. Resources. resource1.baidu );
Objcontextmenu_item1.click + =   New Eventhandler (objcontextmenu_item1_click );
Objcontextmenu. menuitems. Add (objcontextmenu_item1 );

Autodesk. AutoCAD. Windows. menuitem objcontextmenu_item2 =   New Autodesk. AutoCAD. Windows. menuitem ( " Go to Google " , ARX. UI. Resources. resource1.google );
Objcontextmenu_item2.click + =   New Eventhandler (objcontextmenu_item2_click );
Objcontextmenu. menuitems. Add (objcontextmenu_item2 );

Arxapp. addobjectcontextmenuextension (rxobject. getclass ( Typeof (Polyline), objcontextmenu );
}
Catch (System. Exception exc)
{
Writeline ( String . Format ( " \ N contextmenu error: {0} " , Exc. Message ));
}
}

Void Objcontextmenu_popup ( Object Sender, eventargs E)
{
Using (Documentlock doclock = Arxapp. documentmanager. mdiactivedocument. lockdocument ())
{
Document Doc = Application. documentmanager. mdiactivedocument;
Database DB = Doc. database;
Editor ed = Doc. Editor;
Bool Visible =   True ;

// If that is multiple selection, disabled the menu item.
Promptselectionresult selectionres = Ed. selectimplied ();
If (Selectionres. Status = Promptstatus. OK)
{
Objectid [] objids = Selectionres. value. getobjectids ();
If (Objids ! =   Null   && Objids. Length >   1 )
{
Visible =   False ;
}
}

Contextmenuextension objcontextmenu = Sender As Contextmenuextension;
If (Objcontextmenu ! =   Null )
{
Foreach (Menuitem item In Objcontextmenu. menuitems)
{
Item. Enabled = Visible;
}
}
}
}

Private   Void Defaultcontextmenu_onclick ( Object Sender, eventargs E)
{
Using (Documentlock doclock = Arxapp. documentmanager. mdiactivedocument. lockdocument ())
{
Arxapp. showalertdialog ( " Defaultcontextmenu_onclick " );
}
}

Void Objcontextmenu_item1_click ( Object Sender, eventargs E)
{
Using (Documentlock doclock = Arxapp. documentmanager. mdiactivedocument. lockdocument ())
{
System. Diagnostics. process. Start ( " Iexplore. exe " , " Http://www.baidu.com " );
}
}

Void Objcontextmenu_item2_click ( Object Sender, eventargs E)
{
Using (Documentlock doclock = Arxapp. documentmanager. mdiactivedocument. lockdocument ())
{
System. Diagnostics. process. Start ( " Iexplore. exe " , " Http://www.google.com " );
}
}

# Endregion

You can perform some logic processing in the objcontextmenu_popup event.

The following is the namespace used:

Code

Using Autodesk. AutoCAD. applicationservices;
Using Arxapp = Autodesk. AutoCAD. applicationservices. Application;
Using Arxdoc = Autodesk. AutoCAD. applicationservices. Document;
Using Autodesk. AutoCAD. databaseservices;
Using Autodesk. AutoCAD. windows;

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.