Author Topic: ACAD 2013 Open Drawing  (Read 9530 times)

0 Members and 1 Guest are viewing this topic.

stevenh0616

  • Guest
ACAD 2013 Open Drawing
« on: December 12, 2012, 03:59:20 PM »
Anyone know how to open a drawing programmatically in ACAD 2013? The developer doc (link below) says to do the following, but when I do the acDocMgr.Open says it does not belong to DocumentCollection. I'm thinking this is something they moved with the new API changes. Thoughts???

http://docs.autodesk.com/ACD/2013/ENU/index.html?url=files/GUID-330A8DCB-626F-4271-8B89-9773A7631D87.htm,topicNumber=d30e716937

Code - vb.net: [Select]
  1. Imports System.IO
  2. Imports Autodesk.AutoCAD.ApplicationServices
  3. Imports Autodesk.AutoCAD.DatabaseServices
  4. Imports Autodesk.AutoCAD.Runtime
  5.  
  6. <CommandMethod("OpenDrawing", CommandFlags.Session)> _
  7. Public Sub OpenDrawing()
  8.   Dim strFileName As String = "C:\campus.dwg"
  9.   Dim acDocMgr As DocumentCollection = Application.DocumentManager
  10.  
  11.   If (File.Exists(strFileName)) Then
  12.       acDocMgr.Open(strFileName, False)
  13.   Else
  14.       acDocMgr.MdiActiveDocument.Editor.WriteMessage("File " & strFileName & _
  15.                                                      " does not exist.")
  16.   End If
  17. End Sub
  18.  

BlackBox

  • King Gator
  • Posts: 3770
Re: ACAD 2013 Open Drawing
« Reply #1 on: December 12, 2012, 04:28:26 PM »
Did you add the necessary reference to AcCoreMgd.dll?

<snip>

Extension methods exposed by one type, look like methods of another type.

The Open() method was a member of the DocumentCollection class in previous releases. In AutoCAD 2013, Open() is a member of another class, but is an extension method that target's the DocumentCollection class, which means the method can be called as if it was still a member of DocumentCollection, and calls to it that worked in AutoCAD 2012 will continue to work in AutoCAD 2013, provided the assembly containing the extension method is referenced.

<snip>
"How we think determines what we do, and what we do determines what we get."

Jeff_M

  • King Gator
  • Posts: 4098
  • C3D user & customizer
Re: ACAD 2013 Open Drawing
« Reply #2 on: December 12, 2012, 04:39:29 PM »
You might want to see the 2013 Migration video Stephen Preston made, specifically at about the 3:10 mark.
Download and extract the zip, then load the html file in your browser.
http://adndevblog.typepad.com/autocad/2012/04/migrating-objectarx-and-net-plug-ins-to-autocad-2013.html

stevenh0616

  • Guest
Re: ACAD 2013 Open Drawing
« Reply #3 on: December 12, 2012, 05:33:49 PM »
Thanks to you both.

I did know to add the acCoreMgd.dll, but have not seen the DocumentCollectionExtension. I'll make sure I watch the video thouroughly!!  8-)

stevenh0616

  • Guest
Re: ACAD 2013 Open Drawing
« Reply #4 on: December 12, 2012, 06:27:50 PM »
Actually I'm still getting an error. It builds fine within Visual Studio and loads into CAD fine. When I try to run a command to open a drawing I get the error "Invalid Execution Context."

The error still occurs on "acDocMgr.Open(Path, False)"

I've followed all the 2013 conversion properties... not sure why it's not working. Here's my code.

Code - vb.net: [Select]
  1. Imports System.IO
  2. Imports Autodesk.AutoCAD.ApplicationServices
  3. Imports Autodesk.AutoCAD.ApplicationServices.DocumentCollectionExtension
  4. Imports Autodesk.AutoCAD.DatabaseServices
  5. Imports Autodesk.AutoCAD.Runtime
  6.  
  7. Public Class OpenDrawing
  8.     Public Shared Sub Open(ByVal Path As String)
  9.         Dim acDocMgr As DocumentCollection = Application.DocumentManager
  10.  
  11.         If (File.Exists(Path)) Then
  12.             acDocMgr.Open(Path, False)
  13.         Else
  14.             acDocMgr.MdiActiveDocument.Editor.WriteMessage("File " & Path & " does not exist.")
  15.         End If
  16.     End Sub
  17. End Class

Thanks for the help.

tonofsteel

  • Guest
Re: ACAD 2013 Open Drawing
« Reply #5 on: December 12, 2012, 06:41:03 PM »
Are you trying to open a drawing in AutoCAD from an external program?  The .NET libraries are meant to be used from in-process in AutoCAD and after you create a .dll it needs to be netloaded to run.

If you are trying to open a drawing from out of process then you need to use COM.

stevenh0616

  • Guest
Re: ACAD 2013 Open Drawing
« Reply #6 on: December 12, 2012, 06:42:45 PM »
Thanks.

No, this is being run from inside of CAD, so what I'm doing should work just fine - as documented in the AutoCAD Developers Guide.

Jeff H

  • Needs a day job
  • Posts: 6150
Re: ACAD 2013 Open Drawing
« Reply #7 on: December 12, 2012, 07:02:51 PM »
"Invalid Execution Context."

You need to be in the Application context.
 
You are in the document context.
 
You can use commandFlag.Session or I think there might be a method that will switch it for you.
 

Jeff H

  • Needs a day job
  • Posts: 6150
Re: ACAD 2013 Open Drawing
« Reply #8 on: December 12, 2012, 07:07:27 PM »
Thanks.

No, this is being run from inside of CAD, so what I'm doing should work just fine - as documented in the AutoCAD Developers Guide.

From developers guide
 
Code - Visual Basic: [Select]
  1.  
  2.  <CommandMethod("NewDrawing", CommandFlags.Session)> _
  3. Public Sub NewDrawing()
  4.   '' Specify the template to use, if the template is not found
  5.  '' the default settings are used.
  6.  Dim strTemplatePath As String = "acad.dwt"
  7.  
  8.   Dim acDocMgr As DocumentCollection = Application.DocumentManager
  9.   Dim acDoc As Document = acDocMgr.Add(strTemplatePath)
  10.   acDocMgr.MdiActiveDocument = acDoc
  11. End Sub
  12.  
  13.  
Notice the  <CommandMethod("NewDrawing", CommandFlags.Session)> _
 
Glad they did not name it RunInApplicationContext because that would be confusing.

BlackBox

  • King Gator
  • Posts: 3770
Re: ACAD 2013 Open Drawing
« Reply #9 on: December 12, 2012, 08:38:51 PM »
<snip>

Glad they did not name it RunInApplicationContext because that would be confusing.

 :lmao:
"How we think determines what we do, and what we do determines what we get."

TheMaster

  • Guest
Re: ACAD 2013 Open Drawing
« Reply #10 on: December 12, 2012, 08:49:32 PM »
Are you trying to open a drawing in AutoCAD from an external program?  The .NET libraries are meant to be used from in-process in AutoCAD and after you create a .dll it needs to be netloaded to run.

It should be plainly obvious that the OP's code is a .NET extension.

stevenh0616

  • Guest
Re: ACAD 2013 Open Drawing
« Reply #11 on: December 13, 2012, 12:01:42 AM »
Thanks again everyone.

My overall goal was to allow the user to select a drawing a make some edits to XREFs in the selected drawings database, without opening the file. IE: Unload/reload XREFs prior to opening the file (This I have working well).

My next step, within the same command was to take the original selected file and open it. So initially I was thinking of using this open sub from the .NET developers guide, not having much experience with Command Flags. I did read up on these more and have a better understanding.

For what I'm looking to do, it seems using SendStringtoExecute is a better option I think. Unless somebody as a better idea...

BEEB.NET

  • Guest
Re: ACAD 2013 Open Drawing
« Reply #12 on: January 26, 2013, 05:31:40 AM »
        Dim acDocMgr As DocumentCollection = Application.DocumentManager
        Dim This As Document = DocumentCollectionExtension.Open(acDocMgr, "D:\test.dwg", True)