
NET API won most, if not all, AutoCAD programmers' favorite and AutoCAD COM API has been gradually fade into background. However, there are still times when people want to automate AutoCAD from external process/application, in which AutoCAD COM API still has significant advantage due to its fairly complete COM object model.ĪutoCAD can also be automated from external application in pure. NET communication mechanism between processes/applications can be used to automate AutoCAD. There are a few samples/articles/post on this topic can be found on the Internet (unfortunately I did not keep their links:-(). I recently worked on a web application development project, in which ASP.NET Web API is used to expose business data as OData to be consumed by user side application (web application, mobile application or desktop).

For those who want to know more about ASP.NET Web API, go to here for more details. In spite its name "ASP.NET Web API" say "ASP.NET" and "Web", Web API is not just for web application. Like WCF, it is regarding communication between processes/applications, a much simplified in comparison to WCF. Its communication conduit is purely based on Http protocol, which, besides can be hosted in Windows' IIS server, can also be self hosted easily, thus effectively make its host's computing power available to outside world. So, I explored a bit to see how I could use this technology to automate AutoCAD. To be honest, I am not a fan of automating AutoCAD from external application, even though I did develop a few applications doing this (mostly some kind of drawing batch processing operations), because AutoCAD is a very complicated desktop application and it is very often that an AutoCAD process needs user interaction to complete.
#WIFISPOOF WIKIPEDIA CODE#
So, the code I show here may not have much practical value to my real word AutoCAD development. It only shows a new way how AutoCAD can be automated from external application. I used Visual Studio 2012/.NET 4.5 and AutoCAD 2014. The Visual Studio solution and 3 projects in the solution are shown in pictures below: NET 4.0 is because the NuGet Manager only allows to get latest ASP.NET Web API Self-Host package, which requires. If looking into the code carefully, one would notice that I get a reference to current drawing document via HostApplicationServices.WorkingDatabase->(Database)ĭue to the way the Http self-host server runs, the MdiActiveDocuement is not available. I did not bother, or have time, to dig out the reason, as long as my exploration worked the way I did it.Īlso, by following Http command tradition, the Put() method is meant for updating, thus the DrawController uses Put() to take client's request to draw something in AutoCAD. If I want to drawing something else rather than circle, I would create another Dto data class in AcadHttpDto project (say, LineArgs, which has data for a line's 2 end points) and add an overloaded Put() method that has different argument (LineArgs for drawing a line).
#WIFISPOOF WIKIPEDIA FREE#
Now with just the 2 projects (AcadHttpDto and AcadHttpServerHost) being built, AutoCAD is ready to host the Http Web API inside and accept external requests and acts accordingly.įor any programmer who is familiar to web programming, Fiddler is a very well-known, a must-have free tool. I used Fiddler for testing the above self-host Web API code in AutoCAD before I actually wrote a Http client application. This video clip shows using Fiddler to have AutoCAD draw a circle.Īfter verifying the Web API server hosted in AutoCAD works as expected with Fiddler, I then continued the exploration to start the third project, a WinForm application with its UI looks like: This video clip shows using Fiddler to get/set AutoCAD system variable.

Yeah, I was afraid that the Http server may have difficult to call into AutoCAD operation when I started, but went ahead for a try anyway. OBJECTARX FOR AUTOCAD 2014 CODEĪs the code showed, HostApplicationServices.WorkingDatabase is reachable and a Document can be obtained via the database. That is good enough to lock the document and perform some operation against WorkingDatabase. Obviously, when AutoCAD is receiving request from Http and working in the request, the AutoCAD session should not be operated by a user, as least when the hosted Http server is working on a request.
