Author Topic: App Events not working  (Read 9910 times)

0 Members and 1 Guest are viewing this topic.

ML

  • Guest
App Events not working
« on: July 11, 2007, 09:43:30 AM »

I have been having this problem for months but have not followed through with a post to get it resolved:

I have an acad.rx file; in there I tpyed acvba.arx, it looks like it is initializing VBA on startup however I can not get any app events to work

I have the class module created called Class1

Code: [Select]
Public WithEvents ACADApp As AcadApplication    ' Use with Application Event Examples

Sub Acad_Application_Events()

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

    ' You could get the application from the ThisDocument object, but that
    ' would require having a drawing open, so in this case it is grabbed from the system.
   
    Set ACADApp = GetObject(, "AutoCAD.Application.16.2")
   
End Sub

And a module to call it up

Code: [Select]
Sub ExposeAppEvents()

Dim AppEvents As Class1
 
Set AppEvents = New Class1

End Sub

Still nothing

Any suggestions?

Also, does anyone have a fairly simple App Event that I can use a test?

Thanks

Mark

Bryco

  • Water Moccasin
  • Posts: 1850
Re: App Events not working
« Reply #1 on: July 11, 2007, 10:38:12 AM »
1) Put this at the top of the thisdrawing module (thisdrwawing is a class module)
Code: [Select]
Private WithEvents AutoCAD As AcadApplication2) Put this in the thisdrawing module as well
Code: [Select]
Public Sub Acadstartup()
  Set AutoCAD = Application
  AutoCAD.WindowState = acMax
  ThisDrawing.WindowState = acMax
End Sub
3)In the thisdrawing module of your acad.dvb
Code: [Select]
Sub ACADStartup()
   Call AcadApplication.RunMacro("F:\Project startup2006.dvb!App_StartMacro")
End Sub
Place your path to the dvb you are loading.
4)At the top of your vbaide window there are 2 control boxes, the one on the left is called the object box.
It will probably say (General), if you click the arrow and select "AutoCAD", the pull down box on the right ("Procedure")  will have a listing of all the available application level apps.
Click on BeginOpen, and a sub of that name will appear, write MsgBox("opening") in there.

ML

  • Guest
Re: App Events not working
« Reply #2 on: July 11, 2007, 10:45:28 AM »

Bry

I failed to mention that all of the above is in my acad.dvb file

Mark

ML

  • Guest
Re: App Events not working
« Reply #3 on: July 11, 2007, 10:48:21 AM »


I could be wrong but it looks like you are grabbing the events from drawing level instead of from The system?

Mark

ML

  • Guest
Re: App Events not working
« Reply #4 on: July 11, 2007, 10:49:04 AM »

Which would require a drawing to be open   :-(

Jeff_M

  • King Gator
  • Posts: 3946
  • C3D user & customizer
Re: App Events not working
« Reply #5 on: July 11, 2007, 11:03:51 AM »
Hi Mark,
Attached is my acad.dvb that uses events. See if it helps what you want to do. This has code in it for LandDesktop specific items, but that part shouldn't run if LDT is not running.

Jeff

ML

  • Guest
Re: App Events not working
« Reply #6 on: July 11, 2007, 11:26:20 AM »


Cool Jeff

How are you calling it up?

THanks

Mark


ML

  • Guest
Re: App Events not working
« Reply #7 on: July 11, 2007, 11:46:26 AM »

Jeff

That is good stuff
The cool thing is that I use Land Desktop also but I am still a bit too new at it to really appreciate what you have done. It is certainly worth hanging onto.

In my acad.dvb file

I did a simple event:

Code: [Select]
Private Sub ACADApp_BeginSave(ByVal Filename As String)

Dim Filename As String

Filename = Test.dwg

MsgBox "Hello"

End Sub

When I press the save button, should I not at least get a simple message box?

Thank you

Mark

Jeff_M

  • King Gator
  • Posts: 3946
  • C3D user & customizer
Re: App Events not working
« Reply #8 on: July 11, 2007, 01:55:57 PM »
Hi Mark,
Not sure what's up, but the docs say the the BeginSave & EndSave events use the AcadApp, but the Examples for both use the AcadDocument....this works:
Code: [Select]
Private Sub ACADDocument_BeginSave(ByVal Filename As String)

'Filename = Test.dwg ''this will error since it's not a string

MsgBox "Hello"

End Sub

ML

  • Guest
Re: App Events not working
« Reply #9 on: July 11, 2007, 02:03:37 PM »

Well that is easily solved by

Dim Filenname as String

But the problem I am having is not really using document level events, it is using App level events  :-(

ML

  • Guest
Re: App Events not working
« Reply #10 on: July 11, 2007, 03:14:36 PM »

This came right from the help screen:

Code: [Select]
Private Sub AcadDocument_BeginPlot(ByVal DrawingName As String)
    ' This example intercepts a drawing BeginPlot event.
    '
    ' This event is triggered when a drawing receives a plot request.
    '
    ' To trigger this example event: Plot an open drawing

    ' Use the "DrawingName" variable to determine which drawing is about to plot
    MsgBox "A drawing has just received a request to plot for: " & DrawingName

End Sub

I literally copied and pasted the code in the event and still nothing   :-(

WHY?????????

Jeff_M

  • King Gator
  • Posts: 3946
  • C3D user & customizer
Re: App Events not working
« Reply #11 on: July 11, 2007, 03:32:14 PM »

Well that is easily solved by

Dim Filenname as String
Actually, FileName is already defined as a string in the arguments section...... the way you put in Test.dwg was not a string. Also, since the filename is supplied by Autocad, I'm not sure you want to be changing it in this event (I haven't tested that, just a thought).

Does anything in your acad.dvb get run? What about if you replace yours with mine (rename yours, place mine in the support path & restart acad)?

The Plot code works for me......when you start Acad, once it's fully loaded type VBAIDE. Is the acad.dvb there in the editor? If not, it's not loading...... if it is, could you post or email the dvb to me? miff AT sonic DOT net

ML

  • Guest
Re: App Events not working
« Reply #12 on: July 11, 2007, 03:49:38 PM »


Jeff

Mine is loading fine and all looks well but nothing is triggering?  :-(

If you can take a look, I would really appreciate it

DAM, hell do I attach file?

Thanks

Mark



ML

  • Guest
Re: App Events not working
« Reply #13 on: July 11, 2007, 03:50:29 PM »


Ok, it is attached to the last post

Thanks Jeff!

Jeff_M

  • King Gator
  • Posts: 3946
  • C3D user & customizer
Re: App Events not working
« Reply #14 on: July 11, 2007, 05:22:28 PM »
One last question, Mark. What Acad version are you using?