• <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 閱讀(420) 評(píng)論(0)  編輯 收藏 引用


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


            四虎国产精品免费久久5151| 久久久久久亚洲精品无码| 亚洲国产精品无码久久一线| 97精品依人久久久大香线蕉97| 亚洲国产另类久久久精品小说| 狠狠狠色丁香婷婷综合久久俺| 国产三级精品久久| 一本久久a久久精品综合香蕉| 亚洲中文字幕无码久久2017| 97精品伊人久久久大香线蕉| 香蕉久久AⅤ一区二区三区| 久久精品国产亚洲AV无码娇色| 国产精品久久久久久久午夜片 | 成人妇女免费播放久久久| 国内精品久久久久久久涩爱 | 久久99精品久久久久久| 亚洲Av无码国产情品久久| 韩国三级大全久久网站| 精品久久久久久中文字幕大豆网| 国产日韩欧美久久| 2021久久国自产拍精品| 亚洲AV成人无码久久精品老人| 久久免费国产精品| 欧美一区二区精品久久| 久久亚洲精品成人AV| 久久午夜无码鲁丝片秋霞| 国内精品久久久久影院优 | 久久精品卫校国产小美女| 久久久久人妻一区精品| 91久久香蕉国产熟女线看| 国产亚洲欧美成人久久片| 久久精品国产精品亚洲| 久久夜色精品国产| 女同久久| 日韩人妻无码精品久久久不卡| 久久久一本精品99久久精品88| 久久亚洲国产午夜精品理论片| 国产成人精品久久| 久久久精品国产免大香伊| 好久久免费视频高清| 色偷偷偷久久伊人大杳蕉|