Programming with events in VBA

Discussion in 'AutoCAD' started by fatorial, Mar 17, 2005.

  1. fatorial

    fatorial Guest

    How can I do to load a macro with events automatically? I maked a macro with beginsave event and this one only works if I write the code into AutoCAD Object folder in the IDE.

    This is the code:

    Private Sub AcadDocument_BeginSave(ByVal FileName As String)
    Call AutoDWF
    MsgBox "O DWF has create successful! "
    End Sub
    Public Sub AutoDWF()

    Dim objPlot As Object
    Set objPlot = ThisDrawing.Plot

    Dim blnRet As Boolean
    Dim sDWFFile As String
    Dim sPlotDriver As String
    sDWFFile = "c:\ari\Facility01.dwf"
    sPlotDriver = "c:\ari\DWF6 ePlot.pc3"
    blnRet = objPlot.PlotToFile(sDWFFile, sPlotDriver)
    End Sub

    thanks!
    Ari
     
    fatorial, Mar 17, 2005
    #1
  2. fatorial

    GTVic Guest

    I believe you could load the macro using LISP and put that LISP code in the AcadDoc.lsp file to load automatically with each drawing.
     
    GTVic, Mar 17, 2005
    #2
  3. Create a project called ACAD.DVB. In it, create a STARTUP sub. Next make
    sure that you have the dvb in a folder in your support path along with an
    ACSII text file named ACAD.RX that has one line of code:

    ACVBA.ARX - for 2004+
    ACADVBA - for 2000-2002

    When AutoCAD starts, it'll look for acad.rx which will initialize vba
    within AutoCAD. Next, AutoCAD will load the acad.dvb and run whatever is in
    the startup sub. For events, just include their programming as a part of
    acad.dvb and they will activate whwn the file loads.

    As for GTVic's comment, you could resort to lisp but why mix programming
    languages when you don't need to.

    -- Mike
    ___________________________
    Mike Tuersley
    ___________________________
    the trick is to realize that there is no spoon...
     
    Mike Tuersley, Mar 18, 2005
    #3
  4. fatorial

    Ed Jobe Guest

    One tiny correction Mike, the sub must be called ACADStartup (unless they
    changed it in 2006?).
     
    Ed Jobe, Mar 18, 2005
    #4
  5. Nope, it's still the same. Thanks for the correction, Ed! One of those,
    it's late and my mind is asleep posts.

    -- Mike
    ___________________________
    Mike Tuersley
    ___________________________
    the trick is to realize that there is no spoon...
     
    Mike Tuersley, Mar 18, 2005
    #5
  6. fatorial

    Ed Jobe Guest

    Don't ya just hate that? :) Keep up the good work!
     
    Ed Jobe, Mar 18, 2005
    #6
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.