Hot News:

Unser Angebot:

  Foren auf CAD.de (alle Foren)
  Inventor VBA
  AddIn soll in neuer Registerkarte angezeigt werden

Antwort erstellen  Neues Thema erstellen
CAD.de Login | Logout | Profil | Profil bearbeiten | Registrieren | Voreinstellungen | Hilfe | Suchen

Anzeige:

Darstellung des Themas zum Ausdrucken. Bitte dann die Druckfunktion des Browsers verwenden. | Suche nach Beiträgen nächster neuer Beitrag | nächster älterer Beitrag
  
Gut zu wissen: Hilfreiche Tipps und Tricks aus der Praxis prägnant, und auf den Punkt gebracht für Autodesk Produkte
Autor Thema:  AddIn soll in neuer Registerkarte angezeigt werden (360 mal gelesen)
Goose
Mitglied
Maschinenbautechniker / geb. Zerspanungsmechaniker Fachrichtung Frästechnik


Sehen Sie sich das Profil von Goose an!   Senden Sie eine Private Message an Goose  Schreiben Sie einen Gästebucheintrag für Goose

Beiträge: 202
Registriert: 29.03.2007

IV2021 R4
CATIA V6 R2013x

erstellt am: 09. Mrz. 2022 13:45    Editieren oder löschen Sie diesen Beitrag!  <-- editieren / zitieren -->   Antwort mit Zitat in Fett Antwort mit kursivem Zitat    Unities abgeben: 1 Unity (wenig hilfreich, aber dennoch)2 Unities3 Unities4 Unities5 Unities6 Unities7 Unities8 Unities9 Unities10 Unities

Hallo Zusammen,
das AddIn erzeugt jeweils (Part, Assembly und Drawing) in der Registerkarte Extras einen Button.
Ich würde würde gerne eine zusätzliche Registerkarte erstellen wo dieser Button dann verfügbar ist.
Hat da mal jemand eine Beispieldatei für mich!?

Danke und Gruß


Code:
Imports Inventor
Imports System.Runtime.InteropServices
Imports Microsoft.Win32

Namespace InventorAddinTest
    <ProgIdAttribute("InventorAddinTest.StandardAddInServer"), _
    GuidAttribute(g_simpleAddInClientID)> _
    Public Class StandardAddInServer
        Implements Inventor.ApplicationAddInServer

        '*********************************************************************************
        '* The two declarations below are related to adding buttons to Inventor's UI.
        '* They can be deleted if this add-in doesn't have a UI and only runs in the
        '* background handling events.
        '*********************************************************************************

        ' Declaration of the object for the UserInterfaceEvents to be able to handle
        ' if the user resets the ribbon so the button can be added back in.
        Private WithEvents m_uiEvents As UserInterfaceEvents

        ' Declaration of the button definition with events to handle the click event.
        ' For additional commands this declaration along with other sections of code
        ' that apply to the button can be duplicated from this example.
        Private WithEvents m_sampleButton As ButtonDefinition


#Region "ApplicationAddInServer Members"

        ' This method is called by Inventor when it loads the AddIn. The AddInSiteObject provides access 
        ' to the Inventor Application object. The FirstTime flag indicates if the AddIn is loaded for
        ' the first time. However, with the introduction of the ribbon this argument is always true.
        Public Sub Activate(ByVal addInSiteObject As Inventor.ApplicationAddInSite, ByVal firstTime As Boolean) Implements Inventor.ApplicationAddInServer.Activate
            Try
                ' Initialize AddIn members.
                g_inventorApplication = addInSiteObject.Application

                ' Connect to the user-interface events to handle a ribbon reset.
                m_uiEvents = g_inventorApplication.UserInterfaceManager.UserInterfaceEvents

                '*********************************************************************************
                '* The remaining code in this Sub is all for adding the add-in into Inventor's UI.
                '* It can be deleted if this add-in doesn't have a UI and only runs in the
                '* background handling events.
                '*********************************************************************************

                ' Create the button definition using the CreateButtonDefinition function to simplify this step.
                m_sampleButton = Utilities.CreateButtonDefinition("SET" & vbCr & "Prop", "niftyCommandID", "", "ButtonResources\SampleButton")

                ' Add to the user interface, if it's the first time.
                ' If this add-in doesn't have a UI but runs in the background listening
                ' to events, you can delete this.
                If firstTime Then
                    AddToUserInterface()
                End If
            Catch ex As Exception
                MsgBox("Unexpected failure in the activation of the add-in ""InventorAddinTest""" & vbCrLf & vbCrLf & ex.Message)
            End Try
        End Sub

        ' This method is called by Inventor when the AddIn is unloaded. The AddIn will be
        ' unloaded either manually by the user or when the Inventor session is terminated.
        Public Sub Deactivate() Implements Inventor.ApplicationAddInServer.Deactivate
            ' Release objects.
            m_sampleButton = Nothing
            m_uiEvents = Nothing
            g_inventorApplication = Nothing

            System.GC.Collect()
            System.GC.WaitForPendingFinalizers()
        End Sub

        ' This property is provided to allow the AddIn to expose an API of its own to other
        ' programs. Typically, this  would be done by implementing the AddIn's API
        ' interface in a class and returning that class object through this property.
        ' Typically it's not used, like in this case, and returns Nothing.
        Public ReadOnly Property Automation() As Object Implements Inventor.ApplicationAddInServer.Automation
            Get
                Return Nothing
            End Get
        End Property

        Public Property ThisApplication As Application

        ' Note:this method is now obsolete, you should use the
        ' ControlDefinition functionality for implementing commands.
        Public Sub ExecuteCommand(ByVal commandID As Integer) Implements Inventor.ApplicationAddInServer.ExecuteCommand
            ' Not used.
        End Sub

#End Region

#Region "User interface definition"
        ' Adds whatever is needed by this add-in to the user-interface.  This is
        ' called when the add-in loaded and also if the user interface is reset.
        Private Sub AddToUserInterface()
            ' This sample code illustrates creating a button on a new panel of the Tools tab of
            ' the Part ribbon. You'll need to change this to create the UI that your add-in needs.


            ' Get the part ribbon.
            Dim partRibbon As Ribbon = g_inventorApplication.UserInterfaceManager.Ribbons.Item("Part")

            ' Get the assembly ribbon.
            Dim assemblyRibbon As Ribbon = g_inventorApplication.UserInterfaceManager.Ribbons.Item("Assembly")

            ' Get the drawing ribbon.
            Dim DrawingRibbon As Ribbon = g_inventorApplication.UserInterfaceManager.Ribbons.Item("Drawing")

            ' Get the "Tools" tab.
            Dim toolsTab As RibbonTab = partRibbon.RibbonTabs.Item("id_TabTools")

            Dim toolsTabassembly As RibbonTab = assemblyRibbon.RibbonTabs.Item("id_TabTools")

            Dim toolsTabdrawing As RibbonTab = DrawingRibbon.RibbonTabs.Item("id_TabTools")

            ' Get the "Model" tab from the part ribbon.
            'Dim modelTab As Inventor.RibbonTab = assemblyRibbon.RibbonTabs.Item("id_TabModel")

            ' Get the "Modify" panel from the model tab.
            'Dim modifyPanel As Inventor.RibbonPanel = modelTab.RibbonPanels.Item("id_PanelP_ModelModify")


            Dim m_bulgeButton As ButtonDefinition = Nothing
            ' Add the button to the modify panel.
            'modifyPanel.CommandControls.AddButton(m_bulgeButton, True)

            Dim oUserInterfaceManager As UserInterfaceManager

            oUserInterfaceManager = g_inventorApplication.UserInterfaceManager

            Dim oInterfaceStyle As InterfaceStyleEnum

            oInterfaceStyle = oUserInterfaceManager.InterfaceStyle

            ' Check to see if the "MySample" panel already exists and create it if it doesn't.
            Dim customPanel As RibbonPanel = Nothing

                Dim customPanelassembly As RibbonPanel = Nothing

                Dim customPaneldrawing As RibbonPanel = Nothing

                Try
                    customPanel = toolsTab.RibbonPanels.Item("MyMFP")

                    customPanelassembly = toolsTabassembly.RibbonPanels.Item("MyMFP")

                    customPaneldrawing = toolsTabdrawing.RibbonPanels.Item("MyMFP")

                Catch ex As Exception
                End Try

                If customPanel Is Nothing Then

                    ' Create a new panel.
                    customPanel = toolsTab.RibbonPanels.Add("MFP", "MyMFP", g_addInClientID)


                End If

                If customPanelassembly Is Nothing Then

                    ' Create a new panel.

                    customPanelassembly = toolsTabassembly.RibbonPanels.Add("MFP", "MyMFP", g_addInClientID)

                End If

                If customPaneldrawing Is Nothing Then

                    ' Create a new panel.

                    customPaneldrawing = toolsTabdrawing.RibbonPanels.Add("MFP", "MyMFP", g_addInClientID)

                End If

            Dim firstTime As Boolean = Nothing

            If firstTime Then
                ' Get the part features command bar.
                Dim partCommandBar As Inventor.CommandBar
                partCommandBar = g_inventorApplication.UserInterfaceManager.CommandBars.Item(
"PMxPartFeatureCmdBar")
                Dim m_featureCountButtonDef As ButtonDefinition = Nothing
                ' Add a button to the command bar, defaulting to the end position.
                partCommandBar.Controls.AddButton(m_featureCountButtonDef)
            End If

            ' Add a button.
            If Not m_sampleButton Is Nothing Then

                    customPanel.CommandControls.AddButton(m_sampleButton, True)

                    customPanelassembly.CommandControls.AddButton(m_sampleButton, True)

                    customPaneldrawing.CommandControls.AddButton(m_sampleButton, True)
                End If


        End Sub

        Private Sub m_uiEvents_OnResetRibbonInterface(Context As NameValueMap) Handles m_uiEvents.OnResetRibbonInterface
            ' The ribbon was reset, so add back the add-ins user-interface.
            AddToUserInterface()

        End Sub

        ' Sample handler for the button.
        Private Sub m_sampleButton_OnExecute(Context As NameValueMap) Handles m_sampleButton.OnExecute
            SetPROP()
        End Sub
#End Region

    End Class
End Namespace


Public Module Globals
    ' Inventor application object.
    Public g_inventorApplication As Inventor.Application

    ' The unique ID for this add-in.  If this add-in is copied to create a new add-in
    ' you need to update this ID along with the ID in the .manifest file, the .addin file
    ' and create a new ID for the typelib GUID in AssemblyInfo.vb
    Public Const g_simpleAddInClientID As String = "647237d2-0e27-486f-b901-6903c6913aab"
    Public Const g_addInClientID As String = "{" & g_simpleAddInClientID & "}"
End Module


Eine Antwort auf diesen Beitrag verfassen (mit Zitat/Zitat des Beitrags) IP

rkauskh
Moderator
Dipl.-Ing. (FH) Versorgungstechnik




Sehen Sie sich das Profil von rkauskh an!   Senden Sie eine Private Message an rkauskh  Schreiben Sie einen Gästebucheintrag für rkauskh

Beiträge: 2166
Registriert: 15.11.2006

Windows 10 x64, AIP 2022

erstellt am: 09. Mrz. 2022 14:59    Editieren oder löschen Sie diesen Beitrag!  <-- editieren / zitieren -->   Antwort mit Zitat in Fett Antwort mit kursivem Zitat    Unities abgeben: 1 Unity (wenig hilfreich, aber dennoch)2 Unities3 Unities4 Unities5 Unities6 Unities7 Unities8 Unities9 Unities10 Unities Nur für Goose 10 Unities + Antwort hilfreich

Hallo

Einfach einen neuen RibbonTab im jeweiligen Ribbon.RibbonTabs erstellen.

Code:
RibbonTabs.Add( DisplayName As String, InternalName As String, ClientId As String, [TargetTabInternalName] As String, [InsertBeforeTargetTab] As Boolean, [Contextual] As Boolean ) As RibbonTab

Also statt

Code:

' Get the "Tools" tab.
Dim toolsTab As RibbonTab = partRibbon.RibbonTabs.Item("id_TabTools")
Dim toolsTabassembly As RibbonTab = assemblyRibbon.RibbonTabs.Item("id_TabTools")
Dim toolsTabdrawing As RibbonTab = DrawingRibbon.RibbonTabs.Item("id_TabTools")

Code:

Dim myTabPart As RibbonTab = partRibbon.RibbonTabs.Add("myTab",...)
Dim myTabAssembly As RibbonTab = assemblyRibbon.RibbonTabs.Item("myTab",...)
Dim myTabDrawing As RibbonTab = DrawingRibbon.RibbonTabs.Item("myTab",...)


------------------
MfG
Ralf

RKW Solutions GmbH
www.RKW-Solutions.com

Eine Antwort auf diesen Beitrag verfassen (mit Zitat/Zitat des Beitrags) IP

Anzeige.:

Anzeige: (Infos zum Werbeplatz >>)

Darstellung des Themas zum Ausdrucken. Bitte dann die Druckfunktion des Browsers verwenden. | Suche nach Beiträgen

nächster neuerer Beitrag | nächster älterer Beitrag
Antwort erstellen


Diesen Beitrag mit Lesezeichen versehen ... | Nach anderen Beiträgen suchen | CAD.de-Newsletter

Administrative Optionen: Beitrag schliessen | Archivieren/Bewegen | Beitrag melden!

Fragen und Anregungen: Kritik-Forum | Neues aus der Community: Community-Forum

(c)2023 CAD.de | Impressum | Datenschutz