Imports Autodesk.AutoCAD.DatabaseServices
Imports Autodesk.AutoCAD.EditorInput
Imports Autodesk.AutoCAD.Runtime
Imports Autodesk.AutoCAD.Geometry
Imports Autodesk.AutoCAD.Customization
Imports System
Imports System.Collections.Specialized
Namespace PartialCUI
Public Class Commands
Implements IExtensionApplication
Public Sub Initialize() Implements IExtensionApplication.Initialize
End Sub
Public Sub Terminate() Implements IExtensionApplication.Terminate
End Sub
<CommandMethod("M23")> _
Public Sub BuildMenuCUI()
Const myCuiFile As String = "c:\kean.cuix"
Const myCuiFileToSend As String = "c:/kean.cuix"
Const myCuiSectionName As String = "Kean"
Dim ed As Editor = Application.DocumentManager.MdiActiveDocument.Editor
Dim doc As Document = Application.DocumentManager.MdiActiveDocument
doc.SendStringToExecute("_.cuiunload KEAN ", False, False, False)
Dim mainCui As String = Application.GetSystemVariable("MENUNAME") + ".cuix"
Dim cs As New CustomizationSection(mainCui)
Dim pcfc As PartialCuiFileCollection = cs.PartialCuiFiles
'If pcfc.Contains(myCuiFile) Then
' ed.WriteMessage(vbLf & "Customization file """ + myCuiFile + """ already loaded.")
'Else
If System.IO.File.Exists(myCuiFile) Then
ed.WriteMessage(vbLf & "Customization file """ + myCuiFile + """ exists - loading it.")
LoadMyCui(myCuiFileToSend)
Else
ed.WriteMessage(vbLf & "Customization file """ + myCuiFile + """ does not exist - building it.")
' Create a customization section for our partial menu
Dim pcs As New CustomizationSection()
pcs.MenuGroupName = myCuiSectionName
' Let's add a menu group, with two commands
Dim mg As New MacroGroup(myCuiSectionName, pcs.MenuGroup)
Dim mm1 As New MenuMacro(mg, "Cmd 1", "^C^CCmd1", "ID_MyCmd1")
Dim mm2 As New MenuMacro(mg, "Cmd 2", "^C^CCmd2", "ID_MyCmd2")
' Now let's add a pull-down menu, with two items
Dim sc As New StringCollection()
sc.Add("POP15")
Dim pm As New PopMenu(myCuiSectionName, sc, "ID_MyPop1", pcs.MenuGroup)
Dim pmi1 As New PopMenuItem(mm1, "Pop Cmd 1", pm, -1)
Dim pmi2 As New PopMenuItem(mm2, "Pop Cmd 2", pm, -1)
' Finally we save the file and load it
pcs.SaveAs(myCuiFile)
LoadMyCui(myCuiFileToSend)
End If
'End If
End Sub
Private Sub LoadMyCui(ByVal cuiFile As String)
Dim doc As Document = Application.DocumentManager.MdiActiveDocument
Dim oldCmdEcho As Object = Application.GetSystemVariable("CMDECHO")
Dim oldFileDia As Object = Application.GetSystemVariable("FILEDIA")
Application.SetSystemVariable("CMDECHO", 0)
Application.SetSystemVariable("FILEDIA", 0)
doc.SendStringToExecute("_.cuiunload KEAN ", False, False, False)
doc.SendStringToExecute("_.cuiload " + cuiFile + " ", False, False, False)
doc.SendStringToExecute("(setvar ""FILEDIA"" " + oldFileDia.ToString() + ")(princ) ", False, False, False)
doc.SendStringToExecute("(setvar ""CMDECHO"" " + oldCmdEcho.ToString() + ")(princ) ", False, False, False)
Application.ReloadAllMenus()
End Sub
End Class
End Namespace
http://through-the-interface.typepad.com/throu ... 007/05/creating_a_part.html
[本日志由 tiancao1001 于 2018-09-15 05:52 PM 编辑]
|
暂时没有评论
发表评论 - 不要忘了输入验证码哦! |