I'm trying to convert an existing VBA routine to a vb.Net dll. One of the functions is inserting and scaling an existing tif image file into a blank AutoCAD 2010 drawing. I've searched and found just a few examples, but they all seem horrifically complicated . Am I missing the simple way of doing this, or is this an example of the seemingly massive learning curve of .Net that is beginning to remind me of my collegiate C class (shudder)?
Well, If you stick to the COM API, the code will be almost the same as the VBA code.
I was dangerous/clueless enough in VB6/VBA, but in vb.net I am truly a noob. Do you mean a COM reference such as ...\VBAServer\VBAServerx64.exe?
No, I mean the AutoCAD COM libraries, instead of the Managed .NET References. See image.
Can't find the second one
Not sure why the name is listed that way, but it is the AXDBLib pointing to the file axdb18enu.tlb
And now I get this:
Error 15 The project currently contains references to more than one version of Autodesk.AutoCAD.Interop.Common, a direct reference to version 18.0.0.0 and an indirect reference (through 'Autodesk.AutoCAD.Interop.IAcadApplication.ActiveDocument') to version 18.1.0.0. Change the direct reference to use version 18.1.0.0 (or higher) of Autodesk.AutoCAD.Interop.Common.
I tried a suggested work around by installing ObjectARX in this thread http://forums.autodesk.com/t5/NET/2011-Type-Libraries-Breaks-2010/td-p/2679224, and using those tlb files instead, but I cannot get past this duplication error.
Hi,
As you may notice, this is because your references are duplicated 🙂
First lets clean the house, go to your project properties, at references tab, then remove all AutoCAD.Interop references, including AutoCAD Type Library and ObjectDBX Type Lirabry.
Now add them from the proper place: ObjectARX SDK. Go to add reference, and instead using the COM tab, go to Browse tab and select from the ObjectARX SDK location, add only Autodesk.AutoCAD.Interop.dll and Autodesk.AutoCAD.Interop.Common.dll. Do not select the .tlb, as will be the same as add it from COM tab, which is not good.
Not that the ObjectARX have two folders: \inc-win32 and \inc-x64\. If you plan to reply your application on 32 bit select the first, if 64 bit select them from the second folder.
Finally, if you are developing for a vertical, such as Civil 3D, after doing the above, it is possible (likely) that when you add reference to a vertical .tlb, it will try readd AutoCAD reference, but again this is from .tlb which is not good - remove them again.
When you add the references from ObjectARX SDK you have more control over the version, so select the correct platform (32 or 64) and the minor version on a cycle that you want yo support (e.g. if you want to support 2010/11/12, use 2010 references).
Hope this help.
Augusto Goncalves
Autodesk Developer Network
Okay; with your instructions I got it to finally compile, though using .Net components for .COM functionality is still confusing to my tiny rat brain. With a silly work around(text edit of the *.vbproj file) to allow AutoCAD to be launched for debugging this dll project (using Visual Basic 2008 Express), I now realize I have no idea to invoke this project from within AutoCAD.
So glad Microsoft decided to depricate VBA as so far, .Net is so much easier. #Sarcasm
But I do sincerely thank you for the help.
Hi,
Glad you are moving to .NET, I'm sure you will realize in time that this is much better than VBA
As you have a VBA project, have you looked at this material?
You may see at video above that for a regular VBA subroutine, you need to add a CommandMethod attribute with a command name. Once this is compiled into a DLL, call AutoCAD NETLOAD command and then you custom command will be registered in AutoCAD.
Also, the video come with a tool to help you, including the edition of the .vbproj to start it from Visual Express. Take a look, it worth it!
Regards,
Augusto Goncalves
Autodesk Developer Network
I'll definitely take a look. Thanks again.