EndCommand

EndCommand

Anonymous
Not applicable
589 Views
12 Replies
Message 1 of 13

EndCommand

Anonymous
Not applicable
Hello everyone,

I'm almost done with the little program I'm writing. I've just run into a
small snag. Here's the situation: I want a macro to run each time a
drawing is opened. I've discovered the EndCommand routine and I can get it
to run great. The problem is, it was running even if the open command was
cancelled. I thought I had this figured out by using the BeginCommand event
to capture the drawing name and then comparing it it with the EndCommand to
see if a new drawing was actually opened. Worked great except if I reopen
the drawing I'm currently in. Does anyone know of a way to determine if the
open command actually opened a drawing or if the command was cancelled.

Thanks,

Brian
0 Likes
590 Views
12 Replies
Replies (12)
Message 2 of 13

Anonymous
Not applicable
Use the BeginOpen and EndOpen events of the application object.

--
Saludos, Ing. Jorge Jimenez, SICAD S.A., Costa Rica
"Brian Hailey" wrote in message
news:E35306A0618FB39B6984F2DCD9FD2E29@in.WebX.maYIadrTaRb...
> Hello everyone,
>
> I'm almost done with the little program I'm writing. I've just run into a
> small snag. Here's the situation: I want a macro to run each time a
> drawing is opened. I've discovered the EndCommand routine and I can get
it
> to run great. The problem is, it was running even if the open command was
> cancelled. I thought I had this figured out by using the BeginCommand
event
> to capture the drawing name and then comparing it it with the EndCommand
to
> see if a new drawing was actually opened. Worked great except if I reopen
> the drawing I'm currently in. Does anyone know of a way to determine if
the
> open command actually opened a drawing or if the command was cancelled.
>
> Thanks,
>
> Brian
>
>
0 Likes
Message 3 of 13

Anonymous
Not applicable
Thanks for the response, Jorge. I was under the impression that those
events, being an application level event, only fire when the application is
opened. Please correct me if I'm wrong.

Brian

"Jorge Jimenez" wrote in message
news:2A2207964B0FAA16F9A758F679FEF628@in.WebX.maYIadrTaRb...
> Use the BeginOpen and EndOpen events of the application object.
>
> --
> Saludos, Ing. Jorge Jimenez, SICAD S.A., Costa Rica
> "Brian Hailey" wrote in message
> news:E35306A0618FB39B6984F2DCD9FD2E29@in.WebX.maYIadrTaRb...
> > Hello everyone,
> >
> > I'm almost done with the little program I'm writing. I've just run into
a
> > small snag. Here's the situation: I want a macro to run each time a
> > drawing is opened. I've discovered the EndCommand routine and I can get
> it
> > to run great. The problem is, it was running even if the open command
was
> > cancelled. I thought I had this figured out by using the BeginCommand
> event
> > to capture the drawing name and then comparing it it with the EndCommand
> to
> > see if a new drawing was actually opened. Worked great except if I
reopen
> > the drawing I'm currently in. Does anyone know of a way to determine if
> the
> > open command actually opened a drawing or if the command was cancelled.
> >
> > Thanks,
> >
> > Brian
> >
> >
>
>
0 Likes
Message 4 of 13

Anonymous
Not applicable
The application object events "BeginOpen" and "EndOpen" will fire when you
open a document (drawing)
As a matter of fact, the argument for these two events is the "filename"
(dwg name) being openned.

--
Saludos, Ing. Jorge Jimenez, SICAD S.A., Costa Rica

"Brian Hailey" wrote in message
news:47A87F27AA398913C3A732245C237EAF@in.WebX.maYIadrTaRb...
> Thanks for the response, Jorge. I was under the impression that those
> events, being an application level event, only fire when the application
is
> opened. Please correct me if I'm wrong.
>
> Brian
>
> "Jorge Jimenez" wrote in message
> news:2A2207964B0FAA16F9A758F679FEF628@in.WebX.maYIadrTaRb...
> > Use the BeginOpen and EndOpen events of the application object.
> >
> > --
> > Saludos, Ing. Jorge Jimenez, SICAD S.A., Costa Rica
> > "Brian Hailey" wrote in message
> > news:E35306A0618FB39B6984F2DCD9FD2E29@in.WebX.maYIadrTaRb...
> > > Hello everyone,
> > >
> > > I'm almost done with the little program I'm writing. I've just run
into
> a
> > > small snag. Here's the situation: I want a macro to run each time a
> > > drawing is opened. I've discovered the EndCommand routine and I can
get
> > it
> > > to run great. The problem is, it was running even if the open command
> was
> > > cancelled. I thought I had this figured out by using the BeginCommand
> > event
> > > to capture the drawing name and then comparing it it with the
EndCommand
> > to
> > > see if a new drawing was actually opened. Worked great except if I
> reopen
> > > the drawing I'm currently in. Does anyone know of a way to determine
if
> > the
> > > open command actually opened a drawing or if the command was
cancelled.
> > >
> > > Thanks,
> > >
> > > Brian
> > >
> > >
> >
> >
>
>
0 Likes
Message 5 of 13

Anonymous
Not applicable
Thanks Jorge. I can't seem to get any of the application level events to
work on my computer though. I copy the example from the help file into a
class module, open a new drawing, and nothing. Do you know if I need to do
something different since I'm using LDD 2i? Or am I missing something else
completely?

Brian

"Jorge Jimenez" wrote in message
news:1BEB20D46DAF492B368D6106EDD9C08C@in.WebX.maYIadrTaRb...
> The application object events "BeginOpen" and "EndOpen" will fire when you
> open a document (drawing)
> As a matter of fact, the argument for these two events is the "filename"
> (dwg name) being openned.
>
> --
> Saludos, Ing. Jorge Jimenez, SICAD S.A., Costa Rica
>
> "Brian Hailey" wrote in message
> news:47A87F27AA398913C3A732245C237EAF@in.WebX.maYIadrTaRb...
> > Thanks for the response, Jorge. I was under the impression that those
> > events, being an application level event, only fire when the application
> is
> > opened. Please correct me if I'm wrong.
> >
> > Brian
> >
> > "Jorge Jimenez" wrote in
message
> > news:2A2207964B0FAA16F9A758F679FEF628@in.WebX.maYIadrTaRb...
> > > Use the BeginOpen and EndOpen events of the application object.
> > >
> > > --
> > > Saludos, Ing. Jorge Jimenez, SICAD S.A., Costa Rica
> > > "Brian Hailey" wrote in message
> > > news:E35306A0618FB39B6984F2DCD9FD2E29@in.WebX.maYIadrTaRb...
> > > > Hello everyone,
> > > >
> > > > I'm almost done with the little program I'm writing. I've just run
> into
> > a
> > > > small snag. Here's the situation: I want a macro to run each time
a
> > > > drawing is opened. I've discovered the EndCommand routine and I can
> get
> > > it
> > > > to run great. The problem is, it was running even if the open
command
> > was
> > > > cancelled. I thought I had this figured out by using the
BeginCommand
> > > event
> > > > to capture the drawing name and then comparing it it with the
> EndCommand
> > > to
> > > > see if a new drawing was actually opened. Worked great except if I
> > reopen
> > > > the drawing I'm currently in. Does anyone know of a way to
determine
> if
> > > the
> > > > open command actually opened a drawing or if the command was
> cancelled.
> > > >
> > > > Thanks,
> > > >
> > > > Brian
> > > >
> > > >
> > >
> > >
> >
> >
>
>
0 Likes
Message 6 of 13

Anonymous
Not applicable
if you're using VBA

first

dim withevents MiApp as AcadApplication

then

set MiApp = thisdrawing.application



--
Saludos, Ing. Jorge Jimenez, SICAD S.A., Costa Rica
"Brian Hailey" wrote in message
news:EAA2DE989CF278D3CFAF0FF1B9C3ADAE@in.WebX.maYIadrTaRb...
> Thanks Jorge. I can't seem to get any of the application level events to
> work on my computer though. I copy the example from the help file into a
> class module, open a new drawing, and nothing. Do you know if I need to
do
> something different since I'm using LDD 2i? Or am I missing something
else
> completely?
>
> Brian
>
> "Jorge Jimenez" wrote in message
> news:1BEB20D46DAF492B368D6106EDD9C08C@in.WebX.maYIadrTaRb...
> > The application object events "BeginOpen" and "EndOpen" will fire when
you
> > open a document (drawing)
> > As a matter of fact, the argument for these two events is the
"filename"
> > (dwg name) being openned.
> >
> > --
> > Saludos, Ing. Jorge Jimenez, SICAD S.A., Costa Rica
> >
> > "Brian Hailey" wrote in message
> > news:47A87F27AA398913C3A732245C237EAF@in.WebX.maYIadrTaRb...
> > > Thanks for the response, Jorge. I was under the impression that those
> > > events, being an application level event, only fire when the
application
> > is
> > > opened. Please correct me if I'm wrong.
> > >
> > > Brian
> > >
> > > "Jorge Jimenez" wrote in
> message
> > > news:2A2207964B0FAA16F9A758F679FEF628@in.WebX.maYIadrTaRb...
> > > > Use the BeginOpen and EndOpen events of the application object.
> > > >
> > > > --
> > > > Saludos, Ing. Jorge Jimenez, SICAD S.A., Costa Rica
> > > > "Brian Hailey" wrote in message
> > > > news:E35306A0618FB39B6984F2DCD9FD2E29@in.WebX.maYIadrTaRb...
> > > > > Hello everyone,
> > > > >
> > > > > I'm almost done with the little program I'm writing. I've just
run
> > into
> > > a
> > > > > small snag. Here's the situation: I want a macro to run each
time
> a
> > > > > drawing is opened. I've discovered the EndCommand routine and I
can
> > get
> > > > it
> > > > > to run great. The problem is, it was running even if the open
> command
> > > was
> > > > > cancelled. I thought I had this figured out by using the
> BeginCommand
> > > > event
> > > > > to capture the drawing name and then comparing it it with the
> > EndCommand
> > > > to
> > > > > see if a new drawing was actually opened. Worked great except if
I
> > > reopen
> > > > > the drawing I'm currently in. Does anyone know of a way to
> determine
> > if
> > > > the
> > > > > open command actually opened a drawing or if the command was
> > cancelled.
> > > > >
> > > > > Thanks,
> > > > >
> > > > > Brian
> > > > >
> > > > >
> > > >
> > > >
> > >
> > >
> >
> >
>
>
0 Likes
Message 7 of 13

Anonymous
Not applicable
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
0 Likes
Message 8 of 13

Anonymous
Not applicable
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
>
>
0 Likes
Message 9 of 13

Anonymous
Not applicable
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
> >
> >
>
>
0 Likes
Message 10 of 13

Anonymous
Not applicable
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
> > >
> > >
> >
> >
>
>
0 Likes
Message 11 of 13

Anonymous
Not applicable
WHOOHOOO!!!! It works now!!!!

If you are ever in Northern Colorado, let me know and I'll buy you a beer!
Heck, I'll buy you a whole case!

Cheers,

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
>
0 Likes
Message 12 of 13

Anonymous
Not applicable
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
> > > >
> > > >
> > >
> > >
> >
> >
>
>
0 Likes
Message 13 of 13

Anonymous
Not applicable
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
> > > > >
> > > > >
> > > >
> > > >
> > >
> > >
> >
> >
>
>
0 Likes