Jump to content

Adding a menu with Visual Lisp


Recommended Posts

Posted

All,

 

I am wondering how difficult it would be to add a menu to the menu bar using visual lisp. I have an enterprise CUI on many users computers and several users don't have the menu from that CUI on thier menubar. Instead of going through the CUI and editing thier workspace i want to add the menu using Visual Lisp. I know that this should be possible using, InsertInMenuBar and the PopupMenu object. I am not sure how to access the specific menu.

 

Any suggestions or solutions?

 

Thanks,

Matt

Guest kruuger
Posted

maybe this. just edit the list and extension (cui or cuix)

(defun LOADMENU (/ ERR OLDCMD)
 (setq OLDCMD (getvar "cmdecho"))
 (setvar "cmdecho" 0)
 (foreach MenuName (list "Adservco_2010" "Kojacek_2010" "Tools_2010")  
   (if (not (menugroup MenuName))
     (if (findfile (strcat MenuName ".cuix"))
       (progn
         (command "_cuiload" MenuName)
         (princ (strcat "\n>> Menu [" MenuName "] loaded."))
       )
       (if (not ERR)
         (setq ERR (strcat "\n- " MenuName))
         (setq ERR (strcat ERR "\n- " MenuName))
       )
     )
   )
 )
 (if ERR
   (alert (strcat "\nCan't find partial menu:" ERR))
 )
 (setvar "cmdecho" OLDCMD)
 (princ)
)

(LOADMENU)
(princ)

Posted

This includes no error handling, and just the bare bones, but it should help you get started.

 

; Get AutoCAD
(setq *acad* (vlax-get-acad-object))
; Get the loaded menugroups
(setq *mgs* (vla-get-Menugroups *acad*))
; Get a particular menugroup
(setq *menu* (vlax-invoke-method *mgs* "Item" 0))
; Get the menus in this menugroup
(setq *pops* (vla-get-menus *menu*))
; Get a particular menu
(setq *pop* (vlax-invoke-method *pops* "Item" 5))
; Insert it
(vla-InsertInMenuBar *pop* 5)

  • 10 months later...
Posted
This includes no error handling, and just the bare bones, but it should help you get started.

 

; Get AutoCAD
(setq *acad* (vlax-get-acad-object))
; Get the loaded menugroups
(setq *mgs* (vla-get-Menugroups *acad*))
; Get a particular menugroup
(setq *menu* (vlax-invoke-method *mgs* "Item" 0))
; Get the menus in this menugroup
(setq *pops* (vla-get-menus *menu*))
; Get a particular menu
(setq *pop* (vlax-invoke-method *pops* "Item" 5))
; Insert it
(vla-InsertInMenuBar *pop* 5)

 

The code works nice in 4 first lines, but there is a problem running this line:

(setq *pop* (vlax-invoke-method *pops* "Item" 5))

Visual LISP returns this error message:

; error: Automation Error. Invalid argument index in Item
Who knows what is wrong with my understanding or the code of rkmcswain?

 

P.S. I tried also numbers other than 5 with no success.

Posted

Walk through the code one line at a time and validate each variable.

It sounds like whatever *pops* is, doesn't have an item 5.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...