Thanks for the beer.
Now this is the tricky part.
Remember the VBA example calling for
a) Set ACADApp = GetObject(, "AutoCAD.Application")
and I told you to change it to
b) Set ACADApp = ThisDrawing.Application
Well, that was just for a quick test. The reason for whats happening is that
if you use a) the ACADApp will be set to the application object regardless
of the drawing (could be no drawing open at all)
if you use b) the ACADApp will depend on a current drawing being there.
So, you'll have to work this one out a little bit more.
I don´t use VBA for this sort of thing, I code in VB and create a DLL, but
that's another story.
--
Saludos, Ing. Jorge Jimenez, SICAD S.A., Costa Rica
"Brian Hailey" wrote in message
news:16F773F21742ABF859358A11F340350F@in.WebX.maYIadrTaRb...
> Ok, I have one more question (for now) Jorge.
>
> I placed the Call InitializeEvents directly in the ThisDrawing module
> without success but when I put it in a sub like this:
>
> Private Sub AcadDocument_Activate()
> Call InitializeEvents
> End Sub
>
> It did work, but not every time. Is there a better place to put this call
> so it will work even on the very first drawing?
>
> Thanks,
>
> Brian
>
> "Jorge Jimenez" wrote in message
> news:BAB278B38FC37EF367420722CEB26A64@in.WebX.maYIadrTaRb...
> > Hi Brian.
> > Well, now you have your class defined but it won´t run by itself.
> > You need to have a main module wich will call the InitializeEvents sub
> > For a quick test, dol the dim the X object and Call the initializeevents
> > inside of the "thisdrawing" module.
> > So it should initialize once you start a new drawing.
> >
> > --
> > Saludos, Ing. Jorge Jimenez, SICAD S.A., Costa Rica
> >
> > "Brian Hailey" wrote in message
> > news:5D5041B2EAED33C4BFD23D683B5BCF85@in.WebX.maYIadrTaRb...
> > > That didn't seem to help. In the help files under "Enabling
Application
> > > Level Events" is the following section:
> > >
> > > To connect the declared object to the Application object:
> > >
> > > 1.. In the Code window for your main module, add the following line
to
> > the
> > > declarations section:
> > > Dim X As New EventClassModule2.. In the same window, add the following
> > > subroutine:
> > > Sub InitializeEvents() Set X.App = ThisDrawing.ApplicationEnd
Sub3..
> In
> > > the code for your main module, add a call to the InitializeEvents
> > > subroutine:
> > > Call InitializeEventsOnce the InitializeEvents procedure has been run,
> the
> > > App object in the class module points to the Application object
> specified,
> > > and any event procedures in the class module will run when the events
> > occur.
> > >
> > >
> > >
> > > What does it mean by 3. "In the code for your main module, add a call
to
> > the
> > > InitializeEvents subroutine:"? What main module? The only module I
> have
> > is
> > > the class module. Do I need more code outside the class module? Does
> > this
> > > only work if VBA calls the open command? I've tried this on several
> > > computers in the office (both with LDD and vanilla) and I can't get it
> to
> > > work.
> > >
> > > Again, thanks for all the help, Jorge.
> > >
> > > Brian
> > >
> > > "Jorge Jimenez" wrote in
> message
> > > news:F83DC74F92128D36B238F329434550BA@in.WebX.maYIadrTaRb...
> > > > Try
> > > > Set ACADApp = ThisDrawing.Application
> > > >
> > > > instead of
> > > > Set ACADApp = GetObject(, "AutoCAD.Application")
> > > >
> > > >
> > > > --
> > > > Saludos, Ing. Jorge Jimenez, SICAD S.A., Costa Rica
> > > > "Brian Hailey" wrote in message
> > > > news:401C5A9F973AF5EF19FA1AC6A3EEE947@in.WebX.maYIadrTaRb...
> > > > > Here is exactly what I have in a class module (copied directly
from
> > the
> > > > help
> > > > > files):
> > > > >
> > > > > Public WithEvents ACADApp As AcadApplication ' Use with
> Application
> > > > Event
> > > > > Examples
> > > > > 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 FileName As String)
> > > > > ' This example intercepts an Application EndOpen event.
> > > > > '
> > > > > ' This event is triggered when AutoCAD finishes opening a
> drawing.
> > > > > '
> > > > > ' To trigger this example event:
> > > > > ' 1) Make sure to run the example that initializes
> > > > > ' the public variable (named ACADApp) linked to this
event.
> > > > > '
> > > > > ' 2) Use AutoCAD to open an existing drawing and wait
until
> > the
> > > > > ' operation finishes
> > > > > ' Use the "FileName" variable to determine which drawing file
is
> > > being
> > > > > opened
> > > > > MsgBox "A drawing was just loaded from: " & FileName
> > > > > End Sub
> > > > >
> > > > > What am I missing? Should this be placed in a different module?
Do
> I
> > > > need
> > > > > to do something else to activate it? Do I need to load any
specific
> > > > > references?
> > > > >
> > > > > Brian
> > > > >
> > > > >
> > > >
> > > >
> > >
> > >
> >
> >
>
>