明经CAD社区

 找回密码
 注册

QQ登录

只需一步,快速开始

搜索
查看: 3964|回复: 10

[原创]请教:DotNetARX+C# 方面问题?

[复制链接]
发表于 2010-4-15 10:38:00 | 显示全部楼层 |阅读模式

新手请教各位大侠一个问题:

最近我用DotNetARX+C#做了一dll,好像只能通过netload加载这个dll,有没有其他方法做成一个类似于EXE的应用程序,双击它直接启动CAD,同时加载dll动态库?

发表于 2010-4-15 14:18:00 | 显示全部楼层

可以通过注册表加载,而且可以实现更灵活的加载方式

 楼主| 发表于 2010-4-15 15:25:00 | 显示全部楼层

楼上的朋友,能详细讲解一下注册表方法吗?非常谢谢!

发表于 2010-4-15 15:53:00 | 显示全部楼层
 楼主| 发表于 2010-4-15 21:50:00 | 显示全部楼层

版主:

     你好,按照你的指示,自动加载dll可以了。还有一个问题没弄明白,就是我这个dll里面有一个菜单栏创建命令,想在加载dll时执行加载菜单栏命令,可以实现吗?怎样实现?非常感谢你的不吝赐教!

发表于 2010-4-15 22:06:00 | 显示全部楼层

上面的帖子一楼

 楼主| 发表于 2010-4-16 10:47:00 | 显示全部楼层

版主在吗? 我还是没实现启动CAD时自动加菜单功能,我的代码如下,麻烦你帮我看下谢谢:
using System;
using System.Linq;
using System.Text;
using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.EditorInput;
using Autodesk.AutoCAD.Geometry;
using Autodesk.AutoCAD.Runtime;
using DNA;
using Autodesk.AutoCAD.Colors;
using Autodesk.AutoCAD.Windows;

using System.Diagnostics;
using System.Runtime.InteropServices;
using Autodesk.AutoCAD.Interop;
using Autodesk.AutoCAD.Interop.Common;


namespace CsMgd1
{
    /// <summary>
    /// Summary for Class1.
    /// </summary>
    public class Class1 : IExtensionApplication
    {
        public Class1()
        {
            AddMenuCom();
        }

        public void Initialize()
        {
            try
            {
                //cls.AddMenuCom();
            }
            catch (System.Exception ex)
            {
                ed.WriteMessage("Error: " + ex.Message);
            }
        }
        public void Terminate() { }

        Database db = HostApplicationServices.WorkingDatabase;
        Editor ed = Application.DocumentManager.MdiActiveDocument.Editor;
        [CommandMethod("Test")]
        public void Test()
        {
            using (Transaction trans = db.TransactionManager.StartTransaction())
            {
                trans.Commit();
                //Tools.RunCommand(false, "circle", "5,5", Tools.PauseToken, "line", "5,5", "7,5", "");
            }
        }

        [CommandMethod("AM")]
        public static void AddMenuCom()
        {
            AcadApplication app = (AcadApplication)Marshal.GetActiveObject("AutoCAD.Application.17");
            AcadMenuBar menuBar = app.MenuBar;
            AcadMenuGroup menuGroup = app.MenuGroups.Item(0);
            AcadPopupMenus menus = menuGroup.Menus;
            AcadPopupMenu mymenu = menus.Add("MyMenu");

            mymenu.AddMenuItem(0, "Hello", "hello");
            mymenu.AddSeparator(1);
            mymenu.AddMenuItem(2, "Hello2", "hello");
            AcadPopupMenu ext = mymenu.AddSubMenu(3, "Ext");
            ext.AddMenuItem(0, "Hello", "hello");
            ext.AddSeparator(1);
            ext.AddMenuItem(2, "Hello2", "hello");
            mymenu.InsertInMenuBar(menuBar.Count - 2);
        }

    }
}

发表于 2010-4-16 18:17:00 | 显示全部楼层

        public void Initialize()
        {
            try
            {
            AcadApplication app = (AcadApplication)Marshal.GetActiveObject("AutoCAD.Application.17");
            AcadMenuBar menuBar = app.MenuBar;
            AcadMenuGroup menuGroup = app.MenuGroups.Item(0);
            AcadPopupMenus menus = menuGroup.Menus;
            AcadPopupMenu mymenu = menus.Add("MyMenu");

            mymenu.AddMenuItem(0, "Hello", "hello");
            mymenu.AddSeparator(1);
            mymenu.AddMenuItem(2, "Hello2", "hello");
            AcadPopupMenu ext = mymenu.AddSubMenu(3, "Ext");
            ext.AddMenuItem(0, "Hello", "hello");
            ext.AddSeparator(1);
            ext.AddMenuItem(2, "Hello2", "hello");
            mymenu.InsertInMenuBar(menuBar.Count - 2);
            }
            catch (System.Exception ex)
            {
                ed.WriteMessage("Error: " + ex.Message);
            }
        }

发表于 2010-4-16 18:19:00 | 显示全部楼层

另外,我的建议

菜单、工具条之类的最好用加载cui文件实现,不需编程的

发表于 2010-4-21 22:13:00 | 显示全部楼层
function XML() {
    [native code]
}
您需要登录后才可以回帖 登录 | 注册

本版积分规则

小黑屋|手机版|CAD论坛|CAD教程|CAD下载|联系我们|关于明经|明经通道 ( 粤ICP备05003914号 )  
©2000-2023 明经通道 版权所有 本站代码,在未取得本站及作者授权的情况下,不得用于商业用途

GMT+8, 2024-11-29 13:48 , Processed in 0.181475 second(s), 23 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表