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

            97久久久精品综合88久久| 久久久久久极精品久久久| 日韩久久久久久中文人妻| 国产亚洲欧美精品久久久| 久久电影网2021| 亚洲国产精品无码久久久久久曰| 久久精品国产99国产精品导航| 麻豆成人久久精品二区三区免费| 国产成人香蕉久久久久| 久久久久久国产精品美女 | 国产成人精品久久亚洲高清不卡 | 亚洲AV乱码久久精品蜜桃| 久久精品国产91久久麻豆自制| 亚洲精品无码久久久| 色综合色天天久久婷婷基地| 欧美伊人久久大香线蕉综合| 色综合色天天久久婷婷基地| 欧美黑人激情性久久| 亚洲欧美国产精品专区久久 | 一本色道久久99一综合| 久久久91人妻无码精品蜜桃HD| 国产三级久久久精品麻豆三级| 99久久这里只精品国产免费| 久久噜噜久久久精品66| 99久久精品免费看国产| 999久久久免费精品国产| 久久久久久午夜成人影院| 久久久久亚洲AV无码观看| 思思久久99热免费精品6| 久久99热这里只有精品国产 | 亚洲精品无码成人片久久| 久久久久久久免费视频| 亚洲欧洲中文日韩久久AV乱码| 久久精品无码一区二区三区日韩 | 精品国产一区二区三区久久蜜臀| 久久精品午夜一区二区福利| 99久久精品免费看国产一区二区三区| 香蕉99久久国产综合精品宅男自 | 午夜精品久久久久久久无码| 色综合久久中文字幕综合网| 一级做a爰片久久毛片看看|