• <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, 評論 - 21, 引用 - 0
            數據加載中……

            AutoCAD: 添加鼠標右鍵

            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) 評論(0)  編輯 收藏 引用

            精品久久久久中文字| 亚洲va久久久噜噜噜久久男同| 久久久精品日本一区二区三区| 精品熟女少妇a∨免费久久| 久久婷婷午色综合夜啪| 久久亚洲精品无码aⅴ大香| 久久国产免费| 久久久久国色AV免费看图片| 亚洲国产精品一区二区久久| 97久久久精品综合88久久| 69久久精品无码一区二区| 国产成人久久激情91| 久久国产精品久久精品国产| 久久国产亚洲高清观看| 97久久综合精品久久久综合| 亚洲国产精品无码久久一线| 久久夜色精品国产噜噜麻豆| WWW婷婷AV久久久影片| 久久精品九九亚洲精品天堂| 久久99国产精品99久久| 国产欧美久久久精品| 国产免费久久精品99久久| 国产精品成人久久久久三级午夜电影| 99久久精品国产一区二区| 色8激情欧美成人久久综合电| 亚洲国产香蕉人人爽成AV片久久| 99久久做夜夜爱天天做精品| 无码精品久久久久久人妻中字 | 99久久99久久| 7国产欧美日韩综合天堂中文久久久久| 久久综合久久综合九色| 亚洲国产成人精品91久久久 | 性高湖久久久久久久久AAAAA | 国产亚洲精久久久久久无码| 国产亚洲婷婷香蕉久久精品| 久久久久这里只有精品| 久久这里只有精品首页| 亚洲伊人久久大香线蕉苏妲己| 色综合合久久天天给综看| 久久丫精品国产亚洲av不卡| 国产精品久久久天天影视香蕉|