Problems with VB .NET

Problems with VB .NET

Jedimaster
Collaborator Collaborator
6,150 Views
18 Replies
Message 1 of 19

Problems with VB .NET

Jedimaster
Collaborator
Collaborator

I am trying to learn VB .NET and running into a few snags.

I am running
Windows 7 Professional Service Pack 1 64 Bit
Microsoft Visual Studio Pofessional 2012 Upadte 4
OjectARX 2015
OjectARX 2015 .NET Wizards
AutoCAD MAP 2015

I have refernced in AcDbMgd.dll, AcMgd.dll, Autodesk.AutoCAD.Interop.Common.dll (I have tried both 32 & 64 bit), Autodesk.AutoCAD.Interop.dll(I have tried both 32 & 64 bit).
When tried to drill thru the intellisense ojects like in the demo it stops in certian locations. I tried to manually type in the code it gives me a blue underline and will not complie.


Imports Autodesk.AutoCAD.Interop
Imports Autodesk.AutoCAD.Interop.Common
Public Class AdskCommands
Public ReadOnly Property ThisDrawing() As AcadDocument
Get
**This is what it suppose to look like**
Return Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.AcadDocument
**Here is where it stops**
Return Autodesk.AutoCAD.ApplicationServices.Application.<<STOPS HERE>>
End Get
End Property

**This is what it suppose to look like**
<Autodesk.AutoCAD.Runtime.CommandMethod("myRoutine")>
**Here is where it stops**
<Autodesk.AutoCAD.Runtime.<<STOPS HERE>>
Public Sub myRoutine()
ThisDrawing.Utility.Prompt("Hello World")
End Sub
End Class

Thank you in advance for any advice or help.

0 Likes
Accepted solutions (1)
6,151 Views
18 Replies
Replies (18)
Message 2 of 19

Jedimaster
Collaborator
Collaborator

I clear the second problem with the Autodesk.AutoCAD.Runtime. Refenced AcCoreMGD.dll and added "Imports Autodesk.AutoCAD.Runtime". I am still getting an error "error BC30456: 'AcadDocument' is not a member of 'Autodesk.AutoCAD.ApplicationServices.Document'." I have tried adding "Imports Autodesk.AutoCAD.ApplicationServices.DocumentExtension"

0 Likes
Message 3 of 19

Jedimaster
Collaborator
Collaborator
Accepted solution

I found solution thanks to by _gile

 

http://forums.autodesk.com/t5/net/2014-conversion/td-p/4405227

 

Replaced

Return Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.AcadDocument

 

with

Return Application.DocumentManager.MdiActiveDocument.GetAcadDocument()

 

and added

Imports Autodesk.AutoCAD.ApplicationServices
Imports Autodesk.AutoCAD.ApplicationServices.DocumentExtension

 

AutoDesk or ADN need to update their documentation. http://download.autodesk.com/media/adn/DevTV_VBA_Migration/english/DevTV_VBA_To_VBdotNet_Migration_E... They are always hounding us to upgrade our software. Maybe if they updated their documentation and fixed known problems we would be more inclined to upgrade.

0 Likes
Message 4 of 19

augusto.goncalves
Alumni
Alumni
Hi,

Sorry about the problem you had with the migration material, indeed was designed for our initial migration, but then the API changed...

And I'm glad you're migration from VBA to VB.NET, please let us know if you need further assistance.
Regards,



Augusto Goncalves
Twitter @augustomaia
Autodesk Developer Network
0 Likes
Message 5 of 19

frosty1_4me
Advocate
Advocate

I'm experiencing the same issue but mine are not resolved by the suggested fixes which I already had in place.  My code errors on the below lines:

 

 Dim acDocMgr As DocumentCollection = Application.DocumentManager
        Dim doc As Document = acDocMgr.MdiActiveDocument
        Dim aDoc As AcadDocument
        aDoc = doc.GetAcadDocument()

The error fails on the variable aDoc.  It throws the following error:

 

 

'GetAcadDocument()' is not a member of 'Document'.

 

I have the following imported namespaces as well:

 

Imports Autodesk.AutoCAD.ApplicationServices
Imports Autodesk.AutoCAD.Runtime
Imports Autodesk.AutoCAD.Interop
Imports Autodesk.AutoCAD.Interop.Common
Imports Autodesk.AutoCAD
Imports Autodesk.AutoCAD.ApplicationServices.DocumentExtension
Imports Autodesk.AutoCAD.ApplicationServices.DocumentCollectionExtension

 

Any ideas as to what may be causing this?

 

Thanks.

0 Likes
Message 6 of 19

norman.yuan
Mentor
Mentor

if you are using AutoCAD 2012 or older, no, you cannot use that line of code  - GetAcadDocument();

 

If you use AutoCAD 2013 or later, you need to add at least 3 references:

 

accoremgd.dll

acdbmgd.dll

acmgd.dll

Norman Yuan

Drive CAD With Code

EESignature

0 Likes
Message 7 of 19

frosty1_4me
Advocate
Advocate

I do have those 3 references you listed.   The errors appear when attempting to compile the project in VS2015.  Using an older version of VS2013 and it compiles fine without issue.

 

I'm using 2014 acad map3d and now moving to 2016 map3d.  It's compiled as a 4.0 .net application. 

 

Perhaps its the version of interop dlls and those other autocad dlls that are causing the issue.  Since I embed the dlls within the .Net project.

 

Thanks for the response.

0 Likes
Message 8 of 19

frosty1_4me
Advocate
Advocate

I updated the dll's to use the 2016 installed version and it created more errors as well as continuing with the ones I'm attempting at fixing.  I'd like those fixed before I introduce more.  🙂

 

 

0 Likes
Message 9 of 19

brian.k.smith
Advocate
Advocate

I'm having the same problem.  This code worked from VS2012 in ACD2016.  I recently upgraded to VS2015 and now I'm getting the following error:

"

Severity

Code

Description

Project

File

Line

Suppression State

Error

BC30456

'GetAcadDocument' is not a member of 'Document'.

bks_acd2016_01

D:\Visual Studio 2012\Projects\bks_acd2016_01\bks_acd2016_01\AdskCommands.vb

11

Active

0 Likes
Message 10 of 19

_gile
Consultant
Consultant

Hi,

 

GetAcadDocument is an extension method defined in the DocumentExtension static class (module in VB).

Using extensions methods with VB is not as comfortable as with C#, e.g. with VB you may need to bring in scope extension methods by 'importing' the module:

Imports Autodesk.AutoCAD.ApplicationServices.DocumentExtension

Then you should be able to call the GetAcadDocument() method as an instance method of the Document type (the extended type)

doc.GetAcadDocument()

Anyway, as extension methods are static methods (Shared in VB), you can also call them with classical way.

DocumentExtension.GetAcadDocument(doc)


Gilles Chanteau
Programmation AutoCAD LISP/.NET
GileCAD
GitHub

0 Likes
Message 11 of 19

frosty1_4me
Advocate
Advocate

In my code example, I do call the DocumentExtension but I'm still having issues.

 

Imports Autodesk.AutoCAD.ApplicationServices.DocumentExtension
Imports Autodesk.AutoCAD.ApplicationServices.DocumentCollectionExtension
This Module contains functions that are reference in the project.
    'Some modules can be referenced directly, others are a template to be copied into the required module, and modified.

    Public WithEvents ThisDrawing As Autodesk.AutoCAD.Interop.AcadDocument = Autodesk.AutoCAD.ApplicationServices.Application.AcadApplication.ActiveDocument
    Public WithEvents docs As Autodesk.AutoCAD.ApplicationServices.DocumentCollection = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager
    Public WithEvents acadApp As Autodesk.AutoCAD.Interop.AcadApplication


    Private Sub docs_DocumentActivated(ByVal sender As Object, ByVal e As Autodesk.AutoCAD.ApplicationServices.DocumentCollectionEventArgs) Handles docs.DocumentActivated
        ThisDrawing = e.Document.GetAcadDocument()
    End Sub

The above code fails on the e.Document.GetAcadDocument() as GetAcadDocument not a member of Document.  I've tried ever options for that and still no luck.

0 Likes
Message 12 of 19

_gile
Consultant
Consultant

Hi,

 

Sorry but I cannot help very much further.

This topic seems to be very well named, all the thread I read about GetAcadDocument() issues were also related to VB.

It seems to me most of the problems with this method are related to VB specific behavior (extension methods, modules, ...).

 

What happens if you call the method as a staic (Shared) method.

ThisDrawing = DocumentExtension.GetAcadDocument(e.Document)

 



Gilles Chanteau
Programmation AutoCAD LISP/.NET
GileCAD
GitHub

0 Likes
Message 13 of 19

Jedimaster
Collaborator
Collaborator
Did you add all references in to the project?
0 Likes
Message 14 of 19

frosty1_4me
Advocate
Advocate

I believe so, unless there is one missing or changed:

 

- acadbmgd

- Autocad.interop

- Autcad.interop.common

- interop.autocadMap

- ManagedMapAPI

 

those are the ones in my project.

0 Likes
Message 15 of 19

_gile
Consultant
Consultant

@frosty1_4me

 

Aren't accoremgd and acmgd references missing? DocumentExtension is part of acmgd.dll

 

Maybe this can help:

http://adndevblog.typepad.com/autocad/2012/05/extension-methods-in-autocad-2013.html



Gilles Chanteau
Programmation AutoCAD LISP/.NET
GileCAD
GitHub

0 Likes
Message 16 of 19

frosty1_4me
Advocate
Advocate

My applogies,

 

Yes, those two are also reference in the project.

 

I just find it strange this works in VS2013 but not in VS2015.  It's the same project.  In order to trouble shoot the project we are currently rolling back to use 2013 when necessary.  I've checked the target framework as well and it matches 2013 so that is not an issue.

0 Likes
Message 17 of 19

_gile
Consultant
Consultant

Did you try calling GetAcadDocument() as a static (Shared) method!

ThisDrawing = DocumentExtension.GetAcadDocument(e.Document)


Gilles Chanteau
Programmation AutoCAD LISP/.NET
GileCAD
GitHub

Message 18 of 19

frosty1_4me
Advocate
Advocate

No, I hadn't tried that!  Ok, I've give that a go and let you know the result.

 

Thanks!

 

0 Likes
Message 19 of 19

frosty1_4me
Advocate
Advocate

That did the trick.  It also set me on a path to correct many other functions that were having similar problems.  Must have been a change to the acad map api from the previous version I was using.

 

Thanks!

0 Likes