VBA
Discuss AutoCAD ActiveX and VBA (Visual Basic for Applications) questions here.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Events question

18 REPLIES 18
Reply
Message 1 of 19
JeffatSJE
413 Views, 18 Replies

Events question

I am trying to update title block attributes when ever a file is saved or saved as. I have tried to use application level endsave and document level endsave events and they both work but they only work once. Then I have to run the initialize macro to get them to work again. I thought you only need to initialize them only once. If this is not the case then what do I need to do to keep the events active. I am using AutoCADE 2005
18 REPLIES 18
Message 2 of 19
Anonymous
in reply to: JeffatSJE

Wihout seeing your code it's hard to say, except for:
I would think you'd want to use the BeginSave event for the document......


--
Jeff
check out www.cadvault.com
wrote in message news:4810527@discussion.autodesk.com...
>I am trying to update title block attributes when ever a file is saved or
>saved as. I have tried to use application level endsave and document level
>endsave events and they both work but they only work once. Then I have to
>run the initialize macro to get them to work again. I thought you only need
>to initialize them only once. If this is not the case then what do I need
>to do to keep the events active. I am using AutoCADE 2005
Message 3 of 19
JeffatSJE
in reply to: JeffatSJE

Thanks for the quick reply. The code works but here it is anyway. Starting with the Acaddoc.lsp
(defun-q S::STARTUP ()
(command "_-vbarun" "initialize")
);end startup

Next Acad.rx
ACVBA.ARX

Next Acad.dvb
'main module code

Option Explicit
Dim Dx As New EventClassModule

Sub initialize()
Set Dx.Doc = ThisDrawing
End Sub

'eventclass module code
Public WithEvents Doc As AcadDocument

Private Sub Doc_EndSave(ByVal FileName As String)
' Update Titleblock Information
On Error GoTo errhere
Dim dwgname As String
dwgname = ThisDrawing.Name
If Len(FileName) > 0 And Right(FileName, 4) ".ac$" Then
If Right(FileName, 4) ".sv$" Then
Call UpdateATTRIBS(dwgname)
ThisDrawing.Regen acActiveViewport
End If
End If
errhere:
If Err 0 Then
MsgBox Err.Description & " Number " & Err.Number
End If
Err.Clear
End
End Sub

I tried the beginsave event it worked only for a save not save as, and only once. Its as if the eventclass module is defective. I commented out my call to updateattribs() and it still runs only once.
Message 4 of 19
Anonymous
in reply to: JeffatSJE

The EndSave event, as its name implies, fires *after* the
document has been saved, so if you want to update something
you need to use the BeginSave event.


As far as your event sourde being disconnected, that should
only occur if the variable that you've assigned the event source
object to was reassigned.


--
http://www.caddzone.com


AcadXTabs: MDI Document Tabs for AutoCAD 2004/2005/2006
http://www.acadxtabs.com


wrote in message news:4810527@discussion.autodesk.com...
> I am trying to update title block attributes when ever a file is saved or
saved as. I have tried to use application level endsave and document level
endsave events and they both work but they only work once. Then I have to
run the initialize macro to get them to work again. I thought you only need
to initialize them only once. If this is not the case then what do I need to
do to keep the events active. I am using AutoCADE 2005
Message 5 of 19
JeffatSJE
in reply to: JeffatSJE

After testing both BeginSave and EndSave I have come to the conclusion that they both occur during a save operation. But to get the new filename in a save as operation the EndSave is my best choice. Again the code works but it only works once.
Message 6 of 19
JeffatSJE
in reply to: JeffatSJE

Opps, After further review It looks like only one event in the eventclass module will run period. In otherwords if I remove the BeginSave sub the EndSave will run and if I remove the EndSave sub the BeginSave will run. Can you only have one event in an event class module?
Message 7 of 19
JeffatSJE
in reply to: JeffatSJE

This is worse than I thought I reinstalled AutoCAD E 2005 and I still had the same problem then out of desperation I reinstalled everything and it works. So there must be something in windows causing this problem. Further research required.
Message 8 of 19
JeffatSJE
in reply to: JeffatSJE

Well after further review and some excellent help from Steve at Autodesk, I have come to the conclusion that versions of vba 2005 and above no longer make standard modules visible for calls from acaddoc.lsp file. So I moved my subs and functions to the eventclass module and the initialize sub to the ThisDrawing code section and the events work now.

Thanks Again Steve K.
Message 9 of 19
Anonymous
in reply to: JeffatSJE

I think I had the same problem.
I change the properties of the Class Module: Instancing: 2-PublicNotCreatable and it works.
This is my code:
Class1:
Public WithEvents objApp As AcadApplication
Private Sub objApp_BeginSave(ByVal FileName As String)
MsgBox "hi"
End Sub

Module:
Dim clsEvents As New Class1
Sub InitializeEvents()
Set clsEvents.objApp = ThisDrawing.Application
End Sub
Public Sub KickIt()
Call InitializeEvents
'more to start
End Sub

Acad.lsp:
(command "_vbaload" "../sql_test.dvb")
(command "_vbarun" "kickit")

Flytofly... Marco
Message 10 of 19
JeffatSJE
in reply to: JeffatSJE

Wow It has been a couple of years since and I have been using the application I wrote flawlessly until I recently upgraded to AutoCAD Electrical 2008 64bit. I was having a problem getting it to work again. You may have just solved it. Unbelievable timing.
Thanks!!
Message 11 of 19
JeffatSJE
in reply to: JeffatSJE

Oops again. It is still broken. Even core AutoCAD breaks when my DVB loads. Has anyone else experienced problems with their event class module programs not running and the VBA IDE going modal? (64bit) see attached zipped up DVB file load it and see if AutoCAD will maximize after being minimized and VBA IDE opens Modal from the VBA manager.
Message 12 of 19
Anonymous
in reply to: JeffatSJE

I loaded your acad.dvd and it works welll.
I commented out the lines in doc_beginsave and uncommented your msbox command.
It worked well.
(AutoCAD 2008)


Greeting from Holland,
Marco
Message 13 of 19
JeffatSJE
in reply to: JeffatSJE

Thanks for testing it but was it a 64bit test?
Message 14 of 19
Ed.Jobe
in reply to: JeffatSJE

You said 64 bit. I assume you mean Visat? Does Vista support vba?
http://discussion.autodesk.com/thread.jspa?messageID=5512940

Ed


Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.
How to post your code.

EESignature

Message 15 of 19
JeffatSJE
in reply to: JeffatSJE

Windows XP pro 64bit OS and AutoCAD 2008 64bit. I am using AutoCAD Electrical 2008 64 bit.
Message 16 of 19
Anonymous
in reply to: JeffatSJE

Eeeuhhh, how can I see if its 64 bit??
Message 17 of 19
JeffatSJE
in reply to: JeffatSJE

Ha Ha I don't know other than the DVD saying 64 bit I guess we really don't know. The OS is easy just open windows explorer and select Help - About you should see your windows OS. I would expect the same from Autodesk. Doh!
Message 18 of 19
Anonymous
in reply to: JeffatSJE

ok, I don't have the x64 edition, just professional.
sorry.
Message 19 of 19
quancij
in reply to: JeffatSJE

Not sure this will be helpful... I am not a programmer...
From last year ADN member DevDays conference briefing on 64-bit...
When using VBA with 64 bit...

Must use ‘Handle’ or ‘ObjectId32’ instead of ‘ObjectId’

Recommend
AcadApplication.GetInterfaceObject( )
Instead of “ Dim someObject as New AcAnyObject”
Or
“Set someObject = New AcAnyObject”

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report

”Boost