TheSwamp

Code Red => VB(A) => Topic started by: mlabell on September 03, 2008, 10:34:55 AM

Title: Close an AutoCAD Dialogue through VBA
Post by: mlabell 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.
Title: Re: Close an AutoCAD Dialogue through VBA
Post by: Atook 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
Title: Re: Close an AutoCAD Dialogue through VBA
Post by: mlabell 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?
Title: Re: Close an AutoCAD Dialogue through VBA
Post by: David Hall 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.
Title: Re: Close an AutoCAD Dialogue through VBA
Post by: David Hall on September 03, 2008, 10:50:52 AM
It means it breaks, or fails.
Title: Re: Close an AutoCAD Dialogue through VBA
Post by: David Hall 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.
Title: Re: Close an AutoCAD Dialogue through VBA
Post by: mlabell 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.
Title: Re: Close an AutoCAD Dialogue through VBA
Post by: David Hall 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.

Title: Re: Close an AutoCAD Dialogue through VBA
Post by: mlabell 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.
Title: Re: Close an AutoCAD Dialogue through VBA
Post by: rogue 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...
Title: Re: Close an AutoCAD Dialogue through VBA
Post by: mlabell 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.
Title: Re: Close an AutoCAD Dialogue through VBA
Post by: rogue 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 ...
Title: Re: Close an AutoCAD Dialogue through VBA
Post by: mlabell 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.
Title: Re: Close an AutoCAD Dialogue through VBA
Post by: Matt__W 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.
Title: Re: Close an AutoCAD Dialogue through VBA
Post by: mlabell 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.
Title: Re: Close an AutoCAD Dialogue through VBA
Post by: Matt__W on September 08, 2008, 11:17:13 AM
Any idea how to turn off the dialogue that pops up the "You are opening a drawing with custom MEP objects?"

Isn't there a toggle to "not show again"?  If there is, check it once and you should be all set.
Title: Re: Close an AutoCAD Dialogue through VBA
Post by: mlabell on September 08, 2008, 11:58:00 AM
Completely correct, but I could never guess as to what every single machine in our entire corporation is set at on the display of that dialogue.  Default is on, and most people probably havent checked the "Don't display again".  There should be a variable for that dialogue it would seem, since everything else is that way...
Title: Re: Close an AutoCAD Dialogue through VBA
Post by: Matt__W on September 08, 2008, 12:29:08 PM
Completely correct, but I could never guess as to what every single machine in our entire corporation is set at on the display of that dialogue.  Default is on, and most people probably havent checked the "Don't display again".  There should be a variable for that dialogue it would seem, since everything else is that way...
I believe there's a registry key for that.

You might also want to look into AECFILEOPENMESSAGE.
Title: Re: Close an AutoCAD Dialogue through VBA
Post by: mlabell on September 08, 2008, 02:04:03 PM
Right before you posted
Quote
I believe there's a registry key for that.
I started hacking the registry...

Here is my findings...
Registry value for MEP...
[HKEY_CURRENT_USER\Software\Autodesk\AutoCAD\R17.1\ACAD-6001:409\AEC\5.5\AecbBldSrv55\Preferences] "HideAecbWarningFlags" and set the key to 2
Registry value for C3D (I am making an assumption on this part, since I havent found a drawing with civil 3d objects to completely test...)
[HKEY_CURRENT_USER\Software\Autodesk\AutoCAD\R17.1\ACAD-6001:409\AEC\5.5\AeccvBase50\Preferences] "HideAeccvWarningFlags" and set the key to 2
Now I need to integrate this into the code, which shouldn't be too hard. 
Title: Re: Close an AutoCAD Dialogue through VBA
Post by: JohnF on September 08, 2008, 06:37:16 PM
What about using the API to loop through the Window Caption names of the ones that are open and close any Windows that cause problems?

I have done this before and if I remember correctly it is the "GetWindowTextA".

This is the Declare:

Declare Function GetWindowText Lib "user32" Alias "GetWindowTextA" (ByVal hWnd As Long, ByVal lpString As String, ByVal cch As Long) As Long

Now i'm no API expert and there are plenty on this forum however this may trigger a better solution.