Menuload Lisp Rotine Help

Menuload Lisp Rotine Help

ASCunningham
Collaborator Collaborator
2,120 Views
9 Replies
Message 1 of 10

Menuload Lisp Rotine Help

ASCunningham
Collaborator
Collaborator

I'm not very good at Lisp so I cannot figure out why this routine prompts me for a customization file. I think I have that already set but after starting AutoCAD you are prompted to enter a file name. Any help is much appreciated. Thanks

 

 

(defun find-menu-file (menu / mnuFile)
  (if (or (setq mnuFile (findfile (strcat menu ".cuix")))
      ); or
    mnuFile
  )
)
(if (setq mnuFile (find-menu-file "f:\\autocad\\ba-menu\\barton"))
      (command "menuload" mnuFile)
)

0 Likes
Accepted solutions (1)
2,121 Views
9 Replies
Replies (9)
Message 2 of 10

Anonymous
Not applicable

it probably cant find the given menu file

 

0 Likes
Message 3 of 10

ASCunningham
Collaborator
Collaborator

I'm prompted to enter a custom menu name. Shouldn't this already be set from the lisp routine

0 Likes
Message 4 of 10

ASCunningham
Collaborator
Collaborator

No it finds the menu and its loaded.

 

But its like the lisp routine is running again (repeating) itself. I don't think I have all the parentheses correct?

0 Likes
Message 5 of 10

john.uhden
Mentor
Mentor
(defun find-menu-file (menu / mnuFile)
  (if (or (setq mnuFile (findfile (strcat menu ".cuix")))
      ); or   OR WHAT?
    mnuFile
  )
)

Although if it is found, then the or is superfluous.

But I am still running only ACAD2002, where MENULOAD is looking for a .MNU file.

Is that the right command to load a .CUIX file also?

John F. Uhden

0 Likes
Message 6 of 10

ActivistInvestor
Mentor
Mentor

MENULOAD requires the path to a .cuix file.

 


@john.uhden wrote:
(defun find-menu-file (menu / mnuFile)
  (if (or (setq mnuFile (findfile (strcat menu ".cuix")))
      ); or   OR WHAT?
    mnuFile
  )
)

Although if it is found, then the or is superfluous.

But I am still running only ACAD2002, where MENULOAD is looking for a .MNU file.

Is that the right command to load a .CUIX file also?


 

0 Likes
Message 7 of 10

ActivistInvestor
Mentor
Mentor

@ASCunningham wrote:

No it finds the menu and its loaded.

 

But its like the lisp routine is running again (repeating) itself. I don't think I have all the parentheses correct?


If the .cuix file is already loaded, MENULOAD repeats the prompt.

 

Try this:

 

(defun menuload (filename / path)
   (if (setq path (findfile (setq path (strcat filename ".cuix"))))
      (progn
         (command "._MENULOAD" path)
         (if (eq (getvar "CMDNAMES") "MENULOAD")
            (command)
         )
      )
      (princ (strcat "\nError: Customization file " filename " not found."))
   )
)


0 Likes
Message 8 of 10

ASCunningham
Collaborator
Collaborator

Although the code doesn't have any error's when I run the routine, it doesn't load the menu if it's unloaded.

0 Likes
Message 9 of 10

ASCunningham
Collaborator
Collaborator
Accepted solution

After doing some reading this is what I found

 

The reason is that once a Menu is loaded into AutoCAD, AutoCAD remembers it and reloads it from then automatically. You need to check to see if it is loaded before attempting to load it again or the routine will crash. Use the (menugroup) function to check.

 

In bold below is what I had to add to keep the routine from crashing. I'm sure there is a cleaner way if anyone would like to chime in. Thanks for all the help 

 

(defun find-menu-file (menu / mnuFile)
  (if (or (setq mnuFile (findfile (strcat menu ".cuix")))
           ); or
    mnuFile
  )
)
(if (setq mnuFile (find-menu-file "f:\\autocad\\ba-menu\\barton"))
(if (not (menugroup "BA"))
      (command "menuload" mnuFile)
)
)

0 Likes
Message 10 of 10

ActivistInvestor
Mentor
Mentor

@ASCunningham wrote:

Although the code doesn't have any error's when I run the routine, it doesn't load the menu if it's unloaded.


Not true.

 

If you look at the code, you'll see that you can't include an extension.

 

If you call the function with only the name of the menu file, it loads the menu:

 

 


Command: (command "._MENUUNLOAD" "APPMANAGER") ._MENUUNLOAD Enter the name of a Customization Group to unload:APPMANAGER Customization file unloaded successfully. Customization Group: APPMANAGER Command: (menugroup "APPMANAGER") nil Command: (menuload "appmanager") ._MENULOAD Customization file loaded successfully. Customization Group: APPMANAGER

0 Likes