Author Topic: Checking drawings when opened  (Read 2903 times)

0 Members and 1 Guest are viewing this topic.

Kheilmann

  • Guest
Checking drawings when opened
« on: June 15, 2006, 12:17:16 PM »
I am testing each drawings that I open (actually there is no "on open" event, just an (Activate).  So...each time I open or switch to a dwg my code runs.
The code just searches for a block and either replaces it with the latest version or just updates the year.
It works great except when I have several dwgs open with several layouts in each dwg. 
I was trying to program a couple of flags but could not figure out how to get them to work...
1.  Once a dwg is opened to assign a temporary flag to that dwg so that it will not run the code each time I switch to that dwg.  all it will do is first check that flag and if True, exit sub, if false, continue.
2.  To put my code in an event that will only run when a dwg is first opened......

Any ideas or thoughts,

Thanks is advance...

David Hall

  • Automatic Duh Generator
  • King Gator
  • Posts: 4075
Re: Checking drawings when opened
« Reply #1 on: June 15, 2006, 12:23:49 PM »
how about updateing the dwg on Close?  Reason i ask is there is a close event.  Then it would only run once, as the dwg closes
Everyone has a photographic memory, Some just don't have film.
They say money can't buy happiness, but it can buy Bacon and that's a close second.
Sometimes the question is more important than the answer. (Thanks Kerry for reminding me)

Bob Wahr

  • Guest
Re: Checking drawings when opened
« Reply #2 on: June 15, 2006, 12:25:51 PM »
Here's the Wahr method of a DrawingOpen Event
Code: [Select]
Private Sub AcadDocument_BeginLisp(ByVal FirstLine As String)
If FirstLine = "s::startup" Then
  'The drawing was just opened
End If
End Sub

David Hall

  • Automatic Duh Generator
  • King Gator
  • Posts: 4075
Re: Checking drawings when opened
« Reply #3 on: June 15, 2006, 12:43:13 PM »
Good idea Bob.  Does that mean it looks for the file or the line where s::startup is?
Everyone has a photographic memory, Some just don't have film.
They say money can't buy happiness, but it can buy Bacon and that's a close second.
Sometimes the question is more important than the answer. (Thanks Kerry for reminding me)

Bob Wahr

  • Guest
Re: Checking drawings when opened
« Reply #4 on: June 15, 2006, 12:45:53 PM »
everytime a lisp runs it checks the first line of the lisp to see if it's s::startup or not.  I've had this running as a part of my "what the hell did I work on last week" dvb and haven't noticed any slowdown due to it running before that gets asked by someone.

David Hall

  • Automatic Duh Generator
  • King Gator
  • Posts: 4075
Re: Checking drawings when opened
« Reply #5 on: June 15, 2006, 12:47:32 PM »
very cool!!
Everyone has a photographic memory, Some just don't have film.
They say money can't buy happiness, but it can buy Bacon and that's a close second.
Sometimes the question is more important than the answer. (Thanks Kerry for reminding me)

Bryco

  • Water Moccasin
  • Posts: 1882
Re: Checking drawings when opened
« Reply #6 on: June 15, 2006, 11:48:20 PM »
Kheilmann, there are document level and application level events available.
The beginopen and endopen events are part of the latter.
Paste the following into  your thisdrawing module
Code: [Select]
Private WithEvents AutoCAD As AcadApplication

Public Sub Acadstartup()
  Set AutoCAD = Application
  AutoCAD.WindowState = acMax
  ThisDrawing.WindowState = acMax
End Sub
now clicking on AutocCAD in the object box you will see all the events available in the Procedure/Event Box (to its right).
Besides Bob's cool method I think you can also access the dwg attributes

Kheilmann

  • Guest
Re: Checking drawings when opened
« Reply #7 on: June 19, 2006, 08:54:23 AM »
Thanks Everyone for your input.
Bryco, I will try your method in a minute.

Bob,  Your method works great, except now my lsp files don't seem to load anymore after the first drawing.
SDI = 0
Acaddocaslsp = 1
I commented out the Begin_Lisp procedure and now my commands seem to load OK.
Does anyone know of any conflicts?
I tried moving everything in my Acad.lsp file to the acaddoc.lsp and still nothing loaded after the 1st dwg.

???

Kheilmann

  • Guest
Re: Checking drawings when opened
« Reply #8 on: June 19, 2006, 09:06:01 AM »
Bryco,  your method worked great.  Though I had to use the EndOpen event as opposed to the BeginOpen.