guitarguy1685 Posted May 31, 2017 Posted May 31, 2017 I feel like I'm close but I don't quite understand of the looping lisps. I have a lisp that sets up our standards, including the Enterprise CUi that has about 6 custom Menus. The issue I have is that the Menu's are not displayed in the Menubar automatically. I've done some searching on the forums and found some stuff but I guess I don't quite understand what's happening. I'll post what I have so far and the samples I've seen. (vl-load-com) (defun C:menuload () (setq acadobject (vlax-get-acad-object) allGroups (vlax-get-property acadobj 'MenuGroups) ;as far as I can tell these are all loaded cui's CurMenuBar (vlax-get-property acadobj 'MenuBar) ;my current Menu display ) (Setq MyGroup (vla-item allGroups 2) ;I found that is is My menu, but I wont know this all the time. ;I want to step through all Menu groups until i find the one I want TestMenus (vlax-get-property MyGroup 'Menus) ;This grabs all Menus from My custom Menu Group MenuSteel (vla-item TestMenus 4) ;This finally gets the Menu Parent Name. I had to guess at this. ) (vla-InsertInMenuBar MenuSteel (1+ (vla-get-Count CurMenuBar))) ) ;This is the code that displays the menu in the Menubar. I need to loop this for all menus. I got this from acad help My questions 1) How to I step though the MenuGroups collection to retreive my menu? I have to admit, I'm very weak at looping functions (vlax-get-property (vla-item AllGroups [a number that needs to increment until I find my group]) 'Name) 2) can I use vlax-for (see below) to load every menu instead of multiple lines (vlax-for n TestMenus (vla-InsertInMenuBar [Menu Names] (1+ (vla-get-Count CurMenuBar)))) I based some of it off this http://www.cadtutor.net/forum/showthread.php?26379-about-load-CUI-file Quote
guitarguy1685 Posted May 31, 2017 Author Posted May 31, 2017 I'm closer still. I guess the "=" Is case sensitive. So now the program runs but doesn't set the menu name (setq count 0) (while (null (/= menu "MyMenuGroup")) (setq Menu (vlax-get-property (setq Mygroup (vla-item AllGroups (1+ count) )) 'Name))) [b][color="red"]0[/color][/b] [color="blue"][i] ;results from console[/i][/color] [b][color="red"]nil[/color][/b] [i][color="Blue"];results from console[/color][/i] I preset menu to "test" to check if it changed. It did not. Quote
guitarguy1685 Posted May 31, 2017 Author Posted May 31, 2017 It works!!!! This is what it must've been like to discover fire. I just had to increment the count after the expression was complete. (setq count 0) (while (null (= Menu "MyMenuGroup")) (setq Menu (vlax-get-property (setq Mygroup (vla-item AllGroups count )) 'Name)) (setq count (1+ count)) ) Not just to figure out the vlax-for to insert all my menus. Quote
guitarguy1685 Posted May 31, 2017 Author Posted May 31, 2017 This is as far as I could get. Help on the last part will be greatly appreciated (defun C:test () (setq acadobj (vlax-get-acad-object) allGroups (vlax-get-property acadobj 'MenuGroups) ;as far as I can tell these are all loaded cui's CurMenuBar (vlax-get-property acadobj 'MenuBar) ;my current Menu display ) (setq count 0) (while (null (= MyGroupName "MyMenuGroup")) (setq MyGroupName (vlax-get-property (setq Mygroup (vla-item AllGroups count )) 'Name)) (setq count (1+ count)) ) (setq MyGroupMenus (vlax-get-property MyGroup 'Menus)) (setq repeatNo (vlax-get-property MyGroupMenus 'Count)) (repeat repeatNo (setq count 0) (vla-InsertInMenuBar (vla-item MyGroupMenus count) (1+ (vla-get-Count (vla-get-MenuBar acadObj)))) [i][color="red"];I'm not sure what's happening with the 1+ bfore the vla-getcount[/color][/i] (setq count (1+ count)) ) ) This is the error I get ; error: Automation Error. Invalid argument index in InsertInMenuBar Quote
guitarguy1685 Posted June 1, 2017 Author Posted June 1, 2017 (edited) Well it took some time but I think I finally figured it out. Alot of help from reading other codes on this site as examples. Here is my finish product. Let me know if you see anything potentially bad. (vl-load-com) (defun C:test ( / acadobj AllGroups count GroupMenus GroupName GroupObj GroupPopMenu MenuBar) (setq acadobj (vlax-get-acad-object) ;retrieve acad object AllGroups (vlax-get-property acadobj 'MenuGroups) ;collection of all cuis loaded MenuBar (vlax-get-property acadobj 'MenuBar) ;Current Menubar display ) ;--------------search for desired Group---------------------------------------------------------- (if (menugroup "MyMenu") (progn (setq count 0) ;set counter (while ;step through Group collection until you find your desired group (null (= GroupName "MyMenu")) (setq GroupName (vlax-get-property (setq GroupObj (vla-item AllGroups count )) 'Name)) (setq count (1+ count)) );end while );end progn (alert "\nMyMenu.CUIX not loaded. Contact CAD Manager for help") );end if ;--------------load menus if they are not already loaded----------------------------------------- (setq GroupMenus (vlax-get-property GroupObj 'Menus) count 0) ;reset the counter (repeat (vlax-get-property GroupMenus 'Count) (setq GroupPopMenu (vla-item GroupMenus count)) (if (= (vlax-get-property GroupPopMenu 'OnMenuBar) :vlax-false) (progn (vla-InsertInMenuBar GroupPopMenu (1+ (vla-get-Count MenuBar))) (setq count (1+ count)) );end progn then (progn (princ (strcat "\n--- " (vlax-get-property GroupPopMenu 'Name) " Menu already placed on Menubar ---")) (setq count (1+ count)) );end progn else );end if );end repeat (princ) ;exit quietly ) I had to add a check if the PopMenu was already placed on the Menubar. Otherwise I got an error and my lisp failed. I'll clean up some of the sloppiness later. I was just excited to get it completed. *edit* Code cleaned up. I added a check to see if the required cuix is loaded. Edited June 1, 2017 by guitarguy1685 Cleaned up the Code. Quote
BIGAL Posted June 1, 2017 Posted June 1, 2017 Back to your 1st post try not to use your defun names C:menuload that match a command. Pretty sure I have had errors occur. And you are correct there are 52 characters in the english alphabet use strcase to get around the problem. Quote
guitarguy1685 Posted June 1, 2017 Author Posted June 1, 2017 Back to your 1st post try not to use your defun names C:menuload that match a command. Pretty sure I have had errors occur. You are correct. I fixed it a bit later. also, I should probably add a check if the menugroup even exists. Quote
Aftertouch Posted June 1, 2017 Posted June 1, 2017 Wont the CUILOAD function help you? This adds a CUI to your worksspace and adds all the menus to your current space. Quote
BIGAL Posted June 1, 2017 Posted June 1, 2017 Also be a little careful of adding CUI mnu etc to current work space we have a "No Save Current" in our user workspace so the guys don't screw it up. Quote
guitarguy1685 Posted June 1, 2017 Author Posted June 1, 2017 Wont the CUILOAD function help you?This adds a CUI to your worksspace and adds all the menus to your current space. The cui is set a Enterprise cui. So menus won't get placed on Menubar automatically. 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.