Valued Contributor
69 Posts
1 Kudo
Registered: ‎07-25-2012
Post 1 of 6

VB.NET Sample Code from .NET Developers' Guide Not Working for Me

1715 Views, 5 Replies
08-16-2012 01:42 PM

I hate to keep being the complainer in the group but I'm really trying to understand how to become a better programmer in .NET. My mission today was to write some code which would open an existing drawing. I worked on a machine with 2009 first and only limited success, so I then went to another computer running AC 2013 and accessed the 2013 .NET Developers' Guide at this link:




About 1/2 way down the page I found information on how to open an existing drawing. As usual the text is missing what references need to be added in order to make the code work. So thinking it would be as the first couple of chapters in the guide outlined I would need the following:


    AcMgd.dll       AcDbMgd.dll     AcCoreMdg.dll


When I inserted the code I got the error


'Open is not a member of Autodesk.AutoCAD.ApplicationServices.DocumentCollection'


Now trying to be student who learns why this is happening I do a quick search and find in another Autodesk forum that DocumentCollection should be replaced with DocmentCollectionExtension and that I should read more in the .NET migration part of the .NET Developers' Guide for 2013. I further see mention that the statement should actually be DocumentCollectionExtension.Open but I cannot get the .Open to enter into the IDE. I guess I'm missing another refernence but since I've tried just about all of them I cannot imagine which one it could be.


I have poured over the migration page and found only limited information on how I could resolve this. Perhaps I am missing it right in front of me.



*Expert Elite*
1,286 Posts
37 Kudos
Registered: ‎06-21-2004
Post 2 of 6

Re: VB.NET Sample Code from .NET Developers' Guide Not Working for Me

08-16-2012 02:21 PM in reply to: btillman

You have probably already seen this.




(defun botsbuildbots() (botsbuildbots))
Valued Mentor
388 Posts
30 Kudos
Registered: ‎03-31-2005
Post 3 of 6

Re: VB.NET Sample Code from .NET Developers' Guide Not Working for Me

08-16-2012 02:33 PM in reply to: btillman

Hello btillman.  I wanted to try this since I installed Map 3D 2013 last week.  This works, but for some reason it is not the "active" drawing - drawing 1 is on top (active) after I run this.


Option Strict On
Option Explicit On

Imports acapp = Autodesk.AutoCAD.ApplicationServices
Imports Autodesk.AutoCAD.Runtime

Public Class Acad2013Class1

    <CommandMethod("opendwg")> _
    Sub openmain()
        Dim fname As String = "d:\acad\drawings\ne.dwg"
        Dim acdocmgr As acapp.DocumentCollection = Nothing
        Dim acdoc As acapp.Document = Autodesk.AutoCAD.ApplicationServices.DocumentCollectionExtension.Open(acdocmgr, fname, False)
        acdocmgr.MdiActiveDocument = acdoc
    End Sub

End Class

 I am also attaching a screen shot of the references.  I do not do this as a rule.  I feel it is an important part of learning app. development in the .NET environment.  APIs and Namespaces contain all of the secrets - the coding part is easy. 


Good luck!

Valued Contributor
69 Posts
1 Kudo
Registered: ‎07-25-2012
Post 4 of 6

Re: VB.NET Sample Code from .NET Developers' Guide Not Working for Me

08-17-2012 04:49 AM in reply to: arcticad

Thanks for all the replies. And yes, arcticad, that was the exact post I was referring to. And in that post the moderator is showing something which looks like he's correcting the OP with DocumentCollectionExtension.Open. However, I cannot seem to get the .Open part to enter into the IDE of VB 2010 Express.


I examined the other reply that included a screen shot of all the references and mine match his exactly. I willi try the code he indicates works for Map 3D but he also mentions that the drawing he opens does not end up as the Active drawing. I think I can tweak that part. But the first thing is to just try and get a drawing to open.

*Expert Elite*
753 Posts
54 Kudos
Registered: ‎02-13-2008
Post 5 of 6

Re: VB.NET Sample Code from .NET Developers' Guide Not Working for Me

08-20-2012 11:33 AM in reply to: btillman

I think the reason fieldguy's code is not activating the new drawing is because he does not have the Session flag on the CommandMethod.

Dave O.                                                                  Sig-Logos32.png
Valued Mentor
370 Posts
175 Kudos
Registered: ‎05-06-2012
Post 6 of 6

Re: VB.NET Sample Code from .NET Developers' Guide Not Working for Me

08-21-2012 02:01 AM in reply to: btillman

From what I've been told, VB.NET 2010 does not recognize some extension methods and its logged as a bug on Microsoft Connect.


The fact is that Open() and other methods of the DocumentCollectionExtension class are extension methods that allow them to be used as if they were methods of the DocumentCollection, which (in c# at least) means the same source code that calls them in earlier releases will still work in AutoCAD 2013.

Post to the Community

Have questions about Autodesk products? Ask the community.

New Post
Are you interested in helping shape the future of the Autodesk Community? To participate in this brief usability study, please click here. Your time and input is greatly appreciated!