.NET

.NET

Reply
Valued Contributor
btillman
Posts: 68
Registered: ‎07-25-2012
Message 1 of 6 (1,652 Views)

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

1652 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:

 

http://docs.autodesk.com/ACD/2013/ENU/index.html?url=files/GUID-4E1AAFA9-740E-4097-800C-CAED09CDFF12...

 

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*
arcticad
Posts: 1,286
Registered: ‎06-21-2004
Message 2 of 6 (1,640 Views)

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.

 

http://forums.autodesk.com/t5/NET/Open-is-not-a-member-of-ApplicationServices-DocumentCollection/td-...

---------------------------



(defun botsbuildbots() (botsbuildbots))
Valued Mentor
fieldguy
Posts: 382
Registered: ‎03-31-2005
Message 3 of 6 (1,632 Views)

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
btillman
Posts: 68
Registered: ‎07-25-2012
Message 4 of 6 (1,599 Views)

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*
chiefbraincloud
Posts: 753
Registered: ‎02-13-2008
Message 5 of 6 (1,554 Views)

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
DiningPhilosopher
Posts: 370
Registered: ‎05-06-2012
Message 6 of 6 (1,529 Views)

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
Announcements
Do you have 60 seconds to spare? The Autodesk Community Team is revamping our site ranking system and we want your feedback! Please click here to launch the 5 question survey. As always your input is greatly appreciated.