Activator.CreateInstance启动不同路径的应用程序

发布于 2024-10-02 07:49:41 字数 494 浏览 4 评论 0原文

我正在开发这个项目,.Net EXE 将启动 AutoCAD 并运行一些代码。谷歌搜索后,这是我有的选项:

a)Activator.CreateInstance
b) Process.Start

如果我使用b),AutoCAD启动后很难控制代码。所以a)是唯一的选择。在我客户的计算机上,可能安装了多个 AutoCAD、不同版本(2008、2009、2010、2011 等)、不同偏好(AutoCAD Vanilla、AutoCAD Map、AutoCAD Architecture 等)。对于不同的版本,我可以添加版本号,例如2008年的AutoCAD.Application.17.1。现在不同的喜好是我唯一需要解决的问题。例如,我的计算机上安装了 AutoCAD Map 和 AutoCAD Architecture。它们位于不同的文件夹中。 Activator.CreateInstance 始终启动最新运行的实例。即使我只使用 AutoCAD Architecture,如何在我的 exe 中启动 AutoCAD Map。

I'm working on this project, a .Net EXE will start AutoCAD and run some code. After googling, here is options I have:

a) Activator.CreateInstance
b) Process.Start

If I use b), it is hard to control the code after AutoCAD start. so a) is the only choice. On my client's machine, it is possible have multiple AutoCAD installed, different version (2008, 2009, 2010, 2011, etc), different favor (AutoCAD Vanilla, AutoCAD Map, AutoCAD Architecture, etc). For different version, I can add the version number, like AutoCAD.Application.17.1 for 2008. Now different favor is the only problem I need figure out. e.g. I have AutoCAD Map and AutoCAD Architecture installed on my machine. They are at different folder. Activator.CreateInstance always start the latest running one. How I can start AutoCAD Map in my exe even I just use AutoCAD Architecture.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

晨曦÷微暖 2024-10-09 07:49:41

对于 AutoCAD Map,我认为您可以使用 AutoCADMap.Application 作为程序 ID。对于 ACA,应该是 AecX.AecArchBaseApplication

For AutoCAD Map, I think you can use AutoCADMap.Application as program ID. For ACA, it should be AecX.AecArchBaseApplication

挽袖吟 2024-10-09 07:49:41

您可以指定程序 ID 及其版本来启动特定的 AutoCAD 版本,例如:

    private void addCircleToACAD_Click(object sender, EventArgs e)
    {
        AcadApplication acadApp = null;
        AcadCircle circle = null;
        AcadAcCmColor color = null;
        try
        {
            object obj = Marshal.GetActiveObject("AutoCAD.Application.18");
            if (obj != null)
            {
                acadApp = obj as AcadApplication;
                double[] cen = new double[] { 0, 0, 0 };
                circle = acadApp.ActiveDocument.Database.ModelSpace.AddCircle(cen, 10);
                color = acadApp.GetInterfaceObject("Autocad.AcCmColor.18") as AcadAcCmColor;
                color.SetRGB(50, 150, 250);
                circle.TrueColor = color;
                acadApp.ZoomExtents();
            }
            else
            {
                MessageBox.Show("AutoCAD is not open or version is not right.");
            }
        }
        catch
        {
            MessageBox.Show("AutoCAD is not open or version is not right.");
        }
        finally
        {
            if (color != null) Marshal.FinalReleaseComObject(color);
            if (circle != null) Marshal.FinalReleaseComObject(circle);
            if (acadApp != null) Marshal.FinalReleaseComObject(acadApp);
        }
    }

You can specify the program id and its version to start a particular AutoCAD version, somthing like:

    private void addCircleToACAD_Click(object sender, EventArgs e)
    {
        AcadApplication acadApp = null;
        AcadCircle circle = null;
        AcadAcCmColor color = null;
        try
        {
            object obj = Marshal.GetActiveObject("AutoCAD.Application.18");
            if (obj != null)
            {
                acadApp = obj as AcadApplication;
                double[] cen = new double[] { 0, 0, 0 };
                circle = acadApp.ActiveDocument.Database.ModelSpace.AddCircle(cen, 10);
                color = acadApp.GetInterfaceObject("Autocad.AcCmColor.18") as AcadAcCmColor;
                color.SetRGB(50, 150, 250);
                circle.TrueColor = color;
                acadApp.ZoomExtents();
            }
            else
            {
                MessageBox.Show("AutoCAD is not open or version is not right.");
            }
        }
        catch
        {
            MessageBox.Show("AutoCAD is not open or version is not right.");
        }
        finally
        {
            if (color != null) Marshal.FinalReleaseComObject(color);
            if (circle != null) Marshal.FinalReleaseComObject(circle);
            if (acadApp != null) Marshal.FinalReleaseComObject(acadApp);
        }
    }
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文