Author Topic: Auto load menu  (Read 2045 times)

0 Members and 1 Guest are viewing this topic.

hudster

  • Gator
  • Posts: 2848
Auto load menu
« on: July 25, 2005, 09:47:59 AM »
The following lisp unloads our custom menu, deletes the mnr, mnt & mnc files, and then reloads the menu, we use this as a contractor here has his own version of 2004 and uses our menus.

It workes fine, but a recent server crash has shown a small problem with the way this code works, it ran as normal while the server was down, but couldn't re-load the menus, next time it ran it couldn't find the menu to unload and posts error messages saying menu not found, and it takes about 5 clicks to clear it each time, this happens till the menu is physically re-loaded.

What lisp commands do I have to look at to see if the menu is loaded, and if it isn't, automatically load it?

This would also help on computer setup, all that would be required is that the folder containing this acaddoc.lsp file, would have to be added to the support path and it would auto load the menus.

Cheers in advance for any help.

Code: [Select]
(vl-load-com)
(if (findfile "X:/AIDS/BLOCKS/RYBKA_BLOCKS/MENU/RYBKA.mnr")
  (vl-file-delete (findfile "X:/AIDS/BLOCKS/RYBKA_BLOCKS/MENU/RYBKA.mnr"))
)
(if (findfile "X:/AIDS/BLOCKS/RYBKA_BLOCKS/MENU/RYBKA.mnt")
  (vl-file-delete (findfile "X:/AIDS/BLOCKS/RYBKA_BLOCKS/MENU/RYBKA.mnt"))
)
(if (findfile "X:/AIDS/BLOCKS/RYBKA_BLOCKS/MENU/RYBKA.mnc")
  (vl-file-delete (findfile "X:/AIDS/BLOCKS/RYBKA_BLOCKS/MENU/RYBKA.mnc"))
)
    ;set the flag
(setq flag1 T)
    ;check if the menu is already loaded
(setq loaded (menugroup "RYBKA"))
    ;if it is not loaded
(if (= loaded nil)
    ;do the following
  (progn
    ;find the menu file
   (setq temp (findfile "X:/Aids/Blocks/Rybka_Blocks/Menu/RYBKA.MNS"))
    ;if you find the menu
   (if temp
    ;do the following
     (progn
    ;switch off dialogues
 (setvar "FILEDIA" 0)
    ;load the menu
 (command "menuload" "RYBKA")
    ;switch on dialogues
 (setvar "FILEDIA" 1)
    ;install the pulldown
(menucmd "Gacad.help=+RYBKA.RYBKA")
    ;inform the user
 (prompt "\nLoading RYBKA Menu....")
     )    ;progn
    ;menu not found, so do the following
     (progn
    ;inform the user
 (alert "Cannot Locate RYBKA Menu. \nRe-Run Install.")
    ;clear the flag
 (setq flag1 nil)
     )    ;progn
   )    ;if
  )    ;progn
  (progn
    ;Menu previously loaded so lets unload it now
    ;unload the menu
   (command "menuunload" "RYBKA")
    ;find the menu file
   (setq temp (findfile "X:/Aids/Blocks/Rybka_Blocks/Menu/RYBKA.MNS"))
    ;if you find the menu
   (if temp
    ;do the following
     (progn
    ;switch off dialogues
 (setvar "FILEDIA" 0)
    ;load the menu
(command "menuload" "X:/Aids/Blocks/Rybka_Blocks/Menu/RYBKA.MNS")
    ;switch on dialogues
 (setvar "FILEDIA" 1)
    ;install the pulldown
 (menucmd "Gacad.help=+RYBKA.RYBKA")
    ;inform the user
 (prompt "\nLoading Users blocks Menu....")
     )    ;progn
    ;menu not found, so do the following
     (progn
    ;inform the user
 (alert
   "Cannot Locate RYBKA Menu.
\nRe-Run Install."
 )
    ;clear the flag
 (setq flag1 nil)
     )    ;progn
   )    ;if found
  )    ;progn
)    ;if loaded
Revit BDS 2017, 2016, 2015, 2014, AutoCAD 2017, 2016, Navisworks 2017, 2016, BIM360 Glue

ronjonp

  • Needs a day job
  • Posts: 7529
Auto load menu
« Reply #1 on: July 25, 2005, 11:25:53 AM »
If you put this piece of code in your mnl file it will create the search paths you specifiy:


Code: [Select]
(defun addpaths (/ files expaths newpath)

  (setq files (vla-get-files (vla-get-preferences (vlax-get-acad-object)))
expaths (vla-get-supportpath files)
  )

  (setq newpath (strcat
 expaths
 ";"
 "C:\\Some Path\\Here"
 ";"
 "C:\\Some Path\\Here"
 ";"
 "C:\\Some Path\\Here"
 ";"
 "C:\\Some Path\\Here"
      )
    )
  (vla-put-supportpath files newpath)
(princ)
)
(addpaths)


I use this to check if the menu is loaded, if not load it:


Code: [Select]
(if (not (menugroup "MENUNAME"))
  (progn
    (command "menuload" "C:\\Program Files\\..\\MENUNAME")
    (menucmd "p30=+MENUNAME.MENUNAME")
    )
  )

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

hudster

  • Gator
  • Posts: 2848
Auto load menu
« Reply #2 on: July 25, 2005, 11:45:15 AM »
Thanks ronjonp that worked a treat, everything now works perfectly.
Revit BDS 2017, 2016, 2015, 2014, AutoCAD 2017, 2016, Navisworks 2017, 2016, BIM360 Glue

ronjonp

  • Needs a day job
  • Posts: 7529
Auto load menu
« Reply #3 on: July 25, 2005, 11:47:26 AM »
Glad to hear it.  :)

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC