CAD二次开发&C#.Net编程-CAD创建右键菜单

CAD二次开发&C#.Net编程—CAD创建右键菜单


 		private static ContextMenuExtension m_ContextMenu;
 		
 		//装载右键菜单
        public static void Attach()
        {
            //右键菜单 对象
            m_ContextMenu = new ContextMenuExtension();

            m_ContextMenu.Title = "修改";

            //右键菜单项及其事件
            MenuItem MenuItem_1 = new MenuItem("竖井");
            
            MenuItem_1.Click += new EventHandler(MenuItem_1_Click);
            
            //菜单项添加到右键菜单
            m_ContextMenu.MenuItems.Add(MenuItem_1);
            
            //加入到应用程序级的右键菜单中
            // Application.AddDefaultContextMenuExtension(m_ContextMenu);

            //加入到某一种对象的右键菜单中
            RXClass rxClass = Entity.GetClass(typeof(BlockReference));
            Application.AddObjectContextMenuExtension(rxClass, m_ContextMenu);

        }

		//卸载右键菜单
        public static void Detach()
        {
            Application.RemoveDefaultContextMenuExtension(m_ContextMenu);
        }
		
		//将竖井插入模型空间的事务处理
        private static void MenuItem_1_Click(object sender,EventArgs e)
        {
            Database db = HostApplicationServices.WorkingDatabase;
            Editor ed = Autodesk.AutoCAD.ApplicationServices.Core.Application.DocumentManager.MdiActiveDocument.Editor;
            ObjectId SpaceId = db.CurrentSpaceId;
            PromptPointResult ppr;
            PromptPointOptions ppa = new PromptPointOptions("\n 指定插入点:")
            {
                UseBasePoint = false
            };
            ppr = ed.GetPoint(ppa);
            Point3d location;
            if (ppr.Status != PromptStatus.OK)
            {
                return;
            }
            else
            {
                location = ppr.Value;
            }
            
            //保留小数点后4位
            string x = location.X.ToString("f4");
            string y = location.Y.ToString("f4");
            
            Set4mShaft(db, SpaceId, x+" "+y+" 竖井", location, layername);
        }
        

你可能感兴趣的:(CAD,c#,c#,.net,cad)