Through the Interface: Loading a partial CUI and making its toolbars visible through .NET

Kean Walmsley

May 2015

Sun Mon Tue Wed Thu Fri Sat
          1 2
3 4 5 6 7 8 9
10 11 12 13 14 15 16
17 18 19 20 21 22 23
24 25 26 27 28 29 30


« Blocking AutoCAD commands from .NET | Main | Controlling interactive polyline creation - Part 1 »

November 01, 2006

Loading a partial CUI and making its toolbars visible through .NET

A discussion in the comments on this previous entry seemed worthy of turning into a post.

The problem appears to be that when you load a partial CUI file into AutoCAD, by default the various resources (pull-down menus, toolbars) are not displayed.

This snippet of code shows you how to both load a CUI file into AutoCAD and then loop through the toolbars in your menu-group, making them all visible. You could extend it fairly easily to add the pull-down menus contained in the CUI by using mg.Menus.InsertMenuInMenuBar(). I'm choosing to leave that as an exercise for the reader mainly because the choice of where the various menus go can be quite specific to individual applications... toolbars are much simpler - we're just going to turn them all on. :-)

So here's the code... for convenience I wrote it in VB.NET, but it uses COM Interop to access the menu API in AutoCAD.

Imports Autodesk.AutoCAD.Runtime

Imports Autodesk.AutoCAD.ApplicationServices

Imports Autodesk.AutoCAD.Interop

Public Class ToolbarCmds

  <CommandMethod("LoadTBs")> _

  Public Sub LoadToolbars()

    Const cuiname As String = "mycuiname"

    Const cuifile As String = "c:\mycuifile.cui"

    Dim mg As AcadMenuGroup


      'Attempt to access our menugroup

      mg = Application.MenuGroups.Item(cuiname)

    Catch ex As System.Exception

      'Failure simply means we need to load the CUI first


      mg = Application.MenuGroups.Item(cuiname)

    End Try

    'Cycle through the toobars, setting them to visible

    Dim i As Integer

    For i = 0 To mg.Toolbars.Count - 1

      mg.Toolbars.Item(i).Visible = True


  End Sub

End Class


TrackBack URL for this entry:

Listed below are links to weblogs that reference Loading a partial CUI and making its toolbars visible through .NET:

blog comments powered by Disqus


10 Random Posts