Code Red > .NET

From Com to Managed

(1/2) > >>

Draftek:
I'm writing a c# batch program for autocad. I wanted to start from a windows app and run autocad from the app so I'm using the Com interop. I also want to take advantage of the managed classes once I have the connection.

The developer help says:

--- Quote ---To get the .NET object from a COM object, use the FromAcadXxx static function. For example, Database.FromAcadDatabase gets the .NET database object from the COM database object.

--- End quote ---
I have this so far:

--- Code: ---Autodesk.AutoCAD.Interop.AcadApplication oApp = oAcad.Application;
Autodesk.AutoCAD.Interop.AcadDocument oDoc = oApp.ActiveDocument;
Autodesk.AutoCAD.Interop.Common.AcadDatabase oData = oDoc.Database;
Autodesk.AutoCAD.DatabaseServices.Database nDatabase = Database.FromAcadDatabase(oDoc.Database);

--- End code ---

The last line give me an exception: "The cast is not valid"

Am I doing this wrong?

TR:
Are you trying to run managed code from a standalone .exe file? If so, I don't think that's possible. As far as I know managed code needs to be loaded via the netload command or from the registry (like the layer manager is).


If you are trying this from a netloaded .dll forget everything I just said.

Draftek:
You are right.

So, in order to get managed code from com, you must first start with managed code?
 
That sux, nor does it make any sense, to me.

Thanks.

TR:
If you accessing the drawing via COM Interop why not just continue doing what you need to do in a COM fashion. If you reflect on Autodesk.AutoCAD.Interop and Autodesk.AutoCAD.Interop.Common you will see that everything you need is accessible to you.

From what I understand the acmgd.dll and acdbmgd.dll contain the code required to run your applications from within AutoCAD, allowing you to define commands and such. It's intent was a .NET interface comparable to ObjectARX. Of course I may be wrong.

Draftek:
Your right. I think I am stupid and still thinking in 'vb6' activex mode.

As I'm developing in .Net, I was going to write utility classes like I did in vb6 (com). I could pass the autocad application to the com (in vb6) object and use my functions no matter whether I was in or out of process with AutoCAD.

Now, it appears for .Net, I will have one method for a com connection and a different one for managed code to do the same thing.

Navigation

[0] Message Index

[#] Next page

Go to full version