December 2014

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 31      










« 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

    Try

      '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

      Application.MenuGroups.Load(cuifile)

      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

    Next


  End Sub

End Class

TrackBack

TrackBack URL for this entry:
http://www.typepad.com/services/trackback/6a00d83452464869e200d834f7b01969e2

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

blog comments powered by Disqus

Feed/Share

10 Random Posts