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

Invoking AutoCAD custom command from web browser

5 REPLIES 5
SOLVED
Reply
Message 1 of 6
Ankit.Chaturvedi
351 Views, 5 Replies

Invoking AutoCAD custom command from web browser

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:

  1. Created a self host webapi that runs inside AutoCAD and it immediately starts a server on https://localhost:9000/ as soon as the addin dll is loaded into AutoCAD. I have created a registry key so the addin dll automatically loads on AutoCAD startup. 
  2. I have created endpoints which perform some action.
  3. I am just calling these endpoints from my Blazor application from the browser. 
  4. However the process is not as smooth as it used to be with the VBA application. Sometimes I see AutoCAD hanging up, sometimes it crashes. 

 

 

Note: I am able to get MdiActiveDocument from my webapi controller. I am able to SendCommand to the drawing. 

 

Is my approach correct ? 

Tags (3)
Labels (1)
5 REPLIES 5
Message 2 of 6
Ed.Jobe
in reply to: Ankit.Chaturvedi


@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.

Ed


Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.
How to post your code.

EESignature

Message 3 of 6

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. 

Message 4 of 6
Ed.Jobe
in reply to: Ankit.Chaturvedi

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.

Ed


Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.
How to post your code.

EESignature

Message 5 of 6

Thanks @Ed.Jobe. 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. 

Message 6 of 6
Ed.Jobe
in reply to: Ankit.Chaturvedi

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.

Ed


Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.
How to post your code.

EESignature

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

Post to forums  

Technology Administrators


Autodesk Design & Make Report