简体   繁体   中英

autoCAD running commands from c#

I want to execute autoCAD command at c#. I want to apply the "JUSTIFYTEXT MC" command to the selected object after clicking the button. Currently my code can be executed in command, but a new autoCAD window will be executed. I want to know how to run the command in the CAD window that is currently running.

My Code

AcadApplication acad = new AcadApplication();

acad.Visible = true;
acad.WindowState = AcWindowState.acMin;
acad.ActiveDocument.SendCommand("JUSTIFYTEXT MC ");

I have done this by creating a bundle that is loaded by the autoloader and creating a Web Api .

Bundle: https://adndevblog.typepad.com/autocad/2013/01/autodesk-autoloader-white-paper.html

A bundle is a folder located on for example C:\\ProgramData\\Autodesk\\ApplicationPlugins that has a certain structure, what Autodesk products the bundle supports, platform ( Win32 , Win64 and where the start point for your bundle is. This config should be within a PackageContents.xml at the root.

A content folder on the same level as PackageContents.xml containing all your dlls etc.

These dlls can be loaded on startup when configuring PackageContents.xml correctly and using the interface IExtensionApplication .

In the class that extends the IExtensionApplication interface you can create a Web Api or some other kind of communication like SignalR when Initialize() is called. Save the connection string to a file and read it from your other application.

You should now have the ability to communicate with a running AutoCAD instance through a local web api hosted within that AutoCAD instance.

Hope that brief explanation helped.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM