• <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>

            Life is Good.

            Enhance Tech and English
            隨筆 - 65, 文章 - 20, 評(píng)論 - 21, 引用 - 0
            數(shù)據(jù)加載中……

            AutoCAD: 添加鼠標(biāo)右鍵

            using System;
            using System.Collections.Generic;
            using System.Text;
            using Autodesk.AutoCAD.ApplicationServices;
            using Autodesk.AutoCAD.DatabaseServices;
            using Autodesk.AutoCAD.EditorInput;
            using Autodesk.AutoCAD.Runtime;
            using Autodesk.AutoCAD.Windows;

            namespace ContextMenuApp
            {
                
            public class ContextMenuApp : IExtensionApplication
                {

                    
            private ContextMenuExtension m_ContextMenu;

                    
            public void Initialize()
                    {
                        AddContextMenu();
                    }

                    
            public void Terminate()
                    {
                        RemoveContextMenu();
                    }


                    
            // AddContextMenu
                    public void AddContextMenu()
                    {
                        
            try
                        {
                            m_ContextMenu 
            = new ContextMenuExtension();
                            m_ContextMenu.Title 
            = (("ContextMenu Title")); // Change it to your Context Menu Title
                            m_ContextMenu.Popup += new EventHandler(BlkRefContextMenu_Popup);

                            MenuItem mi 
            = new MenuItem(("HelloWorld")); // Change it to your Context Menu Item Name
                            mi.Click += new EventHandler(CallbackOnClick);
                            m_ContextMenu.MenuItems.Add(mi);
                            RXClass rxc 
            = BlockReference.GetClass(typeof(BlockReference));
                            Application.AddObjectContextMenuExtension(rxc, m_ContextMenu); 
            // Only Add it to BlockReference
                        }
                        
            catch (System.Exception exc)
                        {
                            Editor ed 
            = Application.DocumentManager.MdiActiveDocument.Editor;
                            ed.WriteMessage(
            string.Format("\n Add ContextMenu error: {0}", exc.Message));
                        }
                    }

                    
            // RemoveContextMenu
                    public void RemoveContextMenu()
                    {
                        
            try
                        {
                            
            if (m_ContextMenu != null)
                            {
                                RXClass rxc 
            = BlockReference.GetClass(typeof(BlockReference));
                                Application.RemoveObjectContextMenuExtension(rxc, m_ContextMenu);
                                m_ContextMenu 
            = null;
                            }
                        }
                        
            catch (System.Exception exc)
                        {
                            Editor ed 
            = Application.DocumentManager.MdiActiveDocument.Editor;
                            ed.WriteMessage(
            string.Format("\n Add ContextMenu error: {0}", exc.Message));
                        }
                    }

                    
            private void BlkRefContextMenu_Popup(Object o, EventArgs e)
                    {
                        DocumentLock docLock 
            = Application.DocumentManager.MdiActiveDocument.LockDocument();

                        Editor ed 
            = Application.DocumentManager.MdiActiveDocument.Editor;
                        
            bool visible = true;

                        
            // If this is multiple selection, disabled the menu item.
                        PromptSelectionResult selectionRes = ed.SelectImplied();
                        
            if (selectionRes.Status == PromptStatus.OK)
                        {
                            ObjectId[] objIds 
            = selectionRes.Value.GetObjectIds();
                            
            if (objIds != null && objIds.Length > 1)
                            {
                                visible 
            = false;
                            }
                        }

                        ContextMenuExtension objContextMenu 
            = o as ContextMenuExtension;
                        
            if (objContextMenu != null)
                        {
                            
            foreach (MenuItem item in objContextMenu.MenuItems)
                            {
                                item.Enabled 
            = visible;
                            }
                        } 
                        
                        docLock.Dispose();
                    }

                    
            // CallbackOnClick
                    private void CallbackOnClick(Object o, EventArgs e)
                    {
                        DocumentLock docLock 
            = Application.DocumentManager.MdiActiveDocument.LockDocument();

                        HelloWorld(); 
            // Invoke this function

                        docLock.Dispose();
                    }

                    
            // You can change this function name 
                    [CommandMethod("HelloWorld")]
                    
            public void HelloWorld()
                    {
                        
            // Get current file name
                        string strFileName = Application.DocumentManager.MdiActiveDocument.Name;

                        
            // Get the selection block reference and block record  handle
                        string strBlkRefHandle = ("");
                        
            string strBlkRecHandle = ("");
                        Editor ed 
            = Application.DocumentManager.MdiActiveDocument.Editor;
                        PromptSelectionResult sSelResult 
            = ed.SelectImplied(); // ed.GetSelection();

                        
            if (sSelResult.Status == PromptStatus.OK)
                        {
                            ObjectId[] objectIDs 
            = sSelResult.Value.GetObjectIds();
                            
            if (objectIDs.Length == 1)
                            {
                                ObjectId blkRefID 
            = objectIDs[0];
                                
            if (blkRefID.IsValid)
                                {
                                    
            // Get handle
                                    Handle handle = blkRefID.Handle;
                                    strBlkRefHandle 
            = handle.ToString();

                                    Database db 
            = HostApplicationServices.WorkingDatabase;
                                    Transaction tr 
            = db.TransactionManager.StartTransaction();

                                    BlockReference blf 
            = (BlockReference)tr.GetObject(blkRefID, OpenMode.ForRead);
                                    
            if (blf is BlockReference)
                                    {
                                        ObjectId blkRecID 
            = blf.BlockTableRecord;
                                        
            if (blkRecID.IsValid)
                                            strBlkRecHandle 
            = blkRecID.Handle.ToString();
                                    }

                                    tr.Commit();
                                }
                            }
                        }

                        
            if (strFileName.Length > 0 && strBlkRefHandle.Length > 0 && strBlkRecHandle.Length > 0)
                        {
                            
            // Invoke external EXE 
                            System.Diagnostics.ProcessStartInfo info =
                                
            new System.Diagnostics.ProcessStartInfo(@"E:\work\ContextMenuApp\SimpleProject\bin\Release\SimpleProject.exe"); // Your exe path

                            
            // Pass three arguments
                            string sArg = strFileName + " " + strBlkRefHandle + " " + strBlkRecHandle; 
                            info.Arguments 
            = sArg;
                            System.Diagnostics.Process p 
            = System.Diagnostics.Process.Start(info);
                        }
                    }
                }
            }


            posted on 2010-05-29 23:17 Mike Song 閱讀(425) 評(píng)論(0)  編輯 收藏 引用


            只有注冊(cè)用戶登錄后才能發(fā)表評(píng)論。
            網(wǎng)站導(dǎo)航: 博客園   IT新聞   BlogJava   博問   Chat2DB   管理


            亚洲中文字幕无码久久2020| 三级韩国一区久久二区综合| 国产精品美女久久久m| 伊人久久综在合线亚洲2019| 色偷偷91久久综合噜噜噜噜| 久久天天躁狠狠躁夜夜96流白浆| 久久精品18| 久久精品国产亚洲网站| 久久人妻少妇嫩草AV蜜桃| 激情五月综合综合久久69| 偷偷做久久久久网站| 久久久久久a亚洲欧洲aⅴ| 无码人妻久久一区二区三区蜜桃 | 伊人色综合九久久天天蜜桃| www.久久热.com| 精品国产乱码久久久久软件| 精品国产乱码久久久久久浪潮| 久久精品国产99久久久| 久久精品国产亚洲AV久| 欧美成a人片免费看久久| 久久亚洲欧美日本精品| 性做久久久久久久| 久久婷婷五月综合97色直播 | 久久久久国产精品熟女影院| 日韩欧美亚洲综合久久| 久久一区二区三区免费| 精品人妻伦九区久久AAA片69| 国产精品青草久久久久婷婷 | 久久精品中文字幕大胸| 草草久久久无码国产专区| 97热久久免费频精品99| 久久国产精品77777| 无码人妻精品一区二区三区久久 | 日韩精品久久无码中文字幕 | 色青青草原桃花久久综合| 久久久久国产视频电影| 久久99久久无码毛片一区二区| 日本道色综合久久影院| 久久精品国产91久久麻豆自制 | 国内精品久久久久久久久电影网| 久久精品?ⅴ无码中文字幕|