Adding Context-Sensitve Shortcut Menus with VLisp

Discussion in 'AutoCAD' started by krollj, Jan 20, 2004.

  1. krollj

    krollj Guest

    Can anyone tell me if it is possible to add context-sensitive shortcut
    menus with VLisp.

    I can add menu items to existing shortcut menus no problems eg adding a
    function (XRELOAD) to XREF shortcut menu

    (defun AddContextMenuItem ( / acadApp acadMenuGroups Menu)
    (setq acadApp (vlax-get-acad-object))
    (setq acadMenuGroups (vla-get-MenuGroups acadApp))
    (vlax-for MenuGroup acadMenuGroups
    (setq Name (vla-get-name MenuGroup))
    (if (= Name "ACAD") (setq Menu MenuGroup))
    )
    (setq PopUps (vla-get-Menus Menu))
    (setq XREFContext nil)
    (vlax-for PopUp PopUps
    (setq Name (vla-get-name PopUp))
    (if (= Name "Context menu for XREF Objects") (setq XREFContext
    PopUp))
    )
    (vla-AddMenuItem XREFContext (vla-get-count XREFContext) "Xref Reload"
    "(xreload) ")
    (princ)
    )

    However if I try to add a completely new menu for an object it won't
    recognise it as a context-sensitive menu, eg adding a menu for a CIRCLE

    (defun AddContextMenu ( / acadApp acadMenuGroups Menu)
    (setq acadApp (vlax-get-acad-object))
    (setq acadMenuGroups (vla-get-MenuGroups acadApp))
    (vlax-for MenuGroup acadMenuGroups
    (setq Name (vla-get-name MenuGroup))
    (if (= Name "ACAD") (setq Menu MenuGroup))
    )
    (setq PopUps (vla-get-Menus Menu))
    (setq CIRC_Context (vla-add Popups "Context menu for CIRCLE Object"))
    (vla-AddMenuItem CIRC_Context "" "Erase" (strcat (chr 3) (chr 3)
    "_erase" (chr 32)))
    (princ)
    )

    It obviously has something to do with the menu ALIAS for Context menus eg
    **OBJECT_CIRCLE, but there doesn't appear to be a property for ALIAS in
    the PopUpMenu Object.

    Does anyone know if there is a way of specifying an ALIAS for a PopUpMenu
    object or is this an impossible task?

    Thanks

    Jason Kroll
     
    krollj, Jan 20, 2004
    #1
  2. I've found that the menuGroup object does not
    support an Add method. I've had to define any
    context menus in a menu file first, then add what
    I want on the fly via Vlisp.

    I'm all ears if someone else knows of a way.
     
    Jason Piercey, Jan 20, 2004
    #2
Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.