.NET
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

COM connect to AutoCad-Addin

7 REPLIES 7
Reply
Message 1 of 8
cccberlin
647 Views, 7 Replies

COM connect to AutoCad-Addin

Hello, I'm writing an AutoCad addin and now looking for a connection using COM. I want to call objects by an own app and give it to another app (eg Excel). Inventor provides the automation object for easy access. Is there anything comparable or an alternative? Greetings from Berlin, Germany Chris
7 REPLIES 7
Message 2 of 8
norman.yuan
in reply to: cccberlin

Could you describe the situation in detail? Such as what is your "own app" and where it runs...?

 

If you mean an EXE application that you want to use to automate AutoCAD via COM, then yes, besides existing AutoCAD COM model, you can expose your AutoCAD .NET addin object (NETLOADed into AutoCAD) as COM and access it from outside AutoCAD. However, this way you need to register the exposed COM in registry, which is a hussle work to do.

 

You can also use WCF to communicate AutoCAD. That is hosting an WCF service inside AutoCAD add-in, and call the service from outside EXE app.

 

However, since AutoCAD is very complicated desktop application, it is really designed for user to control it, not for being used as non-user interactive server. It is better to do the automation the other way around. If you are looking for doing some kind of batch processing work with AutoCAD, you may look into AutoCAD console app (since AutoCAD 2013). Or if the batch process only involves drawing data retrieving/update, you may look into license RealDwg. When automating AutoCAD for a batch process, sometimes user interence is inevitable/required.

Norman Yuan

Drive CAD With Code

EESignature

Message 3 of 8
cccberlin
in reply to: norman.yuan

At first, Many thanks for your detailed reply and that you don't waste a word about my "strange" english 🙂 It is a study project. Our main task is it to pick out the properties of inspection dimensions and process them in Excel. You have to be able to start it from inside AutoCad & Inventor and from outside by windows exe. The latter includes a file search option (dwg, idw). First idea was to control the two Apps via COM, because we've already worked with it. However, we quickly found out, that especially AutoCad don't want to talk with us 🙂 After "little" search, we found the inspection information in the XDatas and a short and easy solution to read it out with a .NET Addin. Everyone talks about .NET solutions and not this antique COM 🙂 Until now, we didn't discover the interop correspondence, which would be the easiest way yet, because of our model architecture. Inventor is less stubborn, because of a good API (.NET & COM Interop identical) and the above-mentioned automation object. I've already thinking about WCF. It seems to be easy to implement, but a completely new approach for me. But you never stop learning 🙂 Thanks again, Chris
Message 4 of 8
StephenPreston
in reply to: cccberlin

Hi cccberlin,

 

AutoCAD has a comprehensive COM (ActiveX) API that can easily be used to automate it from an external application. Please explain what specific problems/errors are you seeing that make you say "AutoCad don't want to talk with us", and then someone may be able to tell you what you're doing wrong.

Cheers,

Stephen Preston
Autodesk Developer Network
Message 5 of 8
cccberlin
in reply to: StephenPreston

Hi, Please do not take my words so literally. I meant that I didn't find enough documentation about accessing AutoCad entities via COM. It is simple to open a document and call its database object, but on this point I'm stuck. With a .NET-Addin I can use the Transactionmanager of the document's database to search through it and parse the informations we need (Dimension.Properties and their XDatas). The problem there, is to carry out my interface-object, because it is hold by the addin. Regards, Chris
Message 6 of 8
StephenPreston
in reply to: cccberlin

Ok - so you're having trouble finding documentation for the ActiveX API. Go to http://www.autodesk.com/developautocad and then scroll down the page until you get to the ActiveX API link in the Documentation section. That will tell you where to find it.

 

Also, if you're using COM automation of AutoCAD 2010 or higher from an external .NET application, then this blog post will help you - http://through-the-interface.typepad.com/through_the_interface/2010/02/handling-com-calls-rejected-b... . You shouldn't have to worry if you're doing it from VBA in Excel or similar.

 

Also, you may have more success asking ActiveX API questions on the AutoCAD->Visual Basic Customization forum.

Cheers,

Stephen Preston
Autodesk Developer Network
Message 7 of 8

You can expose a .NET class in an AutoCAD managed extension to external COM clients and access it via the GetInterfaceObject() method of the AutoCAD Application Object, by passing it the ProgId of your COM class. For that to work, you need to derive your COM class from System.EnterpriseServices.ServicedComponent (I also recommend reading up on it first).

 

With the COM class registered correctly, you shold only need to get the AcadApplication COM object, and call its GetInterfaceObject() method, and that should create an instance of your COM class and return it to the consumer.

 

Message 8 of 8

I just noticed, that I didn't mention some important details: I use C# and ACad & Inventor are version 2013.

Despite COM is almost outdated I'll try it first:

 

 

            AcadDocument doc = acadapp.ActiveDocument;
            
foreach (object myobject in doc.ModelSpace) { AcadDimension dim = myobject as AcadDimension; if (dim != null) { //to avoid casting every type of dimension ... //because many properties are available by their corresponding interface only, even they are identical dynamic dyndim = dim; object oxdatatype = new object(); object oxdatavalue = new object(); dim.GetXData("", out oxdatatype, out oxdatavalue); short[] xdatatype = oxdatatype as short[]; object[] xdatavalue = oxdatavalue as object[]; } }

 

 

 

 This works, but isn't really pretty, isn't it?

After casting "dim" it is still a ComObject ...

 

Regards,

Chris

 

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk DevCon in Munich May 28-29th


Autodesk Design & Make Report

”Boost