VBA-created Toolbar disappears

VBA-created Toolbar disappears

Anonymous
Not applicable
415 Views
4 Replies
Message 1 of 5

VBA-created Toolbar disappears

Anonymous
Not applicable
I have a vba routine to create a macro-assigned toolbar . It creates the toolbar just fine, and the buttons work just fine. However, if I close AutoCAD, when I open AutoCAD again, the toolbar has disappeared. Can you see a probem with this bit of code? Dim objToolbar As AcadToolbar Set objToolbar= ThisDrawing.Application.MenuGroups("ACAD").Toolbars.Add("My Toolbar") Thanks a lot David
0 Likes
416 Views
4 Replies
Replies (4)
Message 2 of 5

Anonymous
Not applicable
I used to have that problem too. Got around it by making a custom menu file (also thru code) and loading it as follows: Public Const sCompany As String = "Jaypro Sports" Dim sFile As String sFile = Support_Path & sCo & ".mns" lFile = FreeFile Open sFile For Output As lFile Print #lFile, sMenu Close #lFile 'sMenu has the actual text of the menu Set acGroup = ThisDrawing.Application.MenuGroups Set acMenu = acGroup.Load(sFile) Set acToolBar = acMenu.Toolbars.item(sCompany) 'apply icons to buttons For i = 1 To UBound(sButtons, 2) Set acButton = acToolBar.item(sButtons(2, i)) acButton.SetBitmaps sButtons(3, i), sButtons(3, i) Next i 'apply icons to flyouts For i = 1 To UBound(sFlyouts, 1) 'first the flyout main button Set acToolBar = acMenu.Toolbars.item("zFly-" & sFlyouts(i, 2, 1)) For j = 1 To UBound(sFlyouts, 3) 'get out of loop at first empty string = last button If sFlyouts(i, 1, j) = "" Then Exit For 'then the individual buttons Set acButton = acToolBar.item(sFlyouts(i, 2, j)) acButton.SetBitmaps sFlyouts(i, 3, j), sFlyouts(i, 3, j) Next Next acMenu.Save acMenuFileCompiled HTH, Kevin "D Hartley" wrote in message news:4090eea1_3@newsprd01... > I have a vba routine to create a macro-assigned toolbar . It creates the > toolbar just fine, and the buttons work just fine. > However, if I close AutoCAD, when I open AutoCAD again, the toolbar has > disappeared. > > Can you see a probem with this bit of code? > > Dim objToolbar As AcadToolbar > Set objToolbar= ThisDrawing.Application.MenuGroups("ACAD").Toolbars.Add("My > Toolbar") > > Thanks a lot > David > >
0 Likes
Message 3 of 5

Anonymous
Not applicable
You need to save your menugroup otherwise the toolbar is dropped: ThisDrawing.Application.MenuGroups.Item(0). _ SaveAs "MyMenu.mnc", acMenuFileCompiled -- ___________________________ Mike Tuersley CADalyst's AutoCAD Clinic Rand IMAGINiT Technologies
0 Likes
Message 4 of 5

Anonymous
Not applicable
Kevin, For a while, the following approach worked after I created the toolbar ThisDrawing.Application.MenuGroups.Item(0).SaveAs "MyMenu.mnc",acMenuFileCompiled Sometimes the toolbar persists and sometimes not As far as your routine, I'm following this except for a couple of things, and I have a feeling these are questions to be scoffed at by an actual programmer, but regarding Print #lFile, sMenu > Close #lFile > 'sMenu has the actual text of the menu How do you get the actual text into sMenu- do you Print it line by line? Also How do you know what menu out of the available menus the user is using? Thanks, David
0 Likes
Message 5 of 5

Anonymous
Not applicable
> How do you get the actual text into sMenu- do you Print it line by line? Yes - ever since I wrote it initially I've been meaning to put it into a spreadsheet driven format or something easier to maintain from the code side, but it's been a back shelf project... Without overloading you (i hope) with miles of meaningless code, here's a starter: 'file header sMenu = "//" & vbCrLf & "// " & sCompany & vbCrLf & "//" & vbCrLf & _ "// " & sDiaTitle & " " & sVersion & " Menu" & vbCrLf & "// " & sVersion & _ vbCrLf & "//" & vbCrLf & vbCrLf 'title section sMenu = sMenu & "***MENUGROUP=" & UCase(sCo) & vbCrLf & vbCrLf 'toolbars section sMenu = sMenu & "***TOOLBARS" & vbCrLf & vbCrLf 'main toolbar sMenu = sMenu & "**TB_" & UCase(sCo) & vbCrLf & "ID_" & LCase(sCo) & _ " [_Toolbar(""" & sCompany & """, " _ & "_Floating, _Show, 240, 160, 1)]" & vbCrLf 'sButtons is an array populated from some spaghetti code of routines and bitmap names, etc. 'there are a lot of better ways to do this... 'add buttons For i = 1 To UBound(sButtons, 2) sMenu = sMenu & "ID_" & LCase(Part_From_Path(sButtons(3, i))) _ & Space(16 - Len(Part_From_Path(sButtons(3, i))) - 2) _ & "[_" & sButtons(0, i) & "(""" etc, etc > How do you know what menu out of the available menus the user is using? I don't assume anything - each time this runs it's running from scratch, in other words it's creating a toolbar from nothing either after uninstalling and reinstalling my app or for a brand new install. Since the user may have toolbars loaded from multiple menus, this was the cleanest way I could think of. Kevin "D Hartley" wrote in message news:40927e3e_2@newsprd01... > Kevin, > > For a while, the following approach worked after I created the toolbar > > ThisDrawing.Application.MenuGroups.Item(0).SaveAs > "MyMenu.mnc",acMenuFileCompiled > Sometimes the toolbar persists and sometimes not > > > > As far as your routine, > I'm following this except for a couple of things, and I have a feeling > these are questions to be scoffed at by an actual programmer, but > regarding > > Print #lFile, sMenu > > Close #lFile > > 'sMenu has the actual text of the menu > How do you get the actual text into sMenu- do you Print it line by line? > > Also > How do you know what menu out of the available menus the user is using? > > Thanks, > David > >
0 Likes