Hi, In my organization we had a VBA application that used to communicate with AutoCAD using COM Api's (1 of 100s or functionalities). We had a addin dll that was developed in C# which was loaded into AutoCAD.
Basically the VBA application was using something like this to invoke commands in AutoCAD
Set G_objAcad = GetObject(, "AutoCAD.Application.24.2")
Set objDoc = G_objAcad.ActiveDocument
objDoc.SendCommand (Chr$(27) & Chr$(27)) 'Send Cancel
objDoc.SendCommand ("COMMANDMETHODNAMETEST")
Recently we have migrated from the VBA application to a Blazor webassembly application that runs on a web browser.
My question is how can I now SendCommand or perform operations from the web browser.
What I have done:
Note: I am able to get MdiActiveDocument from my webapi controller. I am able to SendCommand to the drawing.
Is my approach correct ?
Solved! Go to Solution.
Solved by ed57gmc. Go to Solution.
@Ankit_Chaturvedi wrote:
Is my approach correct ?
That depends on what your requirements are, which you've said nothing about. For example, why did you choose to go to a web browser? If you need to run from a browser, you might want to consider Platform Services, which is basically an instance of cad running on a server.
The VBA application that I had, used to load records from the database and display it on the form. User can perform multiple operations on these records using context menu's, mostly CRUD operations or opening a standard VBA forms for some operation. Only one of the functionality includes communication with AutoCAD. Like linking a database record with the AutoCAD drawing object, or unlinking a database record from AutoCAD drawing object.
The webapplication is a hit as it performs 99.9 % of functionalities better as compared to the legacy once. Just need to find a way to accomodate this AutoCAD functionality. I cannot ask the user to use the legacy app just for this one AutoCAD related functionality.
You can control AutoCAD from another process, but I don't recommend using SendCommand to run scripts. Use the .NET api to execute your process. I don't have a lot of experience with web api's but if you say you have an AutoCAD plugin that communicates with localhost, develop your plugin with the functionality you need and then call those with web requests. However, all of that is already built into the Platform Services api's.
Some other alternatives: 1. Use MS Access for your gui and db needs and then access AutoCAD from there. 2. Use the data objects built into Visual Studio to create your own db and interface using WinForms and COM api to automate AutoCAD.
Thanks @ed57gmc. Do you think the web api that runs inside AutoCAD will be running on a seperate thread than the main thread on which AutiCAD runs? I believe the issue which I am facing like AutoCAD crashing or hanging is caused due to this only. In my web api controller I am trying to operations on the drawing which I believe is running on a seperate thread.
No, everything in AutoCAD runs in the same process. If you are trying to use a web api to send multiple tasks to the same AutoCAD instance, it must occur sequentially. You would have to create an instance of AutoCAD for each thread. This takes a lot of system resources on a pc and doesn't scale well. You don't have this limitation with platform services.
Can't find what you're looking for? Ask the community or share your knowledge.