Is there a better method of calling macros? I wrote this routine to dynamically change the image of a toolbar button upon clicking it. But I'm having trouble getting the macro to run using VBA. Finally, I broke down and encoded this in the toolbar button macro: $M=$(if,$(eq,$(getvar,ucsfollow),1),UF0,UF1) added this to my .mnl file: (defun C:UF0 () (command "-vbarun" "Module1.ToggleUCSOff") (princ)) (defun C:UF1 () (command "-vbarun" "Module1.ToggleUCSOn") (princ)) and loaded the macro code (below) in the Appload Startup Suite: 'ThisDrawing.... Private Sub AcadDocument_Activate() ToggleUCSFollow Not ThisDrawing.ActiveViewport.UCSIconOn End Sub 'Module1.... Public Sub ToggleUCSOn() ToggleUCSFollow 1 End Sub Public Sub ToggleUCSOff() ToggleUCSFollow 0 End Sub Public Sub ToggleUCSFollow(val As Integer) Dim mngUCS As AcadMenuGroup Dim tbrUCS As AcadToolbar Dim Button As AcadToolbarItem Dim strSBN As String Dim strLBN As String Dim strHelp As String Set mngUCS = ThisDrawing.Application.MenuGroups("ACAD") Set tbrUCS = mngUCS.Toolbars("UCS II") Set Button = tbrUCS.Item(1) strSBN = IIf(val, "ucsfollowon.bmp", "ucsfollowoff.bmp") strHelp = IIf(val, "UCS Follow is On, Click to turn UCS Follow OFF", "UCS Follow is Off, Click to turn UCS Follow ON") strSBN = "F:\ACAD Shared\DWA Settings\MenuFiles\" & strSBN strLBN = strSBN Button.SetBitmaps strSBN, strLBN Button.HelpString = strHelp If Button.Name <> strHelp Then Button.Name = strHelp ThisDrawing.SetVariable "ucsfollow", val ActiveDocument.Utility.Prompt "UCSFollow is " & IIf(val, "On", "Off") End Sub
Check into (vla-LoadDVB), (vla-RunMacro), and (vl-VBARun). Search the ng here for more info on the pros/cons of the run functions. -- R. Robert Bell Is there a better method of calling macros? I wrote this routine to dynamically change the image of a toolbar button upon clicking it. But I'm having trouble getting the macro to run using VBA. Finally, I broke down and encoded this in the toolbar button macro: $M=$(if,$(eq,$(getvar,ucsfollow),1),UF0,UF1) added this to my .mnl file: (defun C:UF0 () (command "-vbarun" "Module1.ToggleUCSOff") (princ)) (defun C:UF1 () (command "-vbarun" "Module1.ToggleUCSOn") (princ)) and loaded the macro code (below) in the Appload Startup Suite: 'ThisDrawing.... Private Sub AcadDocument_Activate() ToggleUCSFollow Not ThisDrawing.ActiveViewport.UCSIconOn End Sub 'Module1.... Public Sub ToggleUCSOn() ToggleUCSFollow 1 End Sub Public Sub ToggleUCSOff() ToggleUCSFollow 0 End Sub Public Sub ToggleUCSFollow(val As Integer) Dim mngUCS As AcadMenuGroup Dim tbrUCS As AcadToolbar Dim Button As AcadToolbarItem Dim strSBN As String Dim strLBN As String Dim strHelp As String Set mngUCS = ThisDrawing.Application.MenuGroups("ACAD") Set tbrUCS = mngUCS.Toolbars("UCS II") Set Button = tbrUCS.Item(1) strSBN = IIf(val, "ucsfollowon.bmp", "ucsfollowoff.bmp") strHelp = IIf(val, "UCS Follow is On, Click to turn UCS Follow OFF", "UCS Follow is Off, Click to turn UCS Follow ON") strSBN = "F:\ACAD Shared\DWA Settings\MenuFiles\" & strSBN strLBN = strSBN Button.SetBitmaps strSBN, strLBN Button.HelpString = strHelp If Button.Name <> strHelp Then Button.Name = strHelp ThisDrawing.SetVariable "ucsfollow", val ActiveDocument.Utility.Prompt "UCSFollow is " & IIf(val, "On", "Off") End Sub
The only vl commands I find are (vl-vbaload filename) and (vl-vbarun macroname) . Either way, looks like I'll still need some lisp to run them, eh?
Yes, but you don't need to load the project via the Startup Suite if you use those functions. -- R. Robert Bell The only vl commands I find are (vl-vbaload filename) and (vl-vbarun macroname) . Either way, looks like I'll still need some lisp to run them, eh?
Those functions will let you load via code, not depending on if you added it somewhere. Think portability. What if you update/install a new station, and forget to add the .dvb to the Startup Suite. What if 90% of the AutoCAD sessions don't even need the project loaded?
(vl-vbarun ...) looks like a pretty hokey command. Have you ever run it with cmdecho on? Command: (vl-vbarun "ToggleUCSFollow.FOn") _.-VBARUN Macro name: ToggleUCSFollow.FOn UCSFollow is On Command: Command: "ToggleUCSFollow.FOn" Looks like nothing more than (command "-.vbarun" macroname) to me.
I find "command -vbarun" is fine for use with my programs that use forms but with my command line only programs all of the aforementioned methods have their own idiosyncrasies which I don't like. For these commands I now use the EditorCommand class of Tony Tanzillo's AcadX.Arx. http://mysite.verizon.net/~vze2vjds/acadx/classes/acadxeditorcommand.htm Regards - Nathan