Jump to content

Check Instances of AutoCad for Open Documents


Recommended Posts

Posted

What I am trying to do is check all the instances of Autocad that are running and check for all of the open documents in each one. I have this working in VB6 but .NET is giving me problems. I can get the MainWindowTitle but the other documents open for that instance I have not been able to figure out. Sorry if this has been posted before but I am not sure if I am even on the right track. Any suggestions for this in .NET? I would prefer not to use GetObject(, "Autocad.Application"). Thanks Everybody

Posted

Just out of curiosity, why don't you want to use the getobject method?

Posted

Because it does not want to work, I was looking for other options, I wanted to move out of the VB6 era. I am using VS2008 so I may not have any other options. I am trying to find out. Thanks again.

Posted

FWIW -

 

You may find this old post useful as an example of how to get an existing instance, or create a new instance of an application:

 

Sounds like you need to check for an active process, prior to creating a new instance.

 

Here's a VB.NET snippet from one of my projects, for you to pull from:

 

Imports Excel = Microsoft.Office.Interop.Excel
Imports Microsoft.Office.Interop

Imports System.Diagnostics
Imports System.IO

Module FOO

   Sub Excel_Foo()

       Dim xlApp As Excel.Application

       Try
           [color=seagreen]' Look for an existing process, if available getObject[/color]
           If Process.GetProcessesByName("Excel").Length > 0 Then
               xlApp = CType(GetObject(, "Excel.Application"), Excel.Application)
           [color=seagreen]' Else createObject[/color]
           Else
               xlApp = New Excel.Application
           End If

          [color=seagreen] ' <-- Do something[/color]

       Catch ex As Exception

       Finally
           xlApp = Nothing

   End Sub

End Module

Posted

It is the Do Something I am trying to figure out.

This returns the MainWindowTitle

AutoCAD Map 3D 2010 - [Drawing1.dwg] First instance

AutoCAD Map 3D 2010 - [A5119.DWG] Second Instance

If I have multiple files open in each instance I want the WindowTitle for each one.

Dim p() As Process = Process.GetProcessesByName("Acad")

ForEach proc As Process In p

Debug.Print(proc.MainWindowTitle)

For Each AcadDocument in proc...?

Next

 

Iterate through each instance and each document and return the window title.

Posted

What if none of these will import?

'Imports Autodesk.AutoCAD.Runtime

'Imports Autodesk.AutoCAD.ApplicationServices

'Imports Autodesk.AutoCAD.DatabaseServices

'Imports Autodesk.AutoCAD.EditorInput

Posted

Then you're missing Assembly Reference(s). :thumbsup:

 

... In Solution Explorer, Select the 'Show All Files' button, and expand the References node... Within, you should have AcDbMgd.dll, and AcMgd.dll added (be sure they both have 'Copy Local' = False in the Properties window).

 

If you do not know what these Assembly References are, see this thread.

Posted

I just remembered you're attempting to write an Application outside of AutoCAD... The code being referenced (from the developer help) assumes you are coding a plug-in to load/run within AutoCAD.

Posted

This is a File Manager Applicatio which clients reference an index of documents stored in an Access mdb file. The app allows them to check out, check in or copy files. If a client attempts to check in a file that is open in Autocad he/she receives a message from the app to save and close the file first. This only checks to see if the file is open. It does nothing inside of Autocad or to the file.

 

Here is the VB6 code for this function.

Public Function AcadLink() As Boolean
 Dim i As Integer
 Dim DwgName As String
 Dim hWndMain As Long
 Dim appverfile As String
 Dim lstItem As String
 Dim strappver As String

 AcadLink = False
 On Error GoTo nocad
 Set AcadApp = GetObject(, "AutoCAD.Application")
'  Debug.Print AcadApp.Name
'  Debug.Print AcadApp.FullName
'  Debug.Print AcadApp.hWnd
'  Debug.Print AcadApp.Caption
'  MsgBox ("*" & AcadApp.Caption & "*"), vbOKOnly

 Set fso = CreateObject("Scripting.FileSystemObject")
 appverfile = strAppPath & "ClientAutoCadVersion.rpt"
 If bFileExists(appverfile) Then
   Open appverfile For Input As #filenum
   Do
     Input #filenum, lstItem
     If UCase(lstItem) = UCase(Left(AcadApp.Caption, Len(lstItem))) Then
       strappver = Left(AcadApp.Caption, Len(lstItem))
     End If
   Loop Until EOF(filenum)
   Close #filenum
   DoEvents
 End If

 If Len(strappver) = 0 Then
   appverfile = "\\networkplace\[url="file://\\Dfw1wnh2\Mid-tex_workgroups\gisfmdb\ClientAutoCadVersion.rpt"]ClientAutoCadVersion.rpt[/url]"
   If bFileExists(appverfile) Then
     strappver = Left(AcadApp.Caption, InStr(1, AcadApp.Caption, "[") - 4)
     Open appverfile For Append As #filenum
     Print #filenum, strappver
     Close #filenum
     DoEvents
     filea = strAppPath & "ClientAutoCadVersion.rpt"
     fileb = "[url="file://\\networkplace\ClientAutoCadVersion.rpt"]\\networkplace\ClientAutoCadVersion.rpt[/url]"
     FileUpdate
     DoEvents
   End If
 End If

 appverfile = strAppPath & "ClientAutoCadVersion.rpt"
 If bFileExists(appverfile) Then
   Open appverfile For Input As #filenum
   Do
     Input #filenum, lstItem
     hWndMain = FindWindow(vbNullString, lstItem & " - [" & lstCitem & ".dwg]")
     If hWndMain > 0 Then
       AcadLink = True
       Close #filenum
       DoEvents
       GoTo nocad
     End If
   Loop Until EOF(filenum)
 End If

 For i = 0 To AcadApp.Documents.Count - 1
   DwgName = Left(Right(AcadApp.Documents(i).Name, Len(lstCitem) + 4), Len(lstCitem))
   If lstCitem = DwgName Then
     AcadLink = True
     Exit For
   End If
 Next i
nocad:
End Function

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...