Autocad 2005 events and VB6 and VB.NET

Discussion in 'AutoCAD' started by mrevelli, Aug 2, 2004.

  1. mrevelli

    mrevelli Guest

    Anyone can help me with an example how to use Autocad 2005 events in a VB6 active x dll that I call from lisp
    I have tried this but it doesn't work :
    Option Explicit
    Private WithEvents acadApp As AcadApplication
    Public Sub text()
    Set acadApp = GetObject(, "Autocad.Application.16")
    MsgBox "Test start" + acadApp.FullName
    End Sub
    Private Sub acadApp_BeginQuit(Cancel As Boolean)
    MsgBox "Test events"
    End Sub

    But in a vba routine it works.
    Also an example with VB.net .
    Thanks very much in advance
    Max
     
    mrevelli, Aug 2, 2004
    #1
  2. You have to call the rght object:

    Set acadApp = GetObject(, "Autocad.Application.16.1")

    -- Mike
    ___________________________
    Mike Tuersley
    CADalyst's CAD Clinic
    Rand IMAGINiT Technologies
    ___________________________
    the trick is to realize that there is no spoon...
     
    Mike Tuersley, Aug 2, 2004
    #2
  3. mrevelli

    mrevelli Guest

    Hi Mike,
    also with
    Set acadApp = GetObject(, "Autocad.Application.16.1")
    nothing to do.
    Isn't any examples or documentations how to correct implementate autocad events from vb6 activex dll or from vb.net.
    Thanks in advance.
    Max
     
    mrevelli, Aug 3, 2004
    #3
  4. Okay Max, I looked at your posted code and the problem is that you can't
    just MAKE an event reader by calling it as such. You have to tie into the
    application some how. Here is an example using VB.NET and the COM INTEROP.

    Start a new Windows Application with just a dialog box. To the dialog box,
    add a listbox named lstCommand and two buttons with their default names.
    Next add references to AutoCAD's COM library - Add Reference, COM tab,
    select . Then paste this code in and run it. For it to work, you'll need to
    pick your Button1 to start the monitoring process. From this you should be
    able to figure out what you need to do next.


    '========== BEGIN CODE BLOCK ================

    Imports System.Runtime.InteropServices
    Imports Autodesk.AutoCAD.Interop
    Imports System.Runtime.InteropServices.Marshal

    Private Sub OnAppBeginCmd(ByVal cmdName As String) _
    Handles m_AcadApp.BeginCommand
    With lstCommand
    .Items.Add(String.Concat("Begin Command: ", cmdName))
    .SelectedIndex = .Items.Count - 1
    End With
    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, _
    ByVal e As System.EventArgs) Handles Button1.Click
    Try
    m_AcadApp = GetActiveObject("AutoCAD.Application.16.1")
    Catch ex As Exception
    m_AcadApp = New AcadApplicationClass
    Finally
    m_AcadApp.Visible = True
    End Try
    Me.TopMost = True
    End Sub

    Private Sub Button2_Click(ByVal sender As System.Object, _
    ByVal e As System.EventArgs) Handles Button2.Click
    lstCommand.Items.Clear()
    End Sub

    '========== END CODE BLOCK ================

    -- Mike
    ___________________________
    Mike Tuersley
    CADalyst's CAD Clinic
    Rand IMAGINiT Technologies
    ___________________________
    the trick is to realize that there is no spoon...
     
    Mike Tuersley, Aug 3, 2004
    #4
  5. mrevelli

    mrevelli Guest

    That's OK
    Thank you Mike
    Max
     
    mrevelli, Aug 4, 2004
    #5
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.