Author Topic: Close an AutoCAD Dialogue through VBA  (Read 9052 times)

0 Members and 1 Guest are viewing this topic.

mlabell

  • Guest
Close an AutoCAD Dialogue through VBA
« on: September 03, 2008, 10:34:55 AM »
I am in the process of writing a routine to clean drawings that come from an outside source. What is happening is every once and awhile I will come across a drawing that is unstable and throws up the AutoCAD "Program Errors were detected. Recommend that you save your work and restart the program." Is there any way to prevent this in VBA from coming up, or is there a way to close it in VBA? Here is a snippet of the code that I have written.
Code: [Select]
Sub dwgclean()
  Set objFSO = New FileSystemObject
  Set objFolder = objFSO.GetFolder(Me.txtFolderSource.Text)
  For Each objFile In objFolder.Files
     If objFile.Type = "AutoCAD Drawing" Then
     WholeFile = Me.txtFolderSource.Text & "\" & objFile.Name
     AutoCAD.AcadApplication.Documents.Open WholeFile
        ThisDrawing.PurgeAll
        ThisDrawing.PurgeAll
        ThisDrawing.PurgeAll
        ThisDrawing.PurgeAll
        ThisDrawing.SendCommand ("-purge r *" & vbCr & "n" & vbCr)
        ThisDrawing.AuditInfo True
        RemoveLayerFilters
        DeletePageSetups
        DeleteScaleList
        ThisDrawing.AuditInfo True
        ThisDrawing.SaveAs Me.txtFolderdestination.Text & "\" & objFile.Name
        ThisDrawing.Close
     End If
   Next
   deletebackup
End Sub

I have already tried the "nomutt", "expert", and "filedia" system variables with no help. If you need a drawing example let me know, and I will send it via email. Almost 10Mb...  What would be ideal if I could somehow mimic the scriptpro ability to close dialogues.

Atook

  • Swamp Rat
  • Posts: 1027
  • AKA Tim
Re: Close an AutoCAD Dialogue through VBA
« Reply #1 on: September 03, 2008, 10:43:32 AM »
You may be able to use 'On Error Resume Next' if you know what line is causing the problem. If the problem isn't in VBA though, it may not work.

Example..
        ...
        ThisDrawing.PurgeAll
        On Error Resume Next
             ThisDrawing.SendCommand ("-purge r *" & vbCr & "n" & vbCr) '<-chucks a wobbly
        On Error Goto 0
        ThisDrawing.AuditInfo True

mlabell

  • Guest
Re: Close an AutoCAD Dialogue through VBA
« Reply #2 on: September 03, 2008, 10:49:29 AM »
Yeah it is a standard AutoCAD message when you audit a drawing that is unstable.  I also tried running a recover from vba but message still came up...

Also what does "chucks a wobbly" mean?

David Hall

  • Automatic Duh Generator
  • King Gator
  • Posts: 4075
Re: Close an AutoCAD Dialogue through VBA
« Reply #3 on: September 03, 2008, 10:50:11 AM »
I use a script to process outside drawings.  That way if it crashes like yours, I can see where it stopped.  I still use VBA to clean it up though.
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)

David Hall

  • Automatic Duh Generator
  • King Gator
  • Posts: 4075
Re: Close an AutoCAD Dialogue through VBA
« Reply #4 on: September 03, 2008, 10:50:52 AM »
It means it breaks, or fails.
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)

David Hall

  • Automatic Duh Generator
  • King Gator
  • Posts: 4075
Re: Close an AutoCAD Dialogue through VBA
« Reply #5 on: September 03, 2008, 10:53:48 AM »
From Aussie English for Beginners
Quote
- "chuck a wobbly", means to have a tantrum or lose your temper.
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)

mlabell

  • Guest
Re: Close an AutoCAD Dialogue through VBA
« Reply #6 on: September 03, 2008, 10:55:24 AM »
Script works but not like the entire VBA.  The code that I dont have posted copies an entire directory, nukes any nasty file types, and brings forward the stuff we care about putting on our servers.  There is also a bunch if other stuff that is done as well that could never be done through script that is part of the overall application that I am creating.  The final product will be an audit routine that checks layers and standards conformation...

I guess the overall problem here is that the routine isnt crashing, it is pausing for input.  Which is what I dont want since I am processing an entire directory of drawings.

David Hall

  • Automatic Duh Generator
  • King Gator
  • Posts: 4075
Re: Close an AutoCAD Dialogue through VBA
« Reply #7 on: September 03, 2008, 11:48:53 AM »
Im doing the same thing, what I meant was call your vba from a script, so that if it crashes, you can see where it stopped. I realize crash is the wrong word, but you know what I mean.  I have a very similiar program I use to check what comes from consultants, runs an audit, purges, checks layer, linetypes, fonts, dims etc.

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)

mlabell

  • Guest
Re: Close an AutoCAD Dialogue through VBA
« Reply #8 on: September 03, 2008, 01:07:11 PM »
But the dialogue isnt a result of the VBA code having an error, it is a result of the drawing database being corrupt and AutoCAD 2008 now has a way to warn the user that the database is corrupt instead of crashing later expectedly.  If you were to run an AutoCAD script to audit the drawing it would throw up the same error.  It happens every day here with users since we run an audit of drawings every time they are open.

rogue

  • Guest
Re: Close an AutoCAD Dialogue through VBA
« Reply #9 on: September 05, 2008, 06:13:56 AM »
well, we meet again... I was monotoring your post in another forum, waiting to see if you'd upload a drawing with an error in it - so I can reproduce the dialog, and try writing code to close the window.

If you, or anyone else reading this, had a drawing that will generate the above dialog when checking for errors, pls upload it... so I can take a crack at coding for it...

mlabell

  • Guest
Re: Close an AutoCAD Dialogue through VBA
« Reply #10 on: September 05, 2008, 08:19:32 AM »
Well here is a small drawing,  I am glad I found one a little less in size and not confidential on top of that.  You are also going to get a two-fer and get the Non-DWG drawing display.  Have fun.  Throw the lisp file into your startup, and presto you will get the error.  Thanks in advance.

rogue

  • Guest
Re: Close an AutoCAD Dialogue through VBA
« Reply #11 on: September 05, 2008, 05:27:14 PM »
Well.... I took a quick look. And the dialog you showed in the attached image popped up.

But a couple of things came to mind while I was looking at it...
if you are already using VBA, why not do:

ThisDrawing.AuditInfo (True)
ThisDrawing.PurgeAll

No mess, no fuss (no dialogs)

But a second dialog occurs - maybe you dont see this one  in your install ... hee hee .. that may be your problem ...

mlabell

  • Guest
Re: Close an AutoCAD Dialogue through VBA
« Reply #12 on: September 08, 2008, 09:18:38 AM »
What ultimately gets rid of the Program errors detected box is getting rid of the second ThisDrawing.AuditInfo True that I have in the code. 
Quote
But a second dialog occurs - maybe you dont see this one  in your install ... hee hee .. that may be your problem ...
The dialogue you mentioned in your previous post was the ""NON-DWG" box I was reffering to in this post.
Quote
You are also going to get a two-fer and get the Non-DWG drawing display.
  Shoulda posted a picture to clarify :-o

I am still wondering if there is a way to load the scriptpro.lsp into the code so it supresses all dialogues that get displayed... that way I could just run and chug it.  When the entire debacle is done I will try to post the code, maybe to help others out there or to help those that have helped me.

Matt__W

  • Seagull
  • Posts: 12955
  • I like my water diluted.
Re: Close an AutoCAD Dialogue through VBA
« Reply #13 on: September 08, 2008, 09:57:23 AM »
Would changing the DWGCHECK sysvar be of any help?  You can get a prompt via the command line.  just throwin' in my $0.02.
Autodesk Expert Elite
Revit Subject Matter Expert (SME)
Owner/FAA sUAS Pilot @ http://skyviz.io

mlabell

  • Guest
Re: Close an AutoCAD Dialogue through VBA
« Reply #14 on: September 08, 2008, 10:13:42 AM »
Quote
Would changing the DWGCHECK sysvar be of any help?
Genius!  That worked great!  Any idea how to turn off the dialogue that pops up the "You are opening a drawing with custom MEP objects?"  I have the Civil 3d Object enabler, and MEP enablers installed.

**UPDATE**  "plquiet" is the system variable I was looking for to supress the dialogue.  Set it to 1 in the begininning of the code and and set it to 0 at the end of the code.  Of course this doesn't take care of the DWGcheck, and the Object enabler warning.
« Last Edit: September 08, 2008, 10:26:36 AM by mlabell »