В общем нужно чтобы отрабатывались все методы библиотеки которые выполняются при компиляции этой самой библиотеки, при событии винформы например онклик.
| Код | Imports System Imports System.Collections Imports System.Reflection Imports System.Runtime.InteropServices
Imports SolidWorks.Interop.sldworks Imports SolidWorks.Interop.swconst Imports SolidWorks.Interop.swpublished Imports SolidWorksTools Imports SolidWorksTools.File
<Guid("58c68ff3-be36-4a9a-bb29-2ef89642385d")> _ <ComVisible(True)> _ <SwAddin( _ Description:="SwVBAddin description", _ Title:="SwVBAddin", _ LoadAtStartup:=True _ )> _ Public Class SwAddin Implements SolidWorks.Interop.swpublished.SwAddin
#Region "Local Variables" Dim WithEvents iSwApp As SldWorks Dim iCmdMgr As ICommandManager Dim addinID As Integer Dim openDocs As Hashtable Dim SwEventPtr As SldWorks 'Dim ppage As UserPMPage
' Public Properties ReadOnly Property SwApp() As SldWorks Get Return iSwApp End Get End Property
ReadOnly Property CmdMgr() As ICommandManager Get Return iCmdMgr End Get End Property
ReadOnly Property OpenDocumentsTable() As Hashtable Get Return openDocs End Get End Property #End Region #Region "SolidWorks Registration"
<ComRegisterFunction()> Public Shared Sub RegisterFunction(ByVal t As Type) ' Get Custom Attribute: SwAddinAttribute Dim attributes() As Object Dim SWattr As SwAddinAttribute = Nothing
attributes = System.Attribute.GetCustomAttributes(GetType(SwAddin), GetType(SwAddinAttribute))
If attributes.Length > 0 Then SWattr = DirectCast(attributes(0), SwAddinAttribute) End If
Dim hklm As Microsoft.Win32.RegistryKey = Microsoft.Win32.Registry.LocalMachine Dim hkcu As Microsoft.Win32.RegistryKey = Microsoft.Win32.Registry.CurrentUser
Dim keyname As String = "SOFTWARE\SolidWorks\Addins\{" + t.GUID.ToString() + "}" Dim addinkey As Microsoft.Win32.RegistryKey = hklm.CreateSubKey(keyname) addinkey.SetValue(Nothing, 0) addinkey.SetValue("Description", SWattr.Description) addinkey.SetValue("Title", SWattr.Title)
keyname = "Software\SolidWorks\AddInsStartup\{" + t.GUID.ToString() + "}" addinkey = hkcu.CreateSubKey(keyname) addinkey.SetValue(Nothing, SWattr.LoadAtStartup, Microsoft.Win32.RegistryValueKind.DWord) End Sub <ComUnregisterFunction()> Public Shared Sub UnregisterFunction(ByVal t As Type) Dim hklm As Microsoft.Win32.RegistryKey = Microsoft.Win32.Registry.LocalMachine Dim hkcu As Microsoft.Win32.RegistryKey = Microsoft.Win32.Registry.CurrentUser
Dim keyname As String = "SOFTWARE\SolidWorks\Addins\{" + t.GUID.ToString() + "}" hklm.DeleteSubKey(keyname)
keyname = "Software\SolidWorks\AddInsStartup\{" + t.GUID.ToString() + "}" hkcu.DeleteSubKey(keyname) End Sub #End Region #Region "ISwAddin Implementation"
Function ConnectToSW(ByVal ThisSW As Object, ByVal Cookie As Integer) As Boolean Implements SolidWorks.Interop.swpublished.SwAddin.ConnectToSW iSwApp = ThisSW addinID = Cookie
' Setup callbacks iSwApp.SetAddinCallbackInfo(0, Me, addinID)
' Setup the Command Manager iCmdMgr = iSwApp.GetCommandManager(Cookie) AddCommandMgr()
'Setup the Event Handlers SwEventPtr = iSwApp openDocs = New Hashtable 'AttachEventHandlers()
'Setup Sample Property Manager
ConnectToSW = True End Function
Function DisconnectFromSW() As Boolean Implements SolidWorks.Interop.swpublished.SwAddin.DisconnectFromSW RemoveCommandMgr() 'DetachEventHandlers() iSwApp = Nothing 'The addin _must_ call GC.Collect() here in order to retrieve all managed code pointers GC.Collect() DisconnectFromSW = True End Function #End Region
#Region "UI Methods" Public Sub AddCommandMgr()
Dim cmdGroup As ICommandGroup Dim iBmp As New BitmapHandler Dim thisAssembly As Assembly
Dim cmdIndex0 As Integer Dim Title As String = "Свойства" Dim ToolTip As String = "Удалить"
Dim docTypes() As Integer = {swDocumentTypes_e.swDocASSEMBLY, _ swDocumentTypes_e.swDocDRAWING, _ swDocumentTypes_e.swDocPART} thisAssembly = System.Reflection.Assembly.GetAssembly(Me.GetType())
cmdGroup = iCmdMgr.CreateCommandGroup(1, Title, ToolTip, "", -1)
cmdIndex0 = cmdGroup.AddCommandItem("Конструктор свойств", -1, "Конструктор свойств", "Конструктор свойств", 0, "CreateCube", "", 0) 'cmdIndex1 = cmdGroup.AddCommandItem("Show PMP", -1, "Display sample property manager", "Show PMP", 2, "ShowPMP", "PMPEnable", 2)
cmdGroup.HasToolbar = False cmdGroup.HasMenu = True cmdGroup.Activate()
thisAssembly = Nothing 'iBmp.Dispose() End Sub Public Sub RemoveCommandMgr() iCmdMgr.RemoveCommandGroup(1) End Sub #End Region Sub CreateCube() Shell("C:\Program Files\SolidWorks Corp\SolidWorks\Addins\Конструктор свойств.exe", AppWinStyle.NormalFocus) End Sub End Class
|
|