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.DocumentColle
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.
You have probably already seen this.
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.DocumentColle
ctionExtension.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.
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.
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.
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.
Log into access your profile, ask and answer questions, share ideas and more. Haven't signed up yet? Register