• <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   管理


            日本高清无卡码一区二区久久| 欧美午夜A∨大片久久| 婷婷久久久亚洲欧洲日产国码AV| 波多野结衣久久精品| 久久久久久精品久久久久| 日韩精品久久久久久久电影蜜臀| 久久av无码专区亚洲av桃花岛| 久久噜噜电影你懂的| 日韩亚洲国产综合久久久| 久久无码AV一区二区三区| 久久99精品国产99久久6男男| 免费精品久久久久久中文字幕| 精品多毛少妇人妻AV免费久久| 99久久99久久精品国产| 亚洲国产精品一区二区三区久久| 2021精品国产综合久久| 欧美激情精品久久久久久久九九九 | 久久精品国产网红主播| 久久中文字幕无码专区 | 久久亚洲精品中文字幕三区| 久久无码一区二区三区少妇| 国产精品美女久久久m| 香蕉久久夜色精品国产尤物| 一本久久a久久精品综合夜夜| 无码人妻久久一区二区三区蜜桃| 777久久精品一区二区三区无码| 午夜天堂精品久久久久| 亚洲美日韩Av中文字幕无码久久久妻妇| 国产精品久久自在自线观看| 日产精品久久久久久久| 国产精品日韩欧美久久综合| 97久久香蕉国产线看观看| 午夜天堂av天堂久久久| 久久国语露脸国产精品电影| 久久WWW免费人成—看片| 色综合久久最新中文字幕| 国产精品久久久亚洲| 久久久久久午夜成人影院| 久久人人爽人人爽人人片av高请| 亚洲精品tv久久久久久久久| 亚洲欧美日韩久久精品|