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

Obtaining return values in windows forms exe when working with loaded .dll with COM interop (AUTOCAD .NET API)

2 REPLIES 2
Reply
Message 1 of 3
i_bherer
212 Views, 2 Replies

Obtaining return values in windows forms exe when working with loaded .dll with COM interop (AUTOCAD .NET API)

Hello all,

 

I will start by saying I am currently learning the .net api as well as COM interop, so please forgive my ignorance.

 

I am trying to create a windows forms application that shows off some functions I programmed in a internal .net dll. So far, I have managed to start up an instance of AutoCAD through COM interop without too much difficulty. I then run the "netload" command and I can now call the custom commands I have programmed in my dll. My problematic arises from the fact this method does not allow me to obtain any return values on my windows forms .exe. I would like, for example, to be able to show all the entities in a textbox of my windows forms. 

Ideally I would like to be able to directly call function in my code instead of passing through the AutoCAD console through AcadApplication.SendCommand("xxx") as this produces no return values.

 

I have went through Kean's blog posts about this(https://www.keanw.com/2009/05/interfacing-an-external-com-application-with-a-net-module-in-process-t...), but I cannot get it to work and I need an approach that could be utilized in different computers. 

 

Simply referencing my .dll and creating an object throws an exception..

 

Does anyone have any ideas for me to explore? Any help is greatly appreciated.

 

Thank you all,

2 REPLIES 2
Message 2 of 3
norman.yuan
in reply to: i_bherer

Firstly, I would avoid to run 2 desktop applications (the EXE app and AutoCAD at the same time as a business workflow) as much as possible. If the business workflow depends on AutoCAD/needs AutoCAD, then why simply create the same UI of the EXE in the AutoCAD plugin and let user only deals with one application (AutoCAD)?

 

If you do have legit reasons that require you MUST use external EXE to control desktop AutoCAD, then only automating AutoCAD via its COM API would make more sense.

 

Further, when for some reasons you decided the workflow is to use EXE and let AutoCAD run a custom .NET plugin, then, if you do not expect user to interact with the running AutoCAD, you should consider running AutoCAD core console instead of AutoCAD desktop, or better yes, to using the design automation of Autodesk's Platform Services in the cloud. 

 

Anyway, in order to get the process result data back from the AutoCAD plugin, be it runs as desktop or  as console AutoCAD, you may choose:

 

1. Simply save the result as data file (XML/JSON...) as temp file, and let your EXE poll the temp file location to pick up the file (you could host a FileSystemWatcher in your EXE.

 

2. You can host a HTTP server in your EXE app and have the Acad Plugin send a POST request to the HTTP service endpoint so the result data is posted back to your EXE. Hosting a lightweight http service has been very easy/simple since .NET framework 3.5. You can search online for this topic.

 

 

There could be other  ways, of course.

Norman Yuan

Drive CAD With Code

EESignature

Message 3 of 3
i_bherer
in reply to: i_bherer

Hello Norman,

 

Thanks for your answer. I must run my program out-of-process. I am utilizing the .net api simply because it is more modern, has more functionnalities and more documentation than COM interop. As for the other services you mentionned, I have to admit I do not know them. Basically I am designing an exeternal application that must: a) start up an instance of AutoCAD,  b) extract and read AutoCAD's database, and c) eventually have writing abilities as well. 

For now, I have shifted my methods thanks to your data file idea. I used this blog's (Kean is the top G) implementation to extract the database to an XML that my .exe reads. 

 

My next troubles arise from the fact I need the extracted data to correspond with the API's object model. I want the exported data to be classified in a hierarchal manner (database>blocktable>model_space>arc>properties, for example).

I am trying to understand where/how the entities of custom blocks are stored. Originally would have assumed their entities are stored in their respective blocks and are then pasted onto the model space through a block reference. However, data extraction from the above procedure shows entities twice if I have the same block twice on my drawing (as well as their respective block references). These entities also have some properties that are not the same, suggesting they are based on a reference in the model space rather than one their block (as I have seen before when treating them individually rather than through data extraction functions: for example, when iterating through the block table records). Do you have any insight for me about this?

 

I am also looking for a way to fully export all of the project's dictionnaries and all their contained data.

 

I am dumping a lot in this reply ahah! Any replies/help is greatly appreciated! 🙂

 

Thanks,

 

Isaac

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

Post to forums  

Forma Design Contest


AutoCAD Beta