drafter760 Posted July 16, 2010 Posted July 16, 2010 so I have a lisp file with about 50 lisp routines inside of it. what would be the most direct, (easiest), way to create an AutoCAD menu out of it? would it be a .cui, .cuix, .mnu or .mns? I have tried creating it through the cui editor, however this is far too cumbersome. I don't want to have to define 50 different commands in the cui, and then drag them onto a menu. I mean... they are already bundled together in one place, surely there is a way to import them somehow? Plus, I see no way to export these menus after they are created. Ultimately, I want to be able to just MENULOAD from any cad machine and pull the menu instantly form a thumb drive. Quote
irneb Posted May 12, 2011 Posted May 12, 2011 Sorry for this late post, but I'm actually also looking for something in this line. I've tried using the vla stuff to work with the CUI(x) files in 2008/11, but it doesn't seem to do anything. At present I've got a function which reads through the LSP file to find all the defuns: (vl-load-com) (defun LSP_GetDefuns (fn / f str lst n name args) (if (setq f (open fn "r")) (progn (while (setq str (read-line f)) (setq str (vl-string-left-trim " \t" str) name nil args nil) (if (wcmatch (strcase str) "(DEFUN*") (progn (setq str (vl-string->list (substr str 7))) (while (or (= (car str) 32) (= (car str) 9)) (setq str (cdr str))) (while (and (/= (car str) 32) (/= (car str) 9) (/= (car str) 40)) (setq name (cons (car str) name) str (cdr str) ) ) (while (or (= (car str) 32) (= (car str) 9) (= (car str) 40)) (setq str (cdr str))) (while (and (/= (car str) 41) (/= (car str) 47)) (setq args (cons (car str) args) str (cdr str) ) ) (setq lst (cons (cons (vl-list->string (reverse name)) (length (read (strcat "(" (vl-list->string (reverse args)) ")"))) ) lst ) ) ) ) ) (close f) (reverse lst) ) ) ) From this I get a list of all defun names + how many arguments each needs. A "simple" way of extracting only the commands is to do the following: (setq cmdLst (vl-remove-if-not '(lambda (item) (wcmatch item "C:*,c:*")) (mapcar 'car (LSP_GetDefuns "Path\\Lispfilename.LSP")) )) From there I then add these to an AutoLoad call in the MNL file of the menu. But where I get stuck is actually adding the command into the CUI. E.g. After I've obtained the MenuGroup item from the MenuGroups collection I try to add a new MenuItem into a Menu I know is already there: (setq acad (vlax-get-acad-object) Groups (vla-get-MenuGroups acad) MyGroup (vla-Item Groups "MyGroupName") MyPop (vla-Item (vla-get-Menus MyGroup) "MyPopName") ) (foreach cmd cmdLst (setq cmd (substr cmd 3)) (vla-AddMenuItem MyPop cmd cmd (strcat "^C^C" cmd)) ) I've stepped through it in VLIDE, no errors happen at any stage, and the last foreach returns vla objects for each time it runs the AddMenuItem method. But nothing gets displayed in that menu, and even when then editing through the CUI command nothing seems to be there. Am I missing something, or is this simply not possible through lisp? Apparently the Save & SaveAs methods of the menugroup object is discontinued since ACad 2006, so they do nothing at all: From the Developer Help: Menu groups cannot be saved in AutoCAD 2006 and later releases. This method will be removed from the MenuGroup object in a future release. Quote
Lee Mac Posted May 12, 2011 Posted May 12, 2011 Irne, I needed something similar a while back and came up with this - maybe it will help? (I used it for my AutoLoader program to generate autoload statements) Lee Quote
irneb Posted May 12, 2011 Posted May 12, 2011 Thanks Lee, yours would probably work better than mine (as mine reads nested defuns as well) - though I'm using my LSP_GetDefuns for more than just commands (also to get hold of how to call other "normal" defuns with arguments). But unfortunately that's not where I'm stuck, it's when I try to add the command into the CUI programatically. I am making a CUI from a huge quantity of LSP files and wanted some way of scripting at least the creation of the commands. I'll probably need to edit the CUI file itself through XML though, but since ADesk warns not to do that I was trying to use their methods. Quote
alanjt Posted May 12, 2011 Posted May 12, 2011 Thanks Lee, yours would probably work better than mine (as mine reads nested defuns as well) - though I'm using my LSP_GetDefuns for more than just commands (also to get hold of how to call other "normal" defuns with arguments). But unfortunately that's not where I'm stuck, it's when I try to add the command into the CUI programatically. I am making a CUI from a huge quantity of LSP files and wanted some way of scripting at least the creation of the commands. I'll probably need to edit the CUI file itself through XML though, but since ADesk warns not to do that I was trying to use their methods. Are you editing an existing CUI? If not, you could save yourself a lot of headaches and write to an MNU and load from there. Quote
irneb Posted May 12, 2011 Posted May 12, 2011 Yep, that's probably what I'll need to do! Just thought: "Why revert back? Why not do it all in one step?" Especially since this is for a running CUI which would get updated quite often from various sources - at present there seems to be about 10 new commands per day, disregarding the 100's of backlog. Hopefully not so much in the future though! Suppose I'll just have to go with the intermediate MNU and then Import into the CUI. If anyone's willing to share an old MNU making code I'd be extremely happy, otherwise I'll have to spend the weekend working on it. Quote
BIGAL Posted May 13, 2011 Posted May 13, 2011 This is an old ref but Lakose Visual lisp developers bible 2003.pdf has a section on making cui's which may help. 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.