wangjunqiang19820714 2018-09-05 02:51 采纳率: 0%
浏览 1270
已结题

用vb对SolidWorks二次开发插件,引用图片跟分割线怎么设定?

#Region "UI Methods"
Public Sub AddCommandMgr()

    Dim cmdGroup As ICommandGroup 'interface 接口 集合封装

    If iBmp Is Nothing Then
        iBmp = New BitmapHandler() '? 实例化
    End If

    Dim thisAssembly As Assembly '无冲突程序集

    Dim cmdIndex0 As Integer, cmdIndex1 As Integer
    Dim Title As String = "VS Addin"
    Dim ToolTip As String = "VB Addin"


    Dim docTypes() As Integer = {swDocumentTypes_e.swDocASSEMBLY, _
                                   swDocumentTypes_e.swDocDRAWING, _
                                   swDocumentTypes_e.swDocPART} '枚举 自定义集合 _e?

    thisAssembly = System.Reflection.Assembly.GetAssembly(Me.GetType())

    Dim cmdGroupErr As Integer = 0
    Dim ignorePrevious As Boolean = False

    Dim registryIDs As Object = Nothing
    Dim getDataResult As Boolean = iCmdMgr.GetGroupDataFromRegistry(mainCmdGroupID, registryIDs) '得到注册ID
    Dim knownIDs As Integer() = New Integer(1) {mainItemID1, mainItemID2}

    If getDataResult Then
        If Not CompareIDs(registryIDs, knownIDs) Then 'if the IDs don't match, reset the commandGroup
            ignorePrevious = True
        End If
    End If

    cmdGroup = iCmdMgr.CreateCommandGroup2(mainCmdGroupID, Title, ToolTip, "", -1, ignorePrevious, cmdGroupErr)
    If cmdGroup Is Nothing Or thisAssembly Is Nothing Then
        Throw New NullReferenceException() 'throw 手动抛出异常
    End If



    cmdGroup.LargeIconList = iBmp.CreateFileFromResourceBitmap("SwVBAddin1.ToolbarLarge.bmp", thisAssembly) '(位图名称,)
    cmdGroup.SmallIconList = iBmp.CreateFileFromResourceBitmap("SwVBAddin1.ToolbarSmall.bmp", thisAssembly)
    cmdGroup.LargeMainIcon = iBmp.CreateFileFromResourceBitmap("SwVBAddin1.MainIconLarge.bmp", thisAssembly)
    cmdGroup.SmallMainIcon = iBmp.CreateFileFromResourceBitmap("SwVBAddin1.MainIconSmall.bmp", thisAssembly)

    Dim menuToolbarOption As Integer = swCommandItemType_e.swMenuItem Or swCommandItemType_e.swToolbarItem

    cmdIndex0 = cmdGroup.AddCommandItem2("CreateCube", -1, "Create a cube", "Create cube", 0, "CreateCube", "", mainItemID1, menuToolbarOption)
    cmdIndex1 = cmdGroup.AddCommandItem2("Show PMP", -1, "Display sample property manager", "Show PMP", 2, "ShowPMP", "PMPEnable", mainItemID2, menuToolbarOption)

    cmdGroup.HasToolbar = True '工具窗口有一个工具栏
    cmdGroup.HasMenu = True
    cmdGroup.Activate()

    Dim flyGroup As FlyoutGroup '????????????
    flyGroup = iCmdMgr.CreateFlyoutGroup(flyoutGroupID, "Dynamic Flyout", "Flyout Tooltip", "Flyout Hint", _
          cmdGroup.SmallMainIcon, cmdGroup.LargeMainIcon, cmdGroup.SmallIconList, cmdGroup.LargeIconList, "FlyoutCallback", "FlyoutEnable")

    flyGroup.AddCommandItem("FlyoutCommand 1", "test", 0, "FlyoutCommandItem1", "FlyoutEnableCommandItem1")

    flyGroup.FlyoutType = swCommandFlyoutStyle_e.swCommandFlyoutStyle_Simple


    For Each docType As Integer In docTypes 'For Each <成员> In <数组>
        Dim cmdTab As ICommandTab = iCmdMgr.GetCommandTab(docType, Title)
        Dim bResult As Boolean

        If Not cmdTab Is Nothing And Not getDataResult Or ignorePrevious Then 'if tab exists, but we have ignored the registry info, re-create the tab.  Otherwise the ids won't matchup and the tab will be blank
            Dim res As Boolean = iCmdMgr.RemoveCommandTab(cmdTab)
            cmdTab = Nothing
        End If

        If cmdTab Is Nothing Then
            cmdTab = iCmdMgr.AddCommandTab(docType, Title)

            Dim cmdBox As CommandTabBox = cmdTab.AddCommandTabBox

            Dim cmdIDs(3) As Integer
            Dim TextType(3) As Integer

            cmdIDs(0) = cmdGroup.CommandID(cmdIndex0)
            TextType(0) = swCommandTabButtonTextDisplay_e.swCommandTabButton_TextHorizontal

            cmdIDs(1) = cmdGroup.CommandID(cmdIndex1)
            TextType(1) = swCommandTabButtonTextDisplay_e.swCommandTabButton_TextHorizontal

            cmdIDs(2) = cmdGroup.ToolbarId
            TextType(2) = swCommandTabButtonTextDisplay_e.swCommandTabButton_TextHorizontal


            bResult = cmdBox.AddCommands(cmdIDs, TextType)

            Dim cmdBox1 As CommandTabBox = cmdTab.AddCommandTabBox()
            ReDim cmdIDs(1) '动态数组
            ReDim TextType(1)

            cmdIDs(0) = flyGroup.CmdID
            TextType(0) = swCommandTabButtonTextDisplay_e.swCommandTabButton_TextBelow

            bResult = cmdBox1.AddCommands(cmdIDs, TextType)

            cmdTab.AddSeparator(cmdBox1, cmdIDs(0)) '增加分隔符

        End If
    Next

    thisAssembly = Nothing

End Sub


Public Sub RemoveCommandMgr()
    Try '调试可能异常代码
        iBmp.Dispose()
        iCmdMgr.RemoveCommandGroup(mainCmdGroupID)
        iCmdMgr.RemoveFlyoutGroup(flyoutGroupID)
    Catch e As Exception '错误跳入e
    End Try
End Sub


Function AddPMP() As Boolean
    ppage = New UserPMPage '大类UserPMPage
    ppage.Init(iSwApp, Me) '(sw,addin)
End Function

Function RemovePMP() As Boolean
    ppage = Nothing
End Function

Function CompareIDs(ByVal storedIDs() As Integer, ByVal addinIDs() As Integer) As Boolean

    Dim storeList As New List(Of Integer)(storedIDs) '类 List
    Dim addinList As New List(Of Integer)(addinIDs)

    addinList.Sort() '元素排序
    storeList.Sort()

    If Not addinList.Count = storeList.Count Then

        Return False
    Else

        For i As Integer = 0 To addinList.Count - 1
            If Not addinList(i) = storeList(i) Then

                Return False
            End If
        Next
    End If

    Return True
End Function

#End Region

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 微信公众号自制会员卡没有收款渠道啊
    • ¥15 stable diffusion
    • ¥100 Jenkins自动化部署—悬赏100元
    • ¥15 关于#python#的问题:求帮写python代码
    • ¥20 MATLAB画图图形出现上下震荡的线条
    • ¥15 关于#windows#的问题:怎么用WIN 11系统的电脑 克隆WIN NT3.51-4.0系统的硬盘
    • ¥15 perl MISA分析p3_in脚本出错
    • ¥15 k8s部署jupyterlab,jupyterlab保存不了文件
    • ¥15 ubuntu虚拟机打包apk错误
    • ¥199 rust编程架构设计的方案 有偿