Code:
in StandardAddInServer.vb:
Imports Inventor
Imports System.Runtime.InteropServices
Imports System
Imports System.Drawing
Imports System.Windows.Forms
Namespace HeiTol
Public Class StandardAddInServer
Implements Inventor.ApplicationAddInServer
Dim oForm1 As New Form1
#Region "Data Members"
Private WithEvents oButtonDef As ButtonDefinition
Dim InventorApplication As Inventor.Application
Dim oIconSmall As stdole.IPictureDisp
Dim oIconBig As stdole.IPictureDisp
Dim oSmall As Image
Dim oBig As Image
Dim opath As String
Dim ocommandbar As CommandBar
#End Region
#Region "ApplicationAddInServer Members"
Public Sub Activate(ByVal AddInSiteObject As Inventor.ApplicationAddInSite, ByVal FirstTime As Boolean) Implements Inventor.ApplicationAddInServer.Activate
'the Activate 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
'initialize AddIn members
InventorApplication = AddInSiteObject.Application
' TODO: Add ApplicationAddInServer.Activate implementation
'e.g. event initialization, command creation etc.
InventorApplication.CommandManager.ControlDefinitions.AddButtonDefinition("Schriftfeld", "Schriftfeld_einfügen:cmdintname1", CommandTypesEnum.kQueryOnlyCmdType, "{ID}"Test", "Test", smallico, largeico)
opath = System.Reflection.Assembly.GetExecutingAssembly().Location.ToString
opath = Left(opath, InStrRev(opath, "\"))
oSmall = System.Drawing.Image.FromFile(opath + "Hei.Small.bmp")
oBig = System.Drawing.Image.FromFile(opath + "Hei.Big.bmp")
'oIconSmall = stdole.IPictureDisp
'oIconBig = VB6.ImageToIPictureDisp(oBig)
oIconSmall = ImageToPictureConverter.Convert(oSmall)
oIconBig = ImageToPictureConverter.Convert(oBig)
oButtonDef = InventorApplication.CommandManager.ControlDefinitions.AddButtonDefinition("HeiTol", "SchriftfeldCmdIntName1", CommandTypesEnum.kShapeEditCmdType, "{2E68368E-1A9C-4F08-8429-B424A12C2364}", "Schriftfeld einfügen/bearbeiten", "Schriftfeld einfügen/bearbeiten", oIconSmall, oIconBig, ButtonDisplayEnum.kNoTextWithIcon)
oButtonDef.Enabled = True
' TODO: Add ApplicationAddInServer.Activate implementation
'e.g. event initialization, command creation etc.
If FirstTime = True Then
ocommandbar = InventorApplication.UserInterfaceManager.CommandBars.Add("ZeichnungSchriftfeld1", "ZeichnungIntName1", , ID)
Call ocommandbar.Controls.AddButton(oButtonDef)
Call ocommandbar.PanelBar.CommandBarList.Add(oButtonDef)
ocommandbar.Visible = True
End If
End Sub
Public Sub Deactivate() Implements Inventor.ApplicationAddInServer.Deactivate
'the Deactivate 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
' TODO: Add ApplicationAddInServer.Deactivate implementation
'e.g. command deletion
'release objects
Marshal.ReleaseComObject(InventorApplication)
InventorApplication = Nothing
System.GC.WaitForPendingFinalizers()
System.GC.Collect()
End Sub
Public ReadOnly Property Automation() As Object Implements Inventor.ApplicationAddInServer.Automation
'if you want to return an interface to another client of this addin,
'implement that interface in a class and return that class object
'through this property
Get
Return Nothing
End Get
End Property
Public Sub ExecuteCommand(ByVal CommandID As Integer) Implements Inventor.ApplicationAddInServer.ExecuteCommand
'this method was used to notify when an AddIn command was executed
'the CommandID parameter identifies the command that was executed
'Note:this method is now obsolete, you should use the new
'ControlDefinition objects to implement commands, they have
'their own event sinks to notify when the command is executed
End Sub
Public Sub oButtonDef_OnExecute(ByVal Context As Inventor.NameValueMap) Handles oButtonDef.OnExecute
oForm1.Show()
End Sub
#End Region
#Region "ImageToPictureConverter"
Public NotInheritable Class ImageToPictureConverter
Inherits System.Windows.Forms.AxHost
Private Sub New()
MyBase.New(Nothing)
End Sub
Public Shared Function Convert(ByVal image As System.Drawing.Image) As stdole.IPictureDisp
Return CType(System.Windows.Forms.AxHost.GetIPictureDispFromPicture(image), stdole.IPictureDisp)
End Function
End Class
#End Region
#Region "COM Registration"
' Registers this class as an Add-In for Autodesk Inventor.
' This function is called when the assembly is registered for COM.
<System.Runtime.InteropServices.ComRegisterFunction()> _
Public Shared Sub RegisterFunction(ByVal t As Type)
'call the method in the AddInRegistration class to register the AddIn
AddInRegistration.RegisterInventorAddIn(t)
End Sub
' Unregisters this class as an Add-In for Autodesk Inventor.
' This function is called when the assembly is unregistered.
<System.Runtime.InteropServices.ComUnregisterFunction()> _
Public Shared Sub UnregisterFunction(ByVal t As Type)
'call the method in the AddInRegistration class to unregister the AddIn
AddInRegistration.UnregisterInventorAddIn(t)
End Sub
#End Region
End Class
End Namespace
in Form1.vb:
Public Class Form1
Inherits System.Windows.Forms.Form
#Region " Vom Windows Form Designer generierter Code "
Public Sub New()
MyBase.New()
' Dieser Aufruf ist für den Windows Form-Designer erforderlich.
InitializeComponent()
' Initialisierungen nach dem Aufruf InitializeComponent() hinzufügen
End Sub
' Die Form überschreibt den Löschvorgang der Basisklasse, um Komponenten zu bereinigen.
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
If disposing Then
If Not (components Is Nothing) Then
components.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub
' Für Windows Form-Designer erforderlich
Private components As System.ComponentModel.IContainer
'HINWEIS: Die folgende Prozedur ist für den Windows Form-Designer erforderlich
'Sie kann mit dem Windows Form-Designer modifiziert werden.
'Verwenden Sie nicht den Code-Editor zur Bearbeitung.
Friend WithEvents GroupBox2 As System.Windows.Forms.GroupBox
Friend WithEvents but_7_70 As System.Windows.Forms.RadioButton
Friend WithEvents but_70_7 As System.Windows.Forms.RadioButton
Friend WithEvents GroupBox1 As System.Windows.Forms.GroupBox
Friend WithEvents but_Hh As System.Windows.Forms.RadioButton
Friend WithEvents but_gG As System.Windows.Forms.RadioButton
Friend WithEvents lstShaft As System.Windows.Forms.ListBox
Friend WithEvents lstHole As System.Windows.Forms.ListBox
Friend WithEvents Button1 As System.Windows.Forms.Button
Friend WithEvents lstTol As System.Windows.Forms.ListBox
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
Dim resources As System.Resources.ResourceManager = New System.Resources.ResourceManager(GetType(Form1))
Me.GroupBox2 = New System.Windows.Forms.GroupBox
Me.but_7_70 = New System.Windows.Forms.RadioButton
Me.but_70_7 = New System.Windows.Forms.RadioButton
Me.GroupBox1 = New System.Windows.Forms.GroupBox
Me.but_Hh = New System.Windows.Forms.RadioButton
Me.but_gG = New System.Windows.Forms.RadioButton
Me.lstShaft = New System.Windows.Forms.ListBox
Me.lstHole = New System.Windows.Forms.ListBox
Me.Button1 = New System.Windows.Forms.Button
Me.lstTol = New System.Windows.Forms.ListBox
Me.GroupBox2.SuspendLayout()
Me.GroupBox1.SuspendLayout()
Me.SuspendLayout()
'
'GroupBox2
'
Me.GroupBox2.Controls.Add(Me.but_7_70)
Me.GroupBox2.Controls.Add(Me.but_70_7)
Me.GroupBox2.Location = New System.Drawing.Point(229, 64)
Me.GroupBox2.Name = "GroupBox2"
Me.GroupBox2.Size = New System.Drawing.Size(50, 96)
Me.GroupBox2.TabIndex = 13
Me.GroupBox2.TabStop = False
'
'but_7_70
'
Me.but_7_70.Location = New System.Drawing.Point(8, 56)
Me.but_7_70.Name = "but_7_70"
Me.but_7_70.Size = New System.Drawing.Size(40, 32)
Me.but_7_70.TabIndex = 1
Me.but_7_70.Text = "7 70"
'
'but_70_7
'
Me.but_70_7.Checked = True
Me.but_70_7.Location = New System.Drawing.Point(8, 16)
Me.but_70_7.Name = "but_70_7"
Me.but_70_7.Size = New System.Drawing.Size(40, 32)
Me.but_70_7.TabIndex = 0
Me.but_70_7.TabStop = True
Me.but_70_7.Text = "70 7"
'
'GroupBox1
'
Me.GroupBox1.Controls.Add(Me.but_Hh)
Me.GroupBox1.Controls.Add(Me.but_gG)
Me.GroupBox1.Location = New System.Drawing.Point(165, 64)
Me.GroupBox1.Name = "GroupBox1"
Me.GroupBox1.Size = New System.Drawing.Size(50, 96)
Me.GroupBox1.TabIndex = 12
Me.GroupBox1.TabStop = False
'
'but_Hh
'
Me.but_Hh.Checked = True
Me.but_Hh.Location = New System.Drawing.Point(8, 16)
Me.but_Hh.Name = "but_Hh"
Me.but_Hh.Size = New System.Drawing.Size(32, 32)
Me.but_Hh.TabIndex = 4
Me.but_Hh.TabStop = True
Me.but_Hh.Text = "H h"
'
'but_gG
'
Me.but_gG.Location = New System.Drawing.Point(8, 56)
Me.but_gG.Name = "but_gG"
Me.but_gG.Size = New System.Drawing.Size(32, 32)
Me.but_gG.TabIndex = 5
Me.but_gG.Text = "h H"
'
'lstShaft
'
Me.lstShaft.Location = New System.Drawing.Point(13, 240)
Me.lstShaft.Name = "lstShaft"
Me.lstShaft.Size = New System.Drawing.Size(120, 17)
Me.lstShaft.Sorted = True
Me.lstShaft.TabIndex = 11
'
'lstHole
'
Me.lstHole.Location = New System.Drawing.Point(141, 240)
Me.lstHole.Name = "lstHole"
Me.lstHole.Size = New System.Drawing.Size(120, 17)
Me.lstHole.Sorted = True
Me.lstHole.TabIndex = 10
'
'Button1
'
Me.Button1.Location = New System.Drawing.Point(37, 192)
Me.Button1.Name = "Button1"
Me.Button1.Size = New System.Drawing.Size(120, 23)
Me.Button1.TabIndex = 9
Me.Button1.Text = "Tabelle erstellen"
'
'lstTol
'
Me.lstTol.Location = New System.Drawing.Point(37, 16)
Me.lstTol.Name = "lstTol"
Me.lstTol.Size = New System.Drawing.Size(120, 173)
Me.lstTol.TabIndex = 8
'
'Form1
'
Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
Me.ClientSize = New System.Drawing.Size(296, 269)
Me.Controls.Add(Me.GroupBox2)
Me.Controls.Add(Me.GroupBox1)
Me.Controls.Add(Me.lstShaft)
Me.Controls.Add(Me.lstHole)
Me.Controls.Add(Me.Button1)
Me.Controls.Add(Me.lstTol)
Me.Icon = CType(resources.GetObject("$this.Icon"), System.Drawing.Icon)
Me.Name = "Form1"
Me.Text = "HeiTolTab"
Me.GroupBox2.ResumeLayout(False)
Me.GroupBox1.ResumeLayout(False)
Me.ResumeLayout(False)
End Sub
End Class