Private Sub Problems

Discussion in 'AutoCAD' started by rewilson, Mar 3, 2004.

  1. rewilson

    rewilson Guest

    Trying to fire a macro from a private sub when I open a drawing. Can this be done, and would someone help me?
    TIA :)
     
    rewilson, Mar 3, 2004
    #1
  2. rewilson

    Ben Guest

    Well.... the open event doesn't work like the other events. At least
    not if you want to do it right.

    In order to save you some needless headaches, are you wanting this to
    fire off when the drawing is opened, or when the window for that
    drawing is made active (through the window pull down)?

    Makes a sizeable difference in how to do it.

    Either way, let's help you out here.
     
    Ben, Mar 3, 2004
    #2
  3. rewilson

    rewilson Guest

    Thanks Ben. I can make it fire when the window becomes active. (AcadApplication_Activate). I need it to fire when I open the drawing, and that's a lot more complicated. I appreciate your help. I'm exporting data to a spreadsheet on open and close. Module1.drawingbegin needs to run on open. Module2.DrawingEnd runs from a Beginclose event in thisdrawing. Module2 works fine. Thanks again.
     
    rewilson, Mar 3, 2004
    #3
  4. rewilson

    Jeff Mishler Guest

    Nope, not than I'm aware.
    Change it to a public sub, or call it from another sub that is public,
    and have it run via the acaddoc.lsp file thusly: (vl-vbarun "pub_sub")

    Jeff

    this be done, and would someone help me?
     
    Jeff Mishler, Mar 3, 2004
    #4
  5. rewilson

    rewilson Guest

    Hey Jeff! How's it goin? You mean I can't use an endcommand event to do this? I felt like that was what had to happen and I just wasn't doing it right. I can run it from lisp with no problem if I have to do that. It just seemed that VBA would be a lot cleaner. So tell me this. If I do it from lisp, how would I very if the project was loaded? I can't come up with any way to check for the load, and skip the load if it is. So I get that wonderful little popup everytime I open a drawing. Thanks for the help (again)! :)
     
    rewilson, Mar 3, 2004
    #5
  6. rewilson

    rewilson Guest

    I missed the part of your post that said make it a public sub. I have tried that, but still couldn't get it to run on open. Can you show me how? Thanks.
     
    rewilson, Mar 4, 2004
    #6
  7. rewilson

    Jeff Mishler Guest

    OK, you CAN make it private. But you must do something like the help
    files show......

    A very simple acad.dvb would look like this, code is in the
    "ThisDrawing" module:

    Public WithEvents ACADApp As AcadApplication

    Sub Example_AcadApplication_Events()
    ' This example intializes the public variable (ACADApp) which will
    be used
    ' to intercept AcadApplication Events
    '
    ' The VBA WithEvents statement makes it possible to intercept an
    generic object
    ' with the events associated with that object.
    '
    ' Before you will be able to trigger any of the AcadApplication
    events,
    ' you will first need to run this procedure.

    ' We could get the application from the ThisDocument object, but
    that would
    ' require having a drawing open, so we grab it from the system.
    Set ACADApp = GetObject(, "AutoCAD.Application")
    End Sub

    Private Sub ACADApp_EndOpen(ByVal fName As String)
    'Do your file writing code here.....
    MsgBox "open works, " & fName & " is open....."

    End Sub

    AND you will need your "acad.rx" file to have "acadvba.arx" as the only
    line in it;

    AND you will need "(vl-vbarun "Example_AcadApplication_Events")" in your
    "acaddoc.lsp" file.

    With the above done, I do get a msgbox to pop up right after everything
    is done loading....

    HTH,
    Jeff

    tried that, but still couldn't get it to run on open. Can you show me
    how? Thanks.
     
    Jeff Mishler, Mar 4, 2004
    #7
  8. Is this any help?
    *****
    Private Sub AcadDocument_EndCommand(ByVal CommandName As String)
    If CommandName = "OPEN" Then
    Call Module.Procedure
    End If
    End Sub
    *****
    Regards Nathan
     
    Nathan Taylor, Mar 4, 2004
    #8
  9. rewilson

    Jeff Mishler Guest

    Well, cancel that.....

    It works on any drawing opened AFTER the first one. Will look at that
    tomorrow....

    Sorry,
    Jeff
     
    Jeff Mishler, Mar 4, 2004
    #9
  10. rewilson

    rewilson Guest

    Thanks Nathan. I've tried it, and though it seems like it should work, it does'nt. :)
     
    rewilson, Mar 4, 2004
    #10
  11. rewilson

    rewilson Guest

    That did it, Jeff. I just needed the example_acadapplication_events procedure to make it work. Jeff, you've done it again! Thanks for all your help.
     
    rewilson, Mar 4, 2004
    #11
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.