[英]autoCAD running commands from c#
I want to execute autoCAD command at c#.我想在 c# 上执行 AutoCAD 命令。 I want to apply the "JUSTIFYTEXT MC" command to the selected object after clicking the button.单击按钮后,我想将“JUSTIFYTEXT MC”命令应用于所选对象。 Currently my code can be executed in command, but a new autoCAD window will be executed.目前我的代码可以在命令中执行,但将执行一个新的 AutoCAD 窗口。 I want to know how to run the command in the CAD window that is currently running.我想知道如何在当前运行的 CAD 窗口中运行命令。
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
.我通过创建一个由自动加载器加载的包并创建一个Web Api
来做到这一点。
Bundle: https://adndevblog.typepad.com/autocad/2013/01/autodesk-autoloader-white-paper.html捆绑包: 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.捆绑包是位于例如C:\\ProgramData\\Autodesk\\ApplicationPlugins
的文件夹,它具有特定结构、捆绑包支持的Autodesk
产品、平台( Win32
、 Win64
以及捆绑包的起点在哪里。此配置应在根目录下的PackageContents.xml
。
A content folder on the same level as PackageContents.xml
containing all your dlls etc.与PackageContents.xml
处于同一级别的内容文件夹,其中包含您的所有 dll 等。
These dlls can be loaded on startup when configuring PackageContents.xml
correctly and using the interface IExtensionApplication
.当正确配置PackageContents.xml
并使用接口IExtensionApplication
时,可以在启动时加载这些 dll。
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.在扩展IExtensionApplication
接口的类中,您可以在IExtensionApplication
Initialize()
时创建Web Api
或某种其他类型的通信,例如SignalR
。 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.您现在应该能够通过该AutoCAD
实例中托管的本地 Web api 与正在运行的AutoCAD
实例进行通信。
Hope that brief explanation helped.希望简短的解释有所帮助。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.