TheSwamp

Code Red => AutoLISP (Vanilla / Visual) => Topic started by: Andrea on September 23, 2005, 01:34:11 PM

Title: how to detect menu ?
Post by: Andrea on September 23, 2005, 01:34:11 PM
a little simple question...

maybe i already know....but I can find a way.....

I would like to detect if a menu is loaded or not...
and display a toolbar..

any idea ?
Title: Re: how to detect menu ?
Post by: M-dub on September 23, 2005, 01:37:56 PM
menuload?

Simple enough...
Title: Re: how to detect menu ?
Post by: Andrea on September 23, 2005, 01:45:44 PM
sorry....i mean...in lisp..

eg:

(setq menulist ([list menu]))

or

(if ([Menu "X"]) (vl-cmdf "_-toolbar" "_s" "tb1"))

something like that.
Title: Re: how to detect menu ?
Post by: M-dub on September 23, 2005, 01:47:15 PM
Lisp, eh?  I think you should have posted this in the Lisp forum.  I'll move it.
Title: Re: how to detect menu ?
Post by: Andrea on September 23, 2005, 02:02:21 PM
ok....sorry, :?
Title: Re: how to detect menu ?
Post by: Crank on September 23, 2005, 02:12:46 PM
RTFM  :evil: :

VLISP-help > Menus property, example code

Code: [Select]
Sub Example_Menus()
    ' This example finds the names of all menus in the first menu group.
   
    Dim menuNames As String
    Dim menuCollection As AcadPopupMenus
    Dim menu As AcadPopupMenu
   
    Set menuCollection = ThisDrawing.Application.MenuGroups.Item(0).Menus
    menuNames = ""
    For Each menu In menuCollection
        menuNames = menuNames & menu.name & vbCrLf
    Next menu
    MsgBox menuNames
End Sub
Title: Re: how to detect menu ?
Post by: Andrea on September 23, 2005, 02:18:35 PM
Thanks Crank...
but I found a easier way..

(menugroup groupname)
Title: Re: how to detect menu ?
Post by: Crank on September 23, 2005, 02:28:35 PM
 :-)

Perhaps you can use this function from acadx.com :
Code: [Select]
(defun ax:ListToolbars (groupName / mGroups mGroup lst)
  (vl-load-com)
  (if (not
(vl-catch-all-error-p
  (setq
    mGroup (vl-catch-all-apply
     'vla-item
     (list (vla-get-menugroups (vlax-get-acad-object))
   groupName
     )
   )
  )
)
      )
    (vlax-for tBar (vla-get-toolbars mGroup)
      (setq lst (cons (vla-get-name tBar) lst))
    )
  )
)
Title: Re: how to detect menu ?
Post by: Crank on September 23, 2005, 02:35:14 PM
(to check if the toolbar still exists)
Title: Re: how to detect menu ?
Post by: Andrea on September 23, 2005, 02:46:29 PM
humm... :?

interresting.. thanks.

But how it work ?..
I can found a way to run the routine..
 :|
Title: Re: how to detect menu ?
Post by: Dommy2Hotty on September 23, 2005, 03:00:13 PM
Just for reference:

Code: [Select]
(if (menugroup "ase_partial")
(alert "ASE Partial Menu is loaded.")
(alert "Cannot find specified menu.")
)
Title: Re: how to detect menu ?
Post by: Andrea on September 23, 2005, 04:23:56 PM
Just for reference:

Code: [Select]
(if (menugroup "ase_partial")
(alert "ASE Partial Menu is loaded.")
(alert "Cannot find specified menu.")
)

I mean...Crank's routine..
Title: Re: how to detect menu ?
Post by: Dommy2Hotty on September 23, 2005, 04:28:35 PM
Just for reference:

Code: [Select]
(if (menugroup "ase_partial")
(alert "ASE Partial Menu is loaded.")
(alert "Cannot find specified menu.")
)

I mean...Crank's routine..

I know...just putting some other code out there for people to mull over...  :evil:
Title: Re: how to detect menu ?
Post by: Crank on September 23, 2005, 05:27:57 PM
The routine only returns a list of all toolbars in a menu.
If you want to check if the toolbar exists you'll have to do something like:
Code: [Select]
(if (member "toolbarname" (ax:listtoolbars "menuname"))
   (princ "\nToolbar exists")
   (princ "\nToolbar not present")
)

The menuname and toolbarname are not allways the same as displayed on screen in autocad. You must use the names given in the .mnu/.mns or .cui
Title: Re: how to detect menu ?
Post by: Jürg Menzi on September 24, 2005, 06:33:38 AM
For more functions around menus, visit my homepage -> 'Free Stuff' and search for:
VxGetLoadedMenus, VxUnLoadMenuGroup, VxGetPopups and VxGetToolbars
Title: Re: how to detect menu ?
Post by: Andrea on September 24, 2005, 10:27:55 PM
Hey Jürg ..

Interesting web site..

thanks