TheSwamp

Code Red => VB(A) => Topic started by: mikesmithfl on May 02, 2006, 02:48:45 PM

Title: ObjectDBX from AccessVBA - how do I close out acad.exe ?
Post by: mikesmithfl on May 02, 2006, 02:48:45 PM
Hi all:

Newbie with a question here.  I've been able to finally locate enough info to figure out how to read & change the summary info in dwg files from in Access w VBA & ObjectDBX, but when I clean up, either I can't get it to start up, or the acad.exe process is still hanging around.
Would someone pls clue me in on how to finish it off without needing user intervention?

If I do it like this,
Code: [Select]
   Dim objAcad As Object
   Dim dbxDoc As AxDbDocument
   Dim oSumInfo As AcadSummaryInfo
   Dim strDwgName As String
   
   strDwgName = "D:\Working\Doc_nums_and_logs\NewVersionOffice\Drawing1.dwg"
   
   Set objAcad = GetObject(, "AutoCAD.Application.16")
   Set dbxDoc = objAcad.GetInterfaceObject("ObjectDBX.AxDbDocument.16")
   
   dbxDoc.Open (strDwgName)
   Set oSumInfo = dbxDoc.SummaryInfo
 
   MsgBox "this is it before " & oSumInfo.Comments
   
   dbxDoc.SummaryInfo.Comments = "changed here by me again"
   dbxDoc.SaveAs (strDwgName)
   objAcad.Quit
   
   MsgBox "this is it after " & oSumInfo.Comments

objAcad.Quit

   Set oSumInfo = Nothing
   Set dbxDoc = Nothing
   Set objAcad = Nothing

Then it won't work without Autocad already being started.

If I do it like this, without the 'object' :

Code: [Select]
   Dim dbxDoc As AxDbDocument
   Dim oSumInfo As AcadSummaryInfo
   Dim strDwgName As String
   
   strDwgName = "D:\Working\Doc_nums_and_logs\NewVersionOffice\Drawing1.dwg"
   
   Set dbxDoc = GetInterfaceObject("ObjectDBX.AxDbDocument.16")
   
   dbxDoc.Open (strDwgName)
   Set oSumInfo = dbxDoc.SummaryInfo
 
   MsgBox "this is it before " & oSumInfo.Comments
   
   dbxDoc.SummaryInfo.Comments = "changed here by me again"
   dbxDoc.SaveAs (strDwgName)
   
   MsgBox "this is it after " & oSumInfo.Comments

   Set oSumInfo = Nothing
   Set dbxDoc = Nothing


Then it will start up OK without Autocad already being started, but it won't close correctly and keeps the acad.exe process active. (as far as I can tell)  But if I don't have an object to close, what do I do ?

Thanks for any clues, but the really blatant ones are appreciated even more ;)
Title: Re: ObjectDBX from AccessVBA - how do I close out acad.exe ?
Post by: Dnereb on May 02, 2006, 03:27:49 PM

 
Code: [Select]
  Set objAcad = GetObject(, "AutoCAD.Application.16") 

Then it won't work without Autocad already being started.


GetObject only ties to Get an existing object (Acad running)and raises an error if the object isn't there.
Somewhere in your code you have used on error resume next and didn't reset the error trapping afterwards (on error goto 0)
this is why your code runs but fails. Usually an attempt to create the object is made if Acad isn't running

Example code without good error trapping....

Code: [Select]
Sub test2()

Dim objAcad As Object

On Error Resume Next
Set objAcad = GetObject(, "AutoCAD.Application")
If Err.Number Then
    Set objAcad = CreateObject("Autocad.Application")
End If
On Error GoTo 0

objAcad.Visible = True
MsgBox "Acad is Alive!"
objAcad.Quit

End Sub

Title: Re: ObjectDBX from AccessVBA - how do I close out acad.exe ?
Post by: Jeff_M on May 02, 2006, 03:58:31 PM
Hi Mike,
As Berend says you must check for a running instance and create one if none are found. I would go further by saying you should set a variable to T/F based on whether you instantiated an Acad session, this way you can only close it if you opened it. Regardless, set an Object to the Acad session. Also, before closing Acad when it's needed, Set dbxDoc = Nothing first, then close it.
Title: Re: ObjectDBX from AccessVBA - how do I close out acad.exe ?
Post by: mikesmithfl on May 02, 2006, 04:02:36 PM
Thanks Berend & Jeff - I was working in that direction, but I seem to have the sequence upside down.  You're supposed to clean it and then close it?  Obviously not enough sleep - I know better...

Well, I just got yanked from the project for another fire to put out, so I'll be back again later.

Thanks again!