Message 1 of 2
Saving Toolbars...

Not applicable
08-17-2005
09:47 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hi everyone, I'm having a bit a of a problem saving toolbars created with vba. I know this has come up in the past, but I couldn't find a solution searching the ng. When I shut down and restart, the toolbar is present, but the buttons are history. The toolbar would reappear after a restart up until I started fiddling with the bitmaps / adding icons.
There is also a problem with the macro. When the toolbar is created, the macro will not run. If I go in and edit a single character (ie- remove and replace the semi-colon at the end), then the macro runs fine.
I'm using 2004 mech dx, and I cannot use menus or profiles for reasons too long to explain. Could someone please take a glance at the code below and tell me what I'm missing.
Thanks,
-Josh
Option Explicit
Dim Mgroup As AutoCAD.AcadMenuGroup, Tbar As AutoCAD.AcadToolbar, _
Button As AutoCAD.AcadToolbarItem
Sub Setup()
'set up command strings for buttons
Dim Lay0 As String, LayDim As String, LayHid As String, LayPha As String
Dim LayCen As String, LayTxt As String, Pic As String, BigPic As String
Lay0 = "^C^C(defun c:lay0()(command " & Chr(34) & "-vbarun" & Chr(34) & Chr(32) & Chr(34) & _
"I:/SHARED/Engineering/Lisp/LayerGen.dvb!ObjectLayer" & Chr(34) & "));lay0;"
LayHid = "^C^C(defun c:layhid()(command " & Chr(34) & "-vbarun" & Chr(34) & Chr(32) & Chr(34) & _
"I:/SHARED/Engineering/Lisp/LayerGen.dvb!HiddenLayer" & Chr(34) & "));layhid;"
LayCen = "^C^C(defun c:laycen()(command " & Chr(34) & "-vbarun" & Chr(34) & Chr(32) & Chr(34) & _
"I:/SHARED/Engineering/Lisp/LayerGen.dvb!CenterLayer" & Chr(34) & "));laycen;"
LayPha = "^C^C(defun c:laypha()(command " & Chr(34) & "-vbarun" & Chr(34) & Chr(32) & Chr(34) & _
"I:/SHARED/Engineering/Lisp/LayerGen.dvb!PhantomLayer" & Chr(34) & "));laypha;"
LayTxt = "^C^C(defun c:laytxt()(command " & Chr(34) & "-vbarun" & Chr(34) & Chr(32) & Chr(34) & _
"I:/SHARED/Engineering/Lisp/LayerGen.dvb!TextLayer" & Chr(34) & "));laytxt;"
BigPic = "c:\program files\autodesk\acadm 2004 dx\support\big0lay.bmp"
'create a new toolbar in the menugroup
Set Mgroup = ThisDrawing.Application.MenuGroups.Item("amacad")
Set Tbar = Mgroup.Toolbars.Add("Ipsen Layers")
'add buttons
Set Button = Tbar.AddToolbarButton(1, "Object Layer", "Moves Selected Entities to Layer AM_0", Lay0)
Pic = "c:\program files\autodesk\acadm 2004 dx\support\0lay.bmp"
Button.SetBitmaps Pic, BigPic
Set Button = Tbar.AddToolbarButton(2, "Hidden Layer", "Moves Selected Entities to Layer AM_3", LayHid)
Pic = "c:\program files\autodesk\acadm 2004 dx\support\hidlay.bmp"
BigPic = "c:\program files\autodesk\acadm 2004 dx\support\bighidlay.bmp"
Button.SetBitmaps Pic, BigPic
Set Button = Tbar.AddToolbarButton(3, "Center Layer", "Moves Selected Entities to Layer AM_7", LayCen)
Pic = "c:\program files\autodesk\acadm 2004 dx\support\cenlay.bmp"
BigPic = "c:\program files\autodesk\acadm 2004 dx\support\bigcenlay.bmp"
Button.SetBitmaps Pic, BigPic
Set Button = Tbar.AddToolbarButton(4, "Phantom Layer", "Moves Selected Entities to Layer Am_11", LayPha)
Pic = "c:\program files\autodesk\acadm 2004 dx\support\phanlay.bmp"
BigPic = "c:\program files\autodesk\acadm 2004 dx\support\bigphanlay.bmp"
Button.SetBitmaps Pic, BigPic
Set Button = Tbar.AddToolbarButton(6, "Text Layer", "Moves Selected Entities to Layer Am_6", LayTxt)
Pic = "c:\program files\autodesk\acadm 2004 dx\support\txtlay.bmp"
BigPic = "c:\program files\autodesk\acadm 2004 dx\support\bigtxtlay.bmp"
Button.SetBitmaps Pic, BigPic
'save everything
Mgroup.Save acMenuFileSource
ThisDrawing.Application.Update
End Sub
There is also a problem with the macro. When the toolbar is created, the macro will not run. If I go in and edit a single character (ie- remove and replace the semi-colon at the end), then the macro runs fine.
I'm using 2004 mech dx, and I cannot use menus or profiles for reasons too long to explain. Could someone please take a glance at the code below and tell me what I'm missing.
Thanks,
-Josh
Option Explicit
Dim Mgroup As AutoCAD.AcadMenuGroup, Tbar As AutoCAD.AcadToolbar, _
Button As AutoCAD.AcadToolbarItem
Sub Setup()
'set up command strings for buttons
Dim Lay0 As String, LayDim As String, LayHid As String, LayPha As String
Dim LayCen As String, LayTxt As String, Pic As String, BigPic As String
Lay0 = "^C^C(defun c:lay0()(command " & Chr(34) & "-vbarun" & Chr(34) & Chr(32) & Chr(34) & _
"I:/SHARED/Engineering/Lisp/LayerGen.dvb!ObjectLayer" & Chr(34) & "));lay0;"
LayHid = "^C^C(defun c:layhid()(command " & Chr(34) & "-vbarun" & Chr(34) & Chr(32) & Chr(34) & _
"I:/SHARED/Engineering/Lisp/LayerGen.dvb!HiddenLayer" & Chr(34) & "));layhid;"
LayCen = "^C^C(defun c:laycen()(command " & Chr(34) & "-vbarun" & Chr(34) & Chr(32) & Chr(34) & _
"I:/SHARED/Engineering/Lisp/LayerGen.dvb!CenterLayer" & Chr(34) & "));laycen;"
LayPha = "^C^C(defun c:laypha()(command " & Chr(34) & "-vbarun" & Chr(34) & Chr(32) & Chr(34) & _
"I:/SHARED/Engineering/Lisp/LayerGen.dvb!PhantomLayer" & Chr(34) & "));laypha;"
LayTxt = "^C^C(defun c:laytxt()(command " & Chr(34) & "-vbarun" & Chr(34) & Chr(32) & Chr(34) & _
"I:/SHARED/Engineering/Lisp/LayerGen.dvb!TextLayer" & Chr(34) & "));laytxt;"
BigPic = "c:\program files\autodesk\acadm 2004 dx\support\big0lay.bmp"
'create a new toolbar in the menugroup
Set Mgroup = ThisDrawing.Application.MenuGroups.Item("amacad")
Set Tbar = Mgroup.Toolbars.Add("Ipsen Layers")
'add buttons
Set Button = Tbar.AddToolbarButton(1, "Object Layer", "Moves Selected Entities to Layer AM_0", Lay0)
Pic = "c:\program files\autodesk\acadm 2004 dx\support\0lay.bmp"
Button.SetBitmaps Pic, BigPic
Set Button = Tbar.AddToolbarButton(2, "Hidden Layer", "Moves Selected Entities to Layer AM_3", LayHid)
Pic = "c:\program files\autodesk\acadm 2004 dx\support\hidlay.bmp"
BigPic = "c:\program files\autodesk\acadm 2004 dx\support\bighidlay.bmp"
Button.SetBitmaps Pic, BigPic
Set Button = Tbar.AddToolbarButton(3, "Center Layer", "Moves Selected Entities to Layer AM_7", LayCen)
Pic = "c:\program files\autodesk\acadm 2004 dx\support\cenlay.bmp"
BigPic = "c:\program files\autodesk\acadm 2004 dx\support\bigcenlay.bmp"
Button.SetBitmaps Pic, BigPic
Set Button = Tbar.AddToolbarButton(4, "Phantom Layer", "Moves Selected Entities to Layer Am_11", LayPha)
Pic = "c:\program files\autodesk\acadm 2004 dx\support\phanlay.bmp"
BigPic = "c:\program files\autodesk\acadm 2004 dx\support\bigphanlay.bmp"
Button.SetBitmaps Pic, BigPic
Set Button = Tbar.AddToolbarButton(6, "Text Layer", "Moves Selected Entities to Layer Am_6", LayTxt)
Pic = "c:\program files\autodesk\acadm 2004 dx\support\txtlay.bmp"
BigPic = "c:\program files\autodesk\acadm 2004 dx\support\bigtxtlay.bmp"
Button.SetBitmaps Pic, BigPic
'save everything
Mgroup.Save acMenuFileSource
ThisDrawing.Application.Update
End Sub