Checking the status of a Toolbar using LISP or VBA

<?xml encoding=”UTF-8″>By Fenton Webb

Issue

How to check, at any time, whether a toolbar is shown or not, using either Visual LISP or VBA?

Solution

The following LISP and VBA code will tell you the current status of a specific toolbar.  To modify it, substitute the appropriate menugroup, toolbar name, and properties. 

LISP:

;;; For demonstration purposes only<br>;;; No error checking provided<br>(defun C:TBar_Chk()<br>   (vl-load-com)<br>   (setq oAcad (vlax-get-acad-object)<br>           oDoc (vla-get-activedocument oAcad)<br>           oMenuGrp (vla-item (vla-get-menugroups oAcad) "ACAD")<br>           oTBar (vla-item (vla-get-toolbars oMenuGrp) "Viewports")<br>           sTBarName (vlax-get-property oTBar 'name)<br>   )  <br>   (if (= (vlax-get-property oTBar 'visible) :vlax-true)<br>      (alert (strcat "Toolbar: " sTBarName "nStatus: Visible"))<br>      (alert (strcat "Toolbar: " sTBarName "nStatus: Hidden"))<br>   )<br>)<br>

VBA:

';;; For demonstration purposes only<br>';;; No error checking provided<br>Sub TBar_Chk()<br>    Dim oMenuGrp As AcadMenuGroup<br>    Dim oTBar As AcadToolbar<br>    Dim sTBarName As String<br>    Set oMenuGrp = ThisDrawing.Application.MenuGroups.Item("ACAD")<br>    Set oTBar = oMenuGrp.Toolbars.Item("Viewports")<br>    sTBarName = oTBar.Name<br>    If oTBar.Visible = True Then<br>        MsgBox "Toolbar: " + sTBarName + vbCr + "Status: Visible"<br>    Else<br>        MsgBox "Toolbar: " + sTBarName + vbCr + "Status: Hidden"<br>    End If<br>End Sub<br>


Comments

Leave a Reply

Discover more from Autodesk Developer Blog

Subscribe now to keep reading and get access to the full archive.

Continue reading