MarcoW Posted May 4, 2009 Posted May 4, 2009 Again about menu's... I would like to create / have a menu called “options”, lets say right beside the Express menu. One of the functions must be to load or unload a second menu, lets say that one is called “test”. Both menu’s (test.mnu and options.mnu) are saved in the right support file search path folders. So I’m starting the right way… This is how the menu “options”( wich is loaded whan acad starts up) looks like: ***menugroup=options ***POP1 [->Load or unload other menu’s] [Test On]^C^Cmenuload;test [Test “Off”]^C^Cmenuunload;test; [~ When executing the “Test Off” command it works all right, the menu dissappears and when entering the command “menuload” on the commandbar the dialog box shows no menu called “test”. When executing the “Test On” command it does not work all right: the menu doesn’t show. However: when entering the command “menuload” on the commandbar the dialog box shows that is has loaded the menu “test”. I cannot enter a second command or press a buttun that will load the menu all thru so that it appears. When manually unloading the loaded menu and then manually load it in the dialog box the menu DOES show. Where is this going wrong?? Thanks for helping me out. Quote
rkmcswain Posted May 4, 2009 Posted May 4, 2009 Loading a menu and getting a pull-down to show up are two different operations. We have a lisp routine to do this, and it works something like this. 1. Find out if the menu is loaded or not. 2. If not, load it. 3. Find out if the pull-down is visible or not (remember, if the answer to 1 is yes, then the pull down may already be visible) 4. If not, make it visible. Look into the vla-*Menu* functions Quote
MarcoW Posted May 4, 2009 Author Posted May 4, 2009 Loading a menu and getting a pull-down to show up are two different operations. I have a lisp routine to do this, and it works something like this. 1. Find out if the menu is loaded or not. 2. If not, load it. 3. Find out if the pull-down is visible or not (remember, if the answer to 1 is yes, then the pull down may already be visible) 4. If not, make it visible. Look into the vla-*Menu* functions Tnx for your reply. Yes you are right, 2 differtent things, yet did not look at them as so... What do you mean with: "Look into the vla-*Menu* functions" ? You do not happen to have the piece of code to share with me? Quote
rkmcswain Posted May 4, 2009 Posted May 4, 2009 Tnx for your reply.Yes you are right, 2 differtent things, yet did not look at them as so... What do you mean with: "Look into the vla-*Menu* functions" ? Lisp functions that match the filter vla-*menu* These are what you will need to do what you want to do... You do not happen to have the piece of code to share with me? Sorry, the code is not mine to share. Quote
MarcoW Posted May 5, 2009 Author Posted May 5, 2009 Can anyone explain to me what "rkmcswain" means? Or, rkmcswain, if you can, please would yu? This: Look into the vla-*Menu* functions is what is do not understand. Okay I am Dutch... Thanks so far. Quote
wizman Posted May 5, 2009 Posted May 5, 2009 i've worked with menu's before and noticed same problem with yours, so i ended up writing a routine loading the menu and ensuring that it is visible in the menubar just like rkmcswain suggested. you may try this loadit lisp and link it with your macro: http://www.cadtutor.net/forum/showthread.php?t=26379 another thing i can recommend is to make it just a toggle for on/off instead of having them on two separate lines in your pull down menu. Quote
MarcoW Posted May 5, 2009 Author Posted May 5, 2009 I get error code... THis is what I've made of it: (defun c:loadit (/ cui_database mnbar flag) (vl-load-com) (setq cui_database (list "options" ;<<< MENUGROUP "options.mnu" ;<<<PATH & CUI FILENAME "options" ;<<< MENUNAME ) ;_ end_list ) ;_ end_setq (vlax-for n (setq all_menus (vla-get-MenuGroups (vlax-get-Acad-Object) ) ;_ end_vla-get-MenuGroups ) ;_ end_setq (if (= (vla-get-name n) (car cui_database)) (setq flag T) ) ;_ end_if ) ;_ end_vlax-for (if (null flag) (progn (vla-load all_menus (cadr cui_database) ) ;_ end_vla-load (setq MnBar (vla-get-MenuBar (vlax-get-Acad-Object) ) ;_ end_vla-get-MenuBar ) ;_ end_setq (vla-InsertInMenuBar (vla-Item (vla-get-Menus (vla-Item (vla-get-MenuGroups (vlax-get-Acad-Object) ) ;_ end_vla-get-MenuGroups (car cui_database) ) ;_ end_vla-Item ) ;_ end_vla-get-Menus (caddr cui_database) ) ;_ end_vla-Item (1- (vla-get-Count MnBar)) ) ;_ end_vla-InsertInMenuBar ) ;_ end_progn (princ "\n>>..MENU IS ALREADY LOADED..<<") ) ;_ end_if (princ) ) ;_ end_defun When loading the lisp, it says: Command: ; error: Automation Error. Invalid argument options in Item. What goes wrong? Quote
wizman Posted May 5, 2009 Posted May 5, 2009 i think the menuname could be wrong, try loading it manually then inspecting the menuname in the Tools>customize>interface(im using acad '09, not sure if this is same with acad '07), if still not ok, could you post your mnu file. Quote
MarcoW Posted May 6, 2009 Author Posted May 6, 2009 By the way I use MNU files, not CUI... Is that the problem? Thought I'd altered it allright. Can I send you a PM or should I post on the forum? Quote
wizman Posted May 6, 2009 Posted May 6, 2009 By the way I use MNU files, not CUI...Is that the problem? Thought I'd altered it allright. Can I send you a PM or should I post on the forum? marcow, you'll get a better response if you post it here. i think there's no problem using mnu. Quote
MarcoW Posted May 6, 2009 Author Posted May 6, 2009 (I noticed that this example is not like the example I started with in this threat, sorry for that.) I want to be able to VISIBLE load or unload my custom made options menu (options.mnu) by pressing a toggle switch in another menu. Firts of all: when I simply put the next line into the command line, the desired menu is unloaded: (command "menuunload" "options") The response I get is: Command: (command "menuunload" "options") menuunload Enter the name of a Customization Group to unload:options Customization file unloaded successfully. Customization Group: options Command: nil This works. Then the load command: Entered into the commandline: (command "menuunload" "options") The response I get is: Command: (command "menuload" "options") menuload Enter name of customization file to load: options Customization file loaded successfully. Customization Group: options Command: nil Looks like it works. It is loaded but not visible in the screen. WHY NOT? This is the options.mnu file on my pc in the specified support file search folder: ***menugroup=options ***POP1 [->Load or unload other menu’s] [empty]^C^C [empty]^C^C [~ This is the macro (or called Diesel ..??) which is entered in another menu to load or unload my options menu: [Options OFF]^C^Cmenuunload;options; [Options ON]^C^Cmenuload;options; And again, when loaded it works all fine it just doesn't show the menu options Visible. It is loaded though NOT visible. Guess I'll have to let it rest... NEAH ! Quote
wizman Posted May 6, 2009 Posted May 6, 2009 your menuname is: "Load or unload other menu’s" not options Quote
MarcoW Posted May 6, 2009 Author Posted May 6, 2009 Okay, that was a little stupid I guess... but still dont work. The lisp: (defun c:loadit (/ cui_database mnbar flag) (vl-load-com) (setq cui_database (list "options" ;<<< MENUGROUP "options.mnu" ;<<<PATH & CUI FILENAME "options" ;<<< MENUNAME ) ;_ end_list ) ;_ end_setq (vlax-for n (setq all_menus (vla-get-MenuGroups (vlax-get-Acad-Object) ) ;_ end_vla-get-MenuGroups ) ;_ end_setq (if (= (vla-get-name n) (car cui_database)) (setq flag T) ) ;_ end_if ) ;_ end_vlax-for (if (null flag) (progn (vla-load all_menus (cadr cui_database) ) ;_ end_vla-load (setq MnBar (vla-get-MenuBar (vlax-get-Acad-Object) ) ;_ end_vla-get-MenuBar ) ;_ end_setq (vla-InsertInMenuBar (vla-Item (vla-get-Menus (vla-Item (vla-get-MenuGroups (vlax-get-Acad-Object) ) ;_ end_vla-get-MenuGroups (car cui_database) ) ;_ end_vla-Item ) ;_ end_vla-get-Menus (caddr cui_database) ) ;_ end_vla-Item (1- (vla-get-Count MnBar)) ) ;_ end_vla-InsertInMenuBar ) ;_ end_progn (princ "\n>>..MENU IS ALREADY LOADED..<<") ) ;_ end_if (princ) ) ;_ end_defun The menu: ***menugroup=options ***POP1 [->options] [empty]^C^C [empty]^C^C [~ It still loads, NOT visible: Command: ; error: Automation Error. Invalid argument options in Item Quote
wizman Posted May 6, 2009 Posted May 6, 2009 works fine here, try restarting acad, if still not ok, may be others can assist. Quote
rkmcswain Posted May 6, 2009 Posted May 6, 2009 See also this example: http://www.theswamp.org/index.php?topic=7731.msg98122#msg98122 Quote
MarcoW Posted May 6, 2009 Author Posted May 6, 2009 I have Autocad 2007, maybe that is important to know... The code: ; ; -- Function MeLoadPartMenu ; Loading partial menus. ; Arguments [Type]: ;Grp = Menu group [sTR] [b]SO Grp = options (?)[/b] ;Nme = Menu file name (w/o .ext) [sTR] [b]SO Nme = options.mnu (?)[/b] ; Return [Type]: ; > True if file found [bOOLEAN] ; > Nil if not [bOOLEAN] ; Notes: ; - Already loaded menu remains ; - Consider changed menu file paths ; (defun MeLoadPartMenu ([b]options[/b] options.mnu / AcaObj FilPth GrpCol MnuExt MnuLst) (setq AcaObj (vlax-get-acad-object) GrpCol (vla-get-MenuGroups AcaObj) MnuExt (< (atof (getvar "ACADVER")) 16.2) ".mnc" ".cui") ) (vlax-for Obj GrpCol (setq FilPth (strcase (vla-get-MenuFileName Obj)) MnuLst (cons (strcat (vl-filename-directory FilPth) "\\" (vl-filename-base FilPth) ) MnuLst ) ) (vlax-release-object Obj) ) (if (or (setq FilPth (findfile (strcat Nme MnuExt))) (setq FilPth (findfile (strcat Nme ".mnu"))) ) (progn (setq FilPth (strcat (vl-filename-directory FilPth) "\\" (vl-filename-base FilPth) ) ) (if (menugroup Grp) (if (not (member (strcase FilPth) MnuLst)) (progn (MeUnloadMenuGroup Grp) (vla-load (vla-get-MenuGroups AcaObj) Nme) ) ) (vla-load GrpCol Nme) ) T ) (alert (strcat "Menu file '" Nme MnuExt "/.mnu' not found." "\nCheck your installation please." ) ) ) ) ; ; -- Function MeUnloadPartMenu ; Unload a partial menu. ; Arguments [Type]: ; Grp = Menu group name [sTR] ; Return [Type]: ; > Null ; Notes: ; None ; (defun MeUnloadPartMenu (Grp) (vlax-for Obj (vla-get-MenuGroups (vlax-get-acad-object)) (if (eq (vla-get-Name Obj) Grp) (vla-unload Obj) ) (vlax-release-object Obj) ) (princ) ) How do I run this? I know how to get lisp running, this isn't lisp ? And when my menu is called options is it correct as altered above? Pff... I shall win !! Quote
Lee Mac Posted May 6, 2009 Posted May 6, 2009 This is LISP, but they are sub-functions, hence will need to be called from a main-function with arguments Quote
Lee Mac Posted May 6, 2009 Posted May 6, 2009 I think the LISP has been tampered with, some parts of it were wrong/missing: ; ; -- Function MeLoadPartMenu ; Loading partial menus. ; Arguments [Type]: ;Grp = Menu group [sTR] SO Grp = options (?) ;Nme = Menu file name ([color=Red][b]w/o .ext[/b][/color]) [sTR] SO Nme = options.mnu (?) ; Return [Type]: ; > True if file found [bOOLEAN] ; > Nil if not [bOOLEAN] ; Notes: ; - Already loaded menu remains ; - Consider changed menu file paths ; (defun MeLoadPartMenu ([b][color=Red]Grp Nme[/color][/b] / AcaObj FilPth GrpCol MnuExt MnuLst) (setq AcaObj (vlax-get-acad-object) GrpCol (vla-get-MenuGroups AcaObj) MnuExt [b][color=Red](if[/color][/b] (< (atof (getvar "ACADVER")) 16.2) ".mn[b][color=Red]u[/color][/b]" ".cui")) (vlax-for Obj GrpCol (setq FilPth (strcase (vla-get-MenuFileName Obj)) MnuLst (cons (strcat (vl-filename-directory FilPth) "\\" (vl-filename-base FilPth) ) MnuLst ) ) (vlax-release-object Obj) ) (if (or (setq FilPth (findfile (strcat Nme MnuExt))) (setq FilPth (findfile (strcat Nme ".mnu"))) ) (progn (setq FilPth (strcat (vl-filename-directory FilPth) "\\" (vl-filename-base FilPth) ) ) (if (menugroup Grp) (if (not (member (strcase FilPth) MnuLst)) (progn (MeUnloadMenuGroup Grp) (vla-load (vla-get-MenuGroups AcaObj) Nme) ) ) (vla-load GrpCol Nme) ) T ) (alert (strcat "Menu file '" Nme MnuExt "/.mnu' not found." "\nCheck your installation please.") ) ) ) ; ; -- Function MeUnloadPartMenu ; Unload a partial menu. ; Arguments [Type]: ; Grp = Menu group name [sTR] ; Return [Type]: ; > Null ; Notes: ; None ; (defun MeUnloadPartMenu (Grp) (vlax-for Obj (vla-get-MenuGroups (vlax-get-acad-object)) (if (eq (vla-get-Name Obj) Grp) (vla-unload Obj) ) (vlax-release-object Obj) ) (princ) ) [b][color=Red](defun c:test () (MeLoadPartMenu "options" "options") (princ))[/color][/b] This is what I think on first glance, but haven't had time to look properly tbh. Quote
MarcoW Posted May 6, 2009 Author Posted May 6, 2009 Hi Lee Mac, thank you for your help. Yes the lisp runs now, but the problem still is not solved. Aargh... Commandline: menuload [enter] Commandline: browse [enter] Browsing to the desired .mnu file [open] Then the browsed file is loaded by pressing the button "load". This way it is visible, not via the lisproutine allthough it is loaded. Beats me. Should I consider "leave it be" ? Quote
Lee Mac Posted May 6, 2009 Posted May 6, 2009 The LISP routine will only return T or the alert will show. I need to read the whole thread really - but whether you "leave it be" is entirely up to you Quote
Recommended Posts
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.