Calling Macros

Discussion in 'AutoCAD' started by Allen Johnson, May 25, 2004.

  1. 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
     
    Allen Johnson, May 25, 2004
    #1
  2. 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
     
    R. Robert Bell, May 26, 2004
    #2
  3. 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?
     
    Allen Johnson, May 26, 2004
    #3
  4. 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?
     
    R. Robert Bell, May 26, 2004
    #4
  5. But it still needs to be loaded somewhere.
     
    Allen Johnson, May 26, 2004
    #5
  6. 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?
     
    R. Robert Bell, May 26, 2004
    #6
  7. Right.
     
    Allen Johnson, May 26, 2004
    #7
  8. (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.
     
    Allen Johnson, May 27, 2004
    #8
  9. 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
     
    Nathan Taylor, May 28, 2004
    #9
Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.