Author Topic: Help with error loading a PopUpMenu  (Read 6525 times)

0 Members and 1 Guest are viewing this topic.

A_LOTA_NOTA

  • Guest
Help with error loading a PopUpMenu
« on: October 10, 2007, 02:45:27 PM »
I have this in my "ACAD2006.lsp"

Code: [Select]
(load "C:/Drawings/LoadDynamicMenu.lsp")
(load "C:/Drawings/Menu.lsp")

Loading this file that I got off here
http://www.theswamp.org/index.php?topic=13477.0

Code: [Select]
;;;C:/Drawings/LoadDynamicMenu.lsp
(defun crpd:loadDynamicPopUpMenu (menulist / acadapp currmenugroup
  Doc menu newmenu return Submenu)
  (setvar "CMDECHO" 0)
  (vl-load-com)
  (setq AcadApp       (vlax-get-acad-object)
doc       (vla-get-ActiveDocument AcadApp)
currMenuGroup (vla-item (vla-get-menugroups
  (vla-get-application doc))"ACAD")
cmd       (lambda (x)
(strcat "\033\033\137" x "\040"))
  )
  (if (/= currMenuGroup nil)
    (progn
      (vlax-for menu (vla-get-menus currMenuGroup)
(if (equal (car menuList)
   (vla-get-namenomnemonic menu)
    )
  (setq return T)
  (setq return nil)
)
      )
      (if (= return nil)
(progn
  (setq newMenu (vla-add (vla-get-menus currMenuGroup)
(car menuList)
)
  )
  (foreach e (car (cdr menuList))
    (vla-addMenuItem
      newMenu
      (1+ (vla-get-count newMenu))
      (car e)
      (cmd (cdr e))
    )
  )
  (vla-insertInMenuBar
    newMenu
    (1+ (vla-get-count
(vla-get-menuBar AcadApp)
       )
    )
  )
)
(princ (strcat "error of type ohno " (car menuList) " menu is already loaded "))
      )
    )
  )
  (setvar "CMDECHO" 1)
  (princ)
)

& this file

Code: [Select]
;;;C:/Drawings/Menu.lsp
(crpd:loadDynamicPopUpMenu '("Test1" (("Test1-1" . "add command1")("Test1-2" . "add command2"))))

(crpd:loadDynamicPopUpMenu '("Test2"(("Test2-1" . "add command3")("Test2-2" . "add command4"))))

(crpd:loadDynamicPopUpMenu '("Test3"(("Test3-1" . "add command5")("test3-2" . "add command 6"))))

when I first start ACAD everything works fine, but when I open a drawing or start a new drawing I get this error.
"; error: Automation Error. Popup menu Test3 exists in the menu group"

I don't have the "Load acad.lsp with every drawing" box checked. So I'm confused as to why I get the error how to fix it.

Thanks for the help!



gile

  • Gator
  • Posts: 2514
  • Marseille, France
Re: Help with error loading a PopUpMenu
« Reply #1 on: October 10, 2007, 03:32:11 PM »
Hi,

With ACADLSPASDOC = 0, acad.lsp file is loaded only on starting AutoCAD, but acaddoc.lsp file is loaded on each new drawing whatever ACADLSPASDOC value.
Two files for to two behavior, so if I undersand your problem, you have to put your menu load expression in acad.lsp.
Speaking English as a French Frog

A_LOTA_NOTA

  • Guest
Re: Help with error loading a PopUpMenu
« Reply #2 on: October 10, 2007, 03:49:08 PM »
Hi,

With ACADLSPASDOC = 0, acad.lsp file is loaded only on starting AutoCAD, but acaddoc.lsp file is loaded on each new drawing whatever ACADLSPASDOC value.
Two files for to two behavior, so if I undersand your problem, you have to put your menu load expression in acad.lsp.

I do have it in the acad.lsp & ACADLSODOC = 0. That is why I'm confused to what is going on.

gile

  • Gator
  • Posts: 2514
  • Marseille, France
Re: Help with error loading a PopUpMenu
« Reply #3 on: October 10, 2007, 04:50:01 PM »
You said:
Quote
I have this in my "ACAD2006.lsp"
Not "acad.lsp", so I thaught the problem was comming from here.
Speaking English as a French Frog

A_LOTA_NOTA

  • Guest
Re: Help with error loading a PopUpMenu
« Reply #4 on: October 10, 2007, 04:56:06 PM »
You said:
Quote
I have this in my "ACAD2006.lsp"
Not "acad.lsp", so I thaught the problem was comming from here.
ACAD2006.lsp is the ACAD.lsp!

;;;    Note:
;;;            This file is normally loaded only once per AutoCAD session.
;;;            If you wish to have LISP code loaded into every document,
;;;            you should add your code to acaddoc.lsp.

gile

  • Gator
  • Posts: 2514
  • Marseille, France
Re: Help with error loading a PopUpMenu
« Reply #5 on: October 10, 2007, 05:34:43 PM »
Sorry I confuse  :oops:

And can't see any solution for yor problem.
Speaking English as a French Frog

A_LOTA_NOTA

  • Guest
Re: Help with error loading a PopUpMenu
« Reply #6 on: October 10, 2007, 08:25:27 PM »
Well thanks for the try! :-)

It's Alive!

  • Retired
  • Needs a day job
  • Posts: 8747
  • AKA Daniel
Re: Help with error loading a PopUpMenu
« Reply #7 on: October 11, 2007, 09:38:17 PM »
I changed a few things, let me know if this works for you

Code: [Select]
;;;-===-==-==-==-=-==-==-==-=-==-==-=-==-==-=-==-==-=-==-==-=-==-=-==-
;;; (crpd:loadDynamicPopUpMenu '("Mymenu"(("Do Command1" . "command1")("Do Command2" . "command2"))))
;;;-===-==-==-==-=-==-==-==-=-==-==-=-==-==-=-==-==-=-==-==-=-==-=-==-
(defun crpd:loaddynamicpopupmenu (menulist     /
                                  acadapp      cmd
                                  currmenugroup
                                  doc          loadedmenulist
                                  menu         newmenu
                                 )
  (vl-load-com)
  (setq acadapp        (vlax-get-acad-object)
        loadedmenulist '()
        doc            (vla-get-activedocument acadapp)
        currmenugroup  (vla-item (vla-get-menugroups
                                   (vla-get-application doc)
                                 )
                                 "ACAD"
                       )
        cmd            (lambda (x)
                         (strcat "\033\033\137" x "\040")
                       )
  )
  (if (/= currmenugroup nil)
    (progn
      (vlax-for menu (vla-get-menus currmenugroup)
        (setq loadedmenulist
               (cons
                 (vla-get-namenomnemonic menu)
                 loadedmenulist
               )
        )
      )
      (if (= (vl-position (car menulist) loadedmenulist) nil)
        (progn
          (setq newmenu (vla-add (vla-get-menus currmenugroup)
                                 (car menulist)
                        )
          )
          (foreach e (car (cdr menulist))
            (vla-addmenuitem
              newmenu
              (1+ (vla-get-count newmenu))
              (car e)
              (cmd (cdr e))
            )
          )
          (vla-insertinmenubar
            newmenu
            (1+ (vla-get-count
                  (vla-get-menubar acadapp)
                )
            )
          )
        )
        (princ (strcat "\nerror of type ohno "
                       (car menulist)
                       " menu is already loaded "
               )
        )
      )
    )
  )
  (princ)
)


A_LOTA_NOTA

  • Guest
Re: Help with error loading a PopUpMenu
« Reply #8 on: October 12, 2007, 11:55:49 AM »
works great!! Thanks for all the help!!  :-)

It's Alive!

  • Retired
  • Needs a day job
  • Posts: 8747
  • AKA Daniel
Re: Help with error loading a PopUpMenu
« Reply #9 on: October 12, 2007, 11:58:36 AM »
My pleasure  , thanks for exposing my flawed programming  :-o