1、利用.net編輯好AutoCAD的.dll文件,加載的方式有兩種。
(1)手動加載。打開AutoCAD,命令行輸入netload命令,選擇生成的.dll文件,可以實現加載。
(2)自動加載。找到AutoCAD安裝目錄路徑下的support文件下的acad20xx.lsp文件,用記事本或者notepad進行編輯,打開之后在第二行添加以下代碼:(符號必須是英文狀態的)
(command “netload” “C:\\Users\\Administrator\\Desktop\\xxxx.dll”)
添加后的文件內容如下:
(if (not (= (substr (ver) 1 11) "Visual LISP")) (load "acad2018doc.lsp"))
(command "netload" "C:\\Users\\Administrator\\Desktop\\NEWLayersAdd.dll")
;; Silent load.
(princ)
保存為lsp格式的文件即可,每次打開AutoCAD都會提示,是否加載xxx.dll文件,根據情況進行選擇。
2、加載dll之后利用委托,把編寫的Ribbon顯示出來。如果只是自動加載,並不能實現顯示,需要加載完畢之后才能顯示,這是順序問題。
void IExtensionApplication.Initialize() { Autodesk.Windows.ComponentManager.ItemInitialized += this.EventHandler(ComponentManager_ItemInitialized); } public void ComponentManager_ItemInitialized(object sender, RibbonItemEventArgs e) { if (Autodesk.Windows.ComponentManager.Ribbon != null) { createRibbon();//添加ribbon菜單的函數 Autodesk.Windows.ComponentManager.ItemInitialized -= this.EventHandler(ComponentManager_ItemInitialized); } } public static void createRibbon()//生成菜單的代碼 { //add ribbon here.. } public void Terminate() { }
現在就可以打開AutoCAD檢查一下自己編寫的成果吧。