ok so first you will find code of Userform and at second i've added code of "StandardAddInServer" which ncludes inventor events and therefrom the userform will be started
Code of Userform:
Imports System
Imports System.Type
Imports System.Activator
Imports System.Deployment
Imports System.Runtime.InteropServices
Imports System.Windows.Forms
Imports Inventor
Imports System.Resources
Imports System.Globalization
Imports System.ComponentModel
Imports myInvDrwEvents
<Assembly: NeutralResourcesLanguage("en-US")>
Namespace myInvDrwEvents
Partial Public Class FrmStart
'Version 1.0.1 - Updated to VisualStudio 2015 --> Version Angabe unter Projekteigenschaften->Ressource
Inherits Form
Public Shared sCS() As String = {"@@"} 'Separator
Public Const sRS As String = "@@" 'ReplaceString --> vbcrlf
Dim oApp As Inventor.Application
Dim blnStarted As Boolean = False
Sub New()
'MessageBox.Show("vor 'InitializeComponent()' Aufruf", "Sub New", Windows.Forms.MessageBoxButtons.OK, Windows.Forms.MessageBoxIcon.Information)
' This call is required by the designer.
InitializeComponent()
' Add any initialization after the InitializeComponent() call.
Try
oApp = Marshal.GetActiveObject("Inventor.Application")
Catch ex As Exception
Try
Dim invAppType As Type = GetTypeFromProgID("Inventor.Application")
oApp = CreateInstance(invAppType)
oApp.Visible = True
'Note: if you shut down the Inventor session that was started
'this(way) there is still an Inventor.exe running. We will use
'this Boolean to test whether or not the Inventor App will
'need to be shut down.
blnStarted = True
Catch ex2 As Exception
MsgBox(ex2.ToString())
MsgBox("Unable to get or start Inventor", "frmStart - New()")
End Try
End Try
End Sub
Private Sub frmStart_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
cFunctions.LogEvent("Bin in frmStart - frmStart_Load()",,,,, False)
'MessageBox.Show(GetVersionInfo(True), "Form1_Load", MessageBoxButtons.OK, MessageBoxIcon.Information)
If oApp.Documents.Count = 0 Then
MsgBox("Need to open an Drawing document")
Return
End If
If oApp.ActiveDocument.DocumentType <> DocumentTypeEnum.kDrawingDocumentObject Then
MsgBox("Need to have an Drawing document active")
Return
End If
Dim oDrawDoc As DrawingDocument
oDrawDoc = oApp.ActiveDocument
cFunctions.LogEvent(Space(5) & "Bin in frmStart - frmStart_Load() - nach 'Dim oDrawDoc As DrawingDocument' - oDrawDoc.DisplayName= " & oDrawDoc.DisplayName)
' Obtain a reference to the desired border defintion.
Dim oTitleBlockDef As TitleBlockDefinition
For Each oTitleBlockDef In oDrawDoc.TitleBlockDefinitions
cFunctions.LogEvent("Bin in frmStart - frmStart_Load() - oTitleBlockDef.Name:", oTitleBlockDef.Name)
Me.cboAuswahl.Items.Add(oTitleBlockDef.Name)
Next
'Dim oCI As CultureInfo = CultureInfo.CreateSpecificCulture("en-US")
Dim oCI As CultureInfo = CultureInfo.CurrentCulture
Dim oRM As New ResourceManager("myInvDrwEvents.Desc_" & oCI.Name, System.Reflection.Assembly.GetExecutingAssembly)
With Me
.Text = String.Concat(oRM.GetString("frmStart"), Space(1), GetVersionInfo(True)) 'My.Resources.Version)
.lblTmpFileName.Text = String.Concat(oRM.GetString("lblTempFileName"), Space(1), .lblTmpFileName.Text)
.Label0.Text = oRM.GetString("Label0")
.Label1.Text = oRM.GetString("Label1")
.Label2.Text = oRM.GetString("Label2")
.Label3.Text = oRM.GetString("Label3")
.Label4.Text = oRM.GetString("Label4")
.Label5.Text = oRM.GetString("Label5")
.Label6.Text = oRM.GetString("Label6")
.Label7.Text = oRM.GetString("Label7")
.Label8.Text = oRM.GetString("Label8")
.Label9.Text = oRM.GetString("Label9")
.Label10.Text = oRM.GetString("Label10")
.lblHoch.Text = oRM.GetString("lblHoch")
.lblQuer.Text = oRM.GetString("lblQuer")
.lblAuswahlTxt.Text = oRM.GetString("lblAuswahlTxt")
.btnCancel.Text = oRM.GetString("btnCancel")
.btnOK.Text = oRM.GetString("btnOk")
.gbEingabe.Text = oRM.GetString("gbEingabe")
.gbAuswahl.Text = oRM.GetString("gbAuswahl")
.gbBlattformat.Text = oRM.GetString("gbBlattformat")
.gbOrientierung.Text = oRM.GetString("gbOrientierung")
.rbDinA0.Text = oRM.GetString("rbDinA0")
.rbDinA1.Text = oRM.GetString("rbDinA1")
.rbDinA2.Text = oRM.GetString("cbDinA2")
.rbDinA3.Text = oRM.GetString("rbDinA3")
.rbDinA4.Text = oRM.GetString("rbDinA4")
.rbQuer.Text = oRM.GetString("rbQuer")
.rbHoch.Text = oRM.GetString("rbHoch")
.TextBox0.Text = Date.Now.ToString("d", CultureInfo.CurrentCulture) 'oRM.GetString("Textbox0") 'Bearb.-Datum
.TextBox1.Text = oRM.GetString("Textbox1") 'Maßstab
.TextBox2.Text = oRM.GetString("Textbox2") 'Ursprung
.TextBox3.Text = oRM.GetString("Textbox3") 'Fremdzeichnungsnr.
.TextBox4.Text = oRM.GetString("Textbox4") 'Werkstoff
.TextBox5.Text = oRM.GetString("Textbox5") 'Maßstab2
.TextBox6.Text = oRM.GetString("Textbox6") 'Gewicht - in Acad nicht verwendet
.TextBox7.Text = Year(Now()) 'oRM.GetString("Textbox7") 'Jahr
.TextBox8.Text = oRM.GetString("Textbox8").Replace(sRS, vbCrLf) 'Toleranz
Dim sRetStr As String = oRM.GetString("cboBearbeiter")
sRetStr = sRetStr.Replace(sRS & " ", sRS)
sRetStr = sRetStr.Replace(" " & sRS, sRS)
.cboBearbeiter.DataSource = sRetStr.Split(sCS, StringSplitOptions.RemoveEmptyEntries)
.AcceptButton = Me.btnOK
.CancelButton = Me.btnCancel
.gbEingabe.Visible = False
.btnCancel.Enabled = True
.btnOK.Enabled = False
.rbDinA0.Checked = True
'Einstellungen laden
Me.cboBearbeiter.Text = My.Settings.Bearbeiter
End With
End Sub
Private Sub frmStart_FormClosed(ByVal sender As Object, ByVal e As FormClosedEventArgs) Handles Me.FormClosed
If blnStarted Then
oApp.Quit()
End If
oApp = Nothing
End Sub
Private Sub btnCancel_Click(sender As System.Object, e As System.EventArgs) Handles btnCancel.Click
If blnStarted Then
oApp.Quit()
End If
Me.Close()
oApp = Nothing
End Sub
Private Sub btnOk_Click(sender As System.Object, e As System.EventArgs) Handles btnOK.Click
cFunctions.LogEvent("Bin in frmStart - btnOK_Click()")
If oApp.Documents.Count = 0 Then
MsgBox("Need to open an Drawing document")
Return
End If
If oApp.ActiveDocument.DocumentType <> DocumentTypeEnum.kDrawingDocumentObject Then
MsgBox("Need to have an Drawing document active")
Return
End If
Dim oDrawDoc As DrawingDocument
oDrawDoc = oApp.ActiveDocument
cFunctions.LogEvent(Space(5) & "Bin in frmStart - btnOK_Click() - nach 'Dim oDrawDoc As DrawingDocument' - oDrawDoc.DisplayName= " & oDrawDoc.DisplayName)
cFunctions.LogEvent(Space(5) & "Bin in frmStart - btnOK_Click() - vor 'Dim oTitleBlockDef As TitleBlockDefinition'")
' Obtain a reference to the desired border defintion.
Dim oTitleBlockDef As TitleBlockDefinition
oTitleBlockDef = oDrawDoc.TitleBlockDefinitions.Item(Me.cboAuswahl.SelectedItem.ToString)
cFunctions.LogEvent(Space(5) & "Bin in frmStart - btnOK_Click() - vor 'Dim oSheet As Sheet'")
Dim oSheet As Sheet
oSheet = oDrawDoc.ActiveSheet
cFunctions.LogEvent(Space(5) & "Bin in frmStart - btnOK_Click() - vor 'If Not oSheet.TitleBlock Is Nothing Then'")
' Check to see if the sheet already has a title block and delete it if it does.
If Not oSheet.TitleBlock Is Nothing Then
oSheet.TitleBlock.Delete()
End If
cFunctions.LogEvent(Space(5) & "Bin in frmStart - btnOK_Click() - vor 'Select Case CLng(Me.Tag)' - " & CLng(Me.Tag))
'Check and Set SheetSize and Orientation if neccessary
oSheet.Orientation = PageOrientationTypeEnum.kLandscapePageOrientation
Select Case CLng(Me.Tag)
Case 0
oSheet.Size = DrawingSheetSizeEnum.kA0DrawingSheetSize
Case 1
oSheet.Size = DrawingSheetSizeEnum.kA1DrawingSheetSize
Case 2
oSheet.Size = DrawingSheetSizeEnum.kA2DrawingSheetSize
Case 3
oSheet.Size = DrawingSheetSizeEnum.kA3DrawingSheetSize
Case 4
oSheet.Size = DrawingSheetSizeEnum.kA4DrawingSheetSize
If Me.rbHoch.Checked = True Then oSheet.Orientation = PageOrientationTypeEnum.kPortraitPageOrientation
End Select
cFunctions.LogEvent(Space(5) & "Bin in frmStart - btnOK_Click() - nach 'Select Case CLng(Me.Tag)'")
' This title block definition contains one prompted string input. An array
' must be input that contains the strings for the prompted strings.
Dim sPromptStrings(0 To 8) As String
Dim i As Integer
cFunctions.LogEvent(Space(5) & "Bin in frmStart - btnOK_Click() - vor 'For i = LBound(sPromptStrings) To UBound(sPromptStrings)' - i=" & LBound(sPromptStrings) & " To " & UBound(sPromptStrings))
For i = LBound(sPromptStrings) To UBound(sPromptStrings)
sPromptStrings(i) = " "
Next
' Add an instance of the title block definition to the sheet.
Dim oTitleBlock As TitleBlock
Dim oTextBox As Inventor.TextBox
cFunctions.LogEvent(Space(5) & "Bin in frmStart - btnOK_Click() - vor 'For Each oTextBox In oTitleBlock.Definition.Sketch.TextBoxes'")
oTitleBlock = oSheet.AddTitleBlock(oTitleBlockDef, , sPromptStrings)
Dim strGewicht = ""
If Not Me.TextBox6.Text.EndsWith("kg") Then strGewicht = String.Concat(Me.TextBox6.Text.Trim, " kg")
For Each oTextBox In oTitleBlock.Definition.Sketch.TextBoxes
'Debug.Print oTextBox.FormattedText
If InStr(1, oTextBox.FormattedText, "<ErstellDatum>") <> 0 Then Call oTitleBlock.SetPromptResultText(oTextBox, Me.TextBox0.Text)
If InStr(1, oTextBox.FormattedText, "<Maßstab>") <> 0 Then Call oTitleBlock.SetPromptResultText(oTextBox, Me.TextBox1.Text)
If InStr(1, oTextBox.FormattedText, "<Ursprung>") <> 0 Then Call oTitleBlock.SetPromptResultText(oTextBox, Me.TextBox2.Text)
If InStr(1, oTextBox.FormattedText, "<Fremdzeichnungsnr.:>") <> 0 Then Call oTitleBlock.SetPromptResultText(oTextBox, Me.TextBox3.Text)
If InStr(1, oTextBox.FormattedText, "<Werkstoff>") <> 0 Then Call oTitleBlock.SetPromptResultText(oTextBox, Me.TextBox4.Text)
If InStr(1, oTextBox.FormattedText, "<weitere Maßstäbe>") <> 0 Then Call oTitleBlock.SetPromptResultText(oTextBox, Me.TextBox5.Text)
If InStr(1, oTextBox.FormattedText, "<Gewicht>") <> 0 Then Call oTitleBlock.SetPromptResultText(oTextBox, strGewicht)
If InStr(1, oTextBox.FormattedText, "Jahr") <> 0 Then Call oTitleBlock.SetPromptResultText(oTextBox, Me.TextBox7.Text)
If InStr(1, oTextBox.FormattedText, "<Allg. Toleranz Iso 2768->") <> 0 Then Call oTitleBlock.SetPromptResultText(oTextBox, Me.TextBox8.Text)
Next
'Einstellungen speichern
My.Settings.Bearbeiter = Me.cboBearbeiter.Text
cFunctions.LogEvent(Space(5) & "Bin in frmStart - btnOK_Click() - nach Schleife oTitleBlock.Definition.Sketch.TextBoxes")
oApp.CommandManager.StartCommand(CommandIDEnum.kZoomAllCommand)
Me.Close()
End Sub
Private Sub cboAuswahl_SelectedIndexChanged(sender As System.Object, e As System.EventArgs) Handles cboAuswahl.SelectedIndexChanged
With Me
.gbEingabe.Visible = True
.TextBox1.Select()
.btnOK.Enabled = True
End With
End Sub
Private Sub rbDinA0_CheckedChanged(sender As System.Object, e As System.EventArgs) Handles rbDinA0.CheckedChanged
With Me
.rbQuer.Checked = True
.rbHoch.Enabled = False
.Tag = 0
End With
End Sub
Private Sub rbDinA1_CheckedChanged(sender As System.Object, e As System.EventArgs) Handles rbDinA1.CheckedChanged
With Me
.rbQuer.Checked = True
.rbHoch.Enabled = False
.Tag = 1
End With
End Sub
Private Sub rbDinA2_CheckedChanged(sender As System.Object, e As System.EventArgs) Handles rbDinA2.CheckedChanged
With Me
.rbQuer.Checked = True
.rbHoch.Enabled = False
.Tag = 2
End With
End Sub
Private Sub rbDinA3_CheckedChanged(sender As System.Object, e As System.EventArgs) Handles rbDinA3.CheckedChanged
With Me
.rbQuer.Checked = True
.rbHoch.Enabled = False
.Tag = 3
End With
End Sub
Private Sub rbDinA4_CheckedChanged(sender As System.Object, e As System.EventArgs) Handles rbDinA4.CheckedChanged
With Me
.rbHoch.Enabled = True
.rbHoch.Checked = True
.Tag = 4
End With
End Sub
Private Sub btnInfo_Click(sender As Object, e As EventArgs) Handles btnInfo.Click
MessageBox.Show(Me, GetVersionInfo(False), "myAcadEvents", MessageBoxButtons.OK, MessageBoxIcon.Information)
End Sub
Private Sub TextBox6_TextChanged(sender As System.Object, e As System.EventArgs)
'TextBox Gewicht
If Not IsNumeric(TextBox6.Text) Then TextBox6.Clear()
End Sub
#Region "frmStart_Designer"
Friend WithEvents TextBox6 As Windows.Forms.TextBox
Friend WithEvents lblQuer As Label
Friend WithEvents lblHoch As Label
Friend WithEvents rbQuer As RadioButton
Friend WithEvents cboBearbeiter As ComboBox
Friend WithEvents Label0 As Label
Friend WithEvents Label10 As Label
Friend WithEvents TextBox0 As Windows.Forms.TextBox
Friend WithEvents TextBox8 As Windows.Forms.TextBox
Friend WithEvents TextBox5 As Windows.Forms.TextBox
Friend WithEvents rbHoch As RadioButton
Friend WithEvents TextBox7 As Windows.Forms.TextBox
Friend WithEvents gbOrientierung As GroupBox
Friend WithEvents lblTmpFileName As Label
Friend WithEvents btnCancel As Button
Friend WithEvents btnOK As Button
Friend WithEvents TextBox4 As Windows.Forms.TextBox
Friend WithEvents btnInfo As Button
Friend WithEvents TextBox3 As Windows.Forms.TextBox
Friend WithEvents gbBlattformat As GroupBox
Friend WithEvents TextBox2 As Windows.Forms.TextBox
Friend WithEvents TextBox1 As Windows.Forms.TextBox
Friend WithEvents Label9 As Label
Friend WithEvents Label8 As Label
Friend WithEvents Label7 As Label
Friend WithEvents Label6 As Label
Friend WithEvents Label5 As Label
Friend WithEvents Label4 As Label
Friend WithEvents Label3 As Label
Friend WithEvents gbAuswahl As GroupBox
Friend WithEvents cboAuswahl As ComboBox
Friend WithEvents lblAuswahlTxt As Label
Friend WithEvents Label2 As Label
Friend WithEvents Label1 As Label
Friend WithEvents gbEingabe As GroupBox
Friend WithEvents rbDinA4 As RadioButton
Friend WithEvents rbDinA3 As RadioButton
Friend WithEvents rbDinA2 As RadioButton
Friend WithEvents rbDinA1 As RadioButton
Friend WithEvents rbDinA0 As RadioButton
Private Sub InitializeComponent()
Dim resources As System.ComponentModel.ComponentResourceManager = New System.ComponentModel.ComponentResourceManager(GetType(FrmStart))
Me.TextBox6 = New System.Windows.Forms.TextBox()
Me.lblQuer = New System.Windows.Forms.Label()
Me.lblHoch = New System.Windows.Forms.Label()
Me.rbQuer = New System.Windows.Forms.RadioButton()
Me.cboBearbeiter = New System.Windows.Forms.ComboBox()
Me.Label0 = New System.Windows.Forms.Label()
Me.Label10 = New System.Windows.Forms.Label()
Me.TextBox0 = New System.Windows.Forms.TextBox()
Me.TextBox8 = New System.Windows.Forms.TextBox()
Me.TextBox5 = New System.Windows.Forms.TextBox()
Me.rbHoch = New System.Windows.Forms.RadioButton()
Me.TextBox7 = New System.Windows.Forms.TextBox()
Me.gbOrientierung = New System.Windows.Forms.GroupBox()
Me.lblTmpFileName = New System.Windows.Forms.Label()
Me.btnCancel = New System.Windows.Forms.Button()
Me.btnOK = New System.Windows.Forms.Button()
Me.TextBox4 = New System.Windows.Forms.TextBox()
Me.btnInfo = New System.Windows.Forms.Button()
Me.TextBox3 = New System.Windows.Forms.TextBox()
Me.gbBlattformat = New System.Windows.Forms.GroupBox()
Me.rbDinA4 = New System.Windows.Forms.RadioButton()
Me.rbDinA3 = New System.Windows.Forms.RadioButton()
Me.rbDinA2 = New System.Windows.Forms.RadioButton()
Me.rbDinA1 = New System.Windows.Forms.RadioButton()
Me.rbDinA0 = New System.Windows.Forms.RadioButton()
Me.TextBox2 = New System.Windows.Forms.TextBox()
Me.TextBox1 = New System.Windows.Forms.TextBox()
Me.Label9 = New System.Windows.Forms.Label()
Me.Label8 = New System.Windows.Forms.Label()
Me.Label7 = New System.Windows.Forms.Label()
Me.Label6 = New System.Windows.Forms.Label()
Me.Label5 = New System.Windows.Forms.Label()
Me.Label4 = New System.Windows.Forms.Label()
Me.Label3 = New System.Windows.Forms.Label()
Me.gbAuswahl = New System.Windows.Forms.GroupBox()
Me.cboAuswahl = New System.Windows.Forms.ComboBox()
Me.lblAuswahlTxt = New System.Windows.Forms.Label()
Me.Label2 = New System.Windows.Forms.Label()
Me.Label1 = New System.Windows.Forms.Label()
Me.gbEingabe = New System.Windows.Forms.GroupBox()
Me.gbOrientierung.SuspendLayout()
Me.gbBlattformat.SuspendLayout()
Me.gbAuswahl.SuspendLayout()
Me.gbEingabe.SuspendLayout()
Me.SuspendLayout()
'
'TextBox6
'
Me.TextBox6.Location = New System.Drawing.Point(144, 191)
Me.TextBox6.Name = "TextBox6"
Me.TextBox6.Size = New System.Drawing.Size(208, 20)
Me.TextBox6.TabIndex = 14
Me.TextBox6.Tag = "Gewicht"
'
'lblQuer
'
Me.lblQuer.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle
Me.lblQuer.Font = New System.Drawing.Font("Microsoft Sans Serif", 14.25!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
Me.lblQuer.Location = New System.Drawing.Point(114, 75)
Me.lblQuer.Name = "lblQuer"
Me.lblQuer.Size = New System.Drawing.Size(32, 26)
Me.lblQuer.TabIndex = 3
Me.lblQuer.Text = "A"
Me.lblQuer.TextAlign = System.Drawing.ContentAlignment.MiddleCenter
'
'lblHoch
'
Me.lblHoch.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle
Me.lblHoch.Font = New System.Drawing.Font("Microsoft Sans Serif", 14.25!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
Me.lblHoch.Location = New System.Drawing.Point(114, 25)
Me.lblHoch.Name = "lblHoch"
Me.lblHoch.Size = New System.Drawing.Size(26, 32)
Me.lblHoch.TabIndex = 2
Me.lblHoch.Text = "A"
Me.lblHoch.TextAlign = System.Drawing.ContentAlignment.MiddleCenter
'
'rbQuer
'
Me.rbQuer.AutoSize = True
Me.rbQuer.Location = New System.Drawing.Point(6, 82)
Me.rbQuer.Name = "rbQuer"
Me.rbQuer.Size = New System.Drawing.Size(31, 17)
Me.rbQuer.TabIndex = 1
Me.rbQuer.TabStop = True
Me.rbQuer.Text = "q"
Me.rbQuer.UseVisualStyleBackColor = True
'
'cboBearbeiter
'
Me.cboBearbeiter.FormattingEnabled = True
Me.cboBearbeiter.Location = New System.Drawing.Point(144, 23)
Me.cboBearbeiter.Name = "cboBearbeiter"
Me.cboBearbeiter.Size = New System.Drawing.Size(208, 21)
Me.cboBearbeiter.TabIndex = 20
Me.cboBearbeiter.Tag = "Bearb-Name"
'
'Label0
'
Me.Label0.AutoSize = True
Me.Label0.Location = New System.Drawing.Point(15, 26)
Me.Label0.Name = "Label0"
Me.Label0.Size = New System.Drawing.Size(39, 13)
Me.Label0.TabIndex = 19
Me.Label0.Text = "Label0"
'
'Label10
'
Me.Label10.AutoSize = True
Me.Label10.Location = New System.Drawing.Point(358, 194)
Me.Label10.Name = "Label10"
Me.Label10.Size = New System.Drawing.Size(27, 13)
Me.Label10.TabIndex = 18
Me.Label10.Text = "bl10"
'
'TextBox0
'
Me.TextBox0.Location = New System.Drawing.Point(144, 47)
Me.TextBox0.Name = "TextBox0"
Me.TextBox0.Size = New System.Drawing.Size(208, 20)
Me.TextBox0.TabIndex = 17
Me.TextBox0.Tag = "Bearb-Datum"
'
'TextBox8
'
Me.TextBox8.Location = New System.Drawing.Point(144, 239)
Me.TextBox8.Name = "TextBox8"
Me.TextBox8.Size = New System.Drawing.Size(208, 20)
Me.TextBox8.TabIndex = 16
Me.TextBox8.Tag = "Toleranz"
'
'TextBox5
'
Me.TextBox5.Location = New System.Drawing.Point(144, 167)
Me.TextBox5.Name = "TextBox5"
Me.TextBox5.Size = New System.Drawing.Size(208, 20)
Me.TextBox5.TabIndex = 13
Me.TextBox5.Tag = "Maßstab2"
'
'rbHoch
'
Me.rbHoch.AutoSize = True
Me.rbHoch.Location = New System.Drawing.Point(6, 30)
Me.rbHoch.Name = "rbHoch"
Me.rbHoch.Size = New System.Drawing.Size(31, 17)
Me.rbHoch.TabIndex = 0
Me.rbHoch.TabStop = True
Me.rbHoch.Text = "h"
Me.rbHoch.UseVisualStyleBackColor = True
'
'TextBox7
'
Me.TextBox7.Location = New System.Drawing.Point(144, 215)
Me.TextBox7.Name = "TextBox7"
Me.TextBox7.Size = New System.Drawing.Size(208, 20)
Me.TextBox7.TabIndex = 15
Me.TextBox7.Tag = "Jahr"
'
'gbOrientierung
'
Me.gbOrientierung.Controls.Add(Me.lblQuer)
Me.gbOrientierung.Controls.Add(Me.lblHoch)
Me.gbOrientierung.Controls.Add(Me.rbQuer)
Me.gbOrientierung.Controls.Add(Me.rbHoch)
Me.gbOrientierung.Location = New System.Drawing.Point(218, 14)
Me.gbOrientierung.Name = "gbOrientierung"
Me.gbOrientierung.Size = New System.Drawing.Size(162, 168)
Me.gbOrientierung.TabIndex = 14
Me.gbOrientierung.TabStop = False
Me.gbOrientierung.Text = "GroupBox2"
'
'lblTmpFileName
'
Me.lblTmpFileName.AutoSize = True
Me.lblTmpFileName.Location = New System.Drawing.Point(174, 551)
Me.lblTmpFileName.Name = "lblTmpFileName"
Me.lblTmpFileName.Size = New System.Drawing.Size(82, 13)
Me.lblTmpFileName.TabIndex = 13
Me.lblTmpFileName.Text = "lblTmpFileName"
'
'btnCancel
'
Me.btnCancel.DialogResult = System.Windows.Forms.DialogResult.Cancel
Me.btnCancel.Location = New System.Drawing.Point(93, 546)
Me.btnCancel.Name = "btnCancel"
Me.btnCancel.Size = New System.Drawing.Size(75, 23)
Me.btnCancel.TabIndex = 12
Me.btnCancel.Text = "abbrechen"
Me.btnCancel.UseVisualStyleBackColor = True
'
'btnOK
'
Me.btnOK.Location = New System.Drawing.Point(12, 546)
Me.btnOK.Name = "btnOK"
Me.btnOK.Size = New System.Drawing.Size(75, 23)
Me.btnOK.TabIndex = 11
Me.btnOK.Text = "ok"
Me.btnOK.UseVisualStyleBackColor = True
'
'TextBox4
'
Me.TextBox4.Location = New System.Drawing.Point(144, 143)
Me.TextBox4.Name = "TextBox4"
Me.TextBox4.Size = New System.Drawing.Size(208, 20)
Me.TextBox4.TabIndex = 12
Me.TextBox4.Tag = "Werkstoff"
'
'btnInfo
'
Me.btnInfo.Image = CType(resources.GetObject("btnInfo.Image"), System.Drawing.Image)
Me.btnInfo.Location = New System.Drawing.Point(411, 1)
Me.btnInfo.Name = "btnInfo"
Me.btnInfo.Size = New System.Drawing.Size(24, 24)
Me.btnInfo.TabIndex = 15
Me.btnInfo.UseVisualStyleBackColor = True
'
'TextBox3
'
Me.TextBox3.Location = New System.Drawing.Point(144, 119)
Me.TextBox3.Name = "TextBox3"
Me.TextBox3.Size = New System.Drawing.Size(208, 20)
Me.TextBox3.TabIndex = 11
Me.TextBox3.Tag = "Fremdzeichnungsnummer"
'
'gbBlattformat
'
Me.gbBlattformat.Controls.Add(Me.rbDinA4)
Me.gbBlattformat.Controls.Add(Me.rbDinA3)
Me.gbBlattformat.Controls.Add(Me.rbDinA2)
Me.gbBlattformat.Controls.Add(Me.rbDinA1)
Me.gbBlattformat.Controls.Add(Me.rbDinA0)
Me.gbBlattformat.Location = New System.Drawing.Point(12, 12)
Me.gbBlattformat.Name = "gbBlattformat"
Me.gbBlattformat.Size = New System.Drawing.Size(200, 170)
Me.gbBlattformat.TabIndex = 8
Me.gbBlattformat.TabStop = False
Me.gbBlattformat.Text = "GroupBox1"
'
'rbDinA4
'
Me.rbDinA4.AutoSize = True
Me.rbDinA4.Location = New System.Drawing.Point(22, 135)
Me.rbDinA4.Name = "rbDinA4"
Me.rbDinA4.Size = New System.Drawing.Size(90, 17)
Me.rbDinA4.TabIndex = 4
Me.rbDinA4.TabStop = True
Me.rbDinA4.Text = "RadioButton5"
Me.rbDinA4.UseVisualStyleBackColor = True
'
'rbDinA3
'
Me.rbDinA3.AutoSize = True
Me.rbDinA3.Location = New System.Drawing.Point(22, 107)
Me.rbDinA3.Name = "rbDinA3"
Me.rbDinA3.Size = New System.Drawing.Size(90, 17)
Me.rbDinA3.TabIndex = 3
Me.rbDinA3.TabStop = True
Me.rbDinA3.Text = "RadioButton4"
Me.rbDinA3.UseVisualStyleBackColor = True
'
'rbDinA2
'
Me.rbDinA2.AutoSize = True
Me.rbDinA2.Location = New System.Drawing.Point(22, 79)
Me.rbDinA2.Name = "rbDinA2"
Me.rbDinA2.Size = New System.Drawing.Size(90, 17)
Me.rbDinA2.TabIndex = 2
Me.rbDinA2.TabStop = True
Me.rbDinA2.Text = "RadioButton3"
Me.rbDinA2.UseVisualStyleBackColor = True
'
'rbDinA1
'
Me.rbDinA1.AutoSize = True
Me.rbDinA1.Location = New System.Drawing.Point(22, 51)
Me.rbDinA1.Name = "rbDinA1"
Me.rbDinA1.Size = New System.Drawing.Size(90, 17)
Me.rbDinA1.TabIndex = 1
Me.rbDinA1.TabStop = True
Me.rbDinA1.Text = "RadioButton2"
Me.rbDinA1.UseVisualStyleBackColor = True
'
'rbDinA0
'
Me.rbDinA0.AutoSize = True
Me.rbDinA0.Location = New System.Drawing.Point(22, 23)
Me.rbDinA0.Name = "rbDinA0"
Me.rbDinA0.Size = New System.Drawing.Size(90, 17)
Me.rbDinA0.TabIndex = 0
Me.rbDinA0.TabStop = True
Me.rbDinA0.Text = "RadioButton1"
Me.rbDinA0.UseVisualStyleBackColor = True
'
'TextBox2
'
Me.TextBox2.Location = New System.Drawing.Point(144, 95)
Me.TextBox2.Name = "TextBox2"
Me.TextBox2.Size = New System.Drawing.Size(208, 20)
Me.TextBox2.TabIndex = 10
Me.TextBox2.Tag = "Ursprung"
'
'TextBox1
'
Me.TextBox1.Location = New System.Drawing.Point(144, 71)
Me.TextBox1.Name = "TextBox1"
Me.TextBox1.Size = New System.Drawing.Size(208, 20)
Me.TextBox1.TabIndex = 9
Me.TextBox1.Tag = "Maßstab"
'
'Label9
'
Me.Label9.AutoSize = True
Me.Label9.Location = New System.Drawing.Point(13, 242)
Me.Label9.Name = "Label9"
Me.Label9.Size = New System.Drawing.Size(39, 13)
Me.Label9.TabIndex = 8
Me.Label9.Text = "Label9"
'
'Label8
'
Me.Label8.AutoSize = True
Me.Label8.Location = New System.Drawing.Point(15, 218)
Me.Label8.Name = "Label8"
Me.Label8.Size = New System.Drawing.Size(39, 13)
Me.Label8.TabIndex = 7
Me.Label8.Text = "Label8"
'
'Label7
'
Me.Label7.AutoSize = True
Me.Label7.Location = New System.Drawing.Point(15, 194)
Me.Label7.Name = "Label7"
Me.Label7.Size = New System.Drawing.Size(39, 13)
Me.Label7.TabIndex = 6
Me.Label7.Text = "Label7"
'
'Label6
'
Me.Label6.AutoSize = True
Me.Label6.Location = New System.Drawing.Point(15, 170)
Me.Label6.Name = "Label6"
Me.Label6.Size = New System.Drawing.Size(39, 13)
Me.Label6.TabIndex = 5
Me.Label6.Text = "Label6"
'
'Label5
'
Me.Label5.AutoSize = True
Me.Label5.Location = New System.Drawing.Point(15, 146)
Me.Label5.Name = "Label5"
Me.Label5.Size = New System.Drawing.Size(39, 13)
Me.Label5.TabIndex = 4
Me.Label5.Text = "Label5"
'
'Label4
'
Me.Label4.AutoSize = True
Me.Label4.Location = New System.Drawing.Point(15, 122)
Me.Label4.Name = "Label4"
Me.Label4.Size = New System.Drawing.Size(39, 13)
Me.Label4.TabIndex = 3
Me.Label4.Text = "Label4"
'
'Label3
'
Me.Label3.AutoSize = True
Me.Label3.Location = New System.Drawing.Point(15, 98)
Me.Label3.Name = "Label3"
Me.Label3.Size = New System.Drawing.Size(39, 13)
Me.Label3.TabIndex = 2
Me.Label3.Text = "Label3"
'
'gbAuswahl
'
Me.gbAuswahl.Controls.Add(Me.cboAuswahl)
Me.gbAuswahl.Controls.Add(Me.lblAuswahlTxt)
Me.gbAuswahl.Location = New System.Drawing.Point(12, 188)
Me.gbAuswahl.Name = "gbAuswahl"
Me.gbAuswahl.Size = New System.Drawing.Size(413, 77)
Me.gbAuswahl.TabIndex = 9
Me.gbAuswahl.TabStop = False
Me.gbAuswahl.Text = "GroupBox1"
'
'cboAuswahl
'
Me.cboAuswahl.FormattingEnabled = True
Me.cboAuswahl.Location = New System.Drawing.Point(14, 39)
Me.cboAuswahl.Name = "cboAuswahl"
Me.cboAuswahl.Size = New System.Drawing.Size(258, 21)
Me.cboAuswahl.TabIndex = 1
'
'lblAuswahlTxt
'
Me.lblAuswahlTxt.AutoSize = True
Me.lblAuswahlTxt.Location = New System.Drawing.Point(11, 23)
Me.lblAuswahlTxt.Name = "lblAuswahlTxt"
Me.lblAuswahlTxt.Size = New System.Drawing.Size(94, 13)
Me.lblAuswahlTxt.TabIndex = 0
Me.lblAuswahlTxt.Text = "Schriftfeld wählen!"
'
'Label2
'
Me.Label2.AutoSize = True
Me.Label2.Location = New System.Drawing.Point(15, 74)
Me.Label2.Name = "Label2"
Me.Label2.Size = New System.Drawing.Size(39, 13)
Me.Label2.TabIndex = 1
Me.Label2.Text = "Label2"
'
'Label1
'
Me.Label1.AutoSize = True
Me.Label1.Location = New System.Drawing.Point(15, 50)
Me.Label1.Name = "Label1"
Me.Label1.Size = New System.Drawing.Size(39, 13)
Me.Label1.TabIndex = 0
Me.Label1.Text = "Label1"
'
'gbEingabe
'
Me.gbEingabe.Controls.Add(Me.cboBearbeiter)
Me.gbEingabe.Controls.Add(Me.Label0)
Me.gbEingabe.Controls.Add(Me.Label10)
Me.gbEingabe.Controls.Add(Me.TextBox0)
Me.gbEingabe.Controls.Add(Me.TextBox8)
Me.gbEingabe.Controls.Add(Me.TextBox7)
Me.gbEingabe.Controls.Add(Me.TextBox6)
Me.gbEingabe.Controls.Add(Me.TextBox5)
Me.gbEingabe.Controls.Add(Me.TextBox4)
Me.gbEingabe.Controls.Add(Me.TextBox3)
Me.gbEingabe.Controls.Add(Me.TextBox2)
Me.gbEingabe.Controls.Add(Me.TextBox1)
Me.gbEingabe.Controls.Add(Me.Label9)
Me.gbEingabe.Controls.Add(Me.Label8)
Me.gbEingabe.Controls.Add(Me.Label7)
Me.gbEingabe.Controls.Add(Me.Label6)
Me.gbEingabe.Controls.Add(Me.Label5)
Me.gbEingabe.Controls.Add(Me.Label4)
Me.gbEingabe.Controls.Add(Me.Label3)
Me.gbEingabe.Controls.Add(Me.Label2)
Me.gbEingabe.Controls.Add(Me.Label1)
Me.gbEingabe.Location = New System.Drawing.Point(12, 271)
Me.gbEingabe.Name = "gbEingabe"
Me.gbEingabe.Size = New System.Drawing.Size(413, 269)
Me.gbEingabe.TabIndex = 10
Me.gbEingabe.TabStop = False
Me.gbEingabe.Text = "GroupBox1"
'
'FrmStart
'
Me.ClientSize = New System.Drawing.Size(438, 584)
Me.Controls.Add(Me.gbOrientierung)
Me.Controls.Add(Me.lblTmpFileName)
Me.Controls.Add(Me.btnCancel)
Me.Controls.Add(Me.btnOK)
Me.Controls.Add(Me.btnInfo)
Me.Controls.Add(Me.gbBlattformat)
Me.Controls.Add(Me.gbAuswahl)
Me.Controls.Add(Me.gbEingabe)
Me.Icon = CType(resources.GetObject("$this.Icon"), System.Drawing.Icon)
Me.Name = "FrmStart"
Me.gbOrientierung.ResumeLayout(False)
Me.gbOrientierung.PerformLayout()
Me.gbBlattformat.ResumeLayout(False)
Me.gbBlattformat.PerformLayout()
Me.gbAuswahl.ResumeLayout(False)
Me.gbAuswahl.PerformLayout()
Me.gbEingabe.ResumeLayout(False)
Me.gbEingabe.PerformLayout()
Me.ResumeLayout(False)
Me.PerformLayout()
End Sub
#End Region
End Class
End Namespace
Code Of "StandardAddInServer"
Imports Inventor
Imports System.Runtime.InteropServices
Imports Microsoft.Win32
Imports System.Resources
Imports System.Globalization
Namespace myInvDrwEvents
<ProgIdAttribute("myInvDrwEvents.StandardAddInServer"), _
GuidAttribute("60d67787-5c1b-4a5f-9e4e-c1086ee6262c")> _
Public Class StandardAddInServer
Implements Inventor.ApplicationAddInServer
Private WithEvents m_uiEvents As UserInterfaceEvents
'Private WithEvents m_sampleButton As ButtonDefinition
' Inventor application object.
Private g_inventorApplication As Inventor.Application
Private WithEvents m_DocEvents As DocumentEvents
Private WithEvents m_AppEvents As ApplicationEvents
#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
' Initialize AddIn members.
g_inventorApplication = addInSiteObject.Application
' Connect to the user-interface events to handle a ribbon reset.
m_uiEvents = g_inventorApplication.UserInterfaceManager.UserInterfaceEvents
' TODO: Add button definitions.
' Sample to illustrate creating a button definition.
'Dim largeIcon As stdole.IPictureDisp = PictureDispConverter.ToIPictureDisp(My.Resources.YourBigImage)
'Dim smallIcon As stdole.IPictureDisp = PictureDispConverter.ToIPictureDisp(My.Resources.YourSmallImage)
'Dim controlDefs As Inventor.ControlDefinitions = g_inventorApplication.CommandManager.ControlDefinitions
'm_sampleButton = controlDefs.AddButtonDefinition("Command Name", "Internal Name", CommandTypesEnum.kShapeEditCmdType, AddInClientID)
' Add to the user interface, if it's the first time.
'If FirstTime Then
' AddToUserInterface()
'End If
m_AppEvents = g_inventorApplication.ApplicationEvents
'Windows.Forms.MessageBox.Show("ApplicationAddInServer - Activate", "Ende", Windows.Forms.MessageBoxButtons.OK, Windows.Forms.MessageBoxIcon.Information)
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
' TODO: Add ApplicationAddInServer.Deactivate implementation
' Release objects.
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.
Public ReadOnly Property Automation() As Object Implements Inventor.ApplicationAddInServer.Automation
Get
Return Nothing
End Get
End Property
' 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
End Sub
#End Region
#Region "User interface definition"
' Sub where the user-interface creation is done. This is called when
' the add-in loaded and also if the user interface is reset.
Private Shared Sub AddToUserInterface()
' This is where you'll add code to add buttons to the ribbon.
'** Sample to illustrate creating a button on a new panel of the Tools tab of the Part ribbon.
'' Get the part ribbon.
'Dim partRibbon As Ribbon = g_inventorApplication.UserInterfaceManager.Ribbons.Item("Part")
'' Get the "Tools" tab.
'Dim toolsTab As RibbonTab = partRibbon.RibbonTabs.Item("id_TabTools")
'' Create a new panel.
'Dim customPanel As RibbonPanel = toolsTab.RibbonPanels.Add("Sample", "MysSample", AddInClientID)
'' Add a button.
'customPanel.CommandControls.AddButton(m_sampleButton)
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
' MsgBox("Button was clicked.")
'End Sub
Private Sub m_AppEvents_OnNewDocument(DocumentObject As Inventor._Document, BeforeOrAfter As Inventor.EventTimingEnum, Context As Inventor.NameValueMap, ByRef HandlingCode As Inventor.HandlingCodeEnum) Handles m_AppEvents.OnNewDocument
Dim strTFN As String = ""
' Windows.Forms.MessageBox.Show(DocumentObject.DisplayName & " - Start", "m_AppEvents_OnNewDocument", Windows.Forms.MessageBoxButtons.OK, Windows.Forms.MessageBoxIcon.Information)
For i As Long = 1 To Context.Count
If Context.Name(i) = "TemplateFileName" Then
strTFN = System.IO.Path.GetFileName(Context.Value(Context.Name(i)).ToString)
End If
Next
Select Case BeforeOrAfter
Case EventTimingEnum.kBefore
'MessageBox.Show("Case Before: ")
Case EventTimingEnum.kAfter
If DocumentObject.DocumentType = DocumentTypeEnum.kDrawingDocumentObject Then
' Windows.Forms.MessageBox.Show("Case kAfter: ", "m_AppEvents_OnNewDocument", Windows.Forms.MessageBoxButtons.OK, Windows.Forms.MessageBoxIcon.Information)
Try
' Windows.Forms.MessageBox.Show("Before frmStart.Show()", "m_AppEvents_OnNewDocument", Windows.Forms.MessageBoxButtons.OK, Windows.Forms.MessageBoxIcon.Information)
Dim oForm As New FrmStart
oForm.lblTmpFileName.Text = strTFN
oForm.Show()
Catch ex As Exception
Windows.Forms.MessageBox.Show(ex.Message, "m_AppEvents_OnNewDocument", Windows.Forms.MessageBoxButtons.OK, Windows.Forms.MessageBoxIcon.Warning)
End Try
End If
Case Else
'no action
End Select
' Windows.Forms.MessageBox.Show(DocumentObject.DisplayName & " - Ende", "m_AppEvents_OnNewDocument", Windows.Forms.MessageBoxButtons.OK, Windows.Forms.MessageBoxIcon.Information)
End Sub
Private Sub m_AppEvents_OnActivateDocument(ByVal DocumentObject As Inventor._Document, ByVal BeforeOrAfter As Inventor.EventTimingEnum,
ByVal Context As Inventor.NameValueMap, ByRef HandlingCode As Inventor.HandlingCodeEnum) Handles m_AppEvents.OnActivateDocument
m_DocEvents = DocumentObject.DocumentEvents
If BeforeOrAfter <> EventTimingEnum.kAfter Then
Exit Sub
End If
' Windows.Forms.MessageBox.Show(DocumentObject.DisplayName, "OnActivateDocument VB - WithEvents", Windows.Forms.MessageBoxButtons.OK, Windows.Forms.MessageBoxIcon.Information)
End Sub
Private Sub m_DocEvents_OnActivate(BeforeOrAfter As Inventor.EventTimingEnum, Context As Inventor.NameValueMap, ByRef HandlingCode As Inventor.HandlingCodeEnum) Handles m_DocEvents.OnActivate
'Dim oApp As Inventor.Application
'oApp = Marshal.GetActiveObject("Inventor.Application")
'If BeforeOrAfter <> EventTimingEnum.kAfter Then
' Exit Sub
'End If
'Select Case oApp.ActiveDocumentType
' Case DocumentTypeEnum.kDrawingDocumentObject
' MessageBox.Show("Hallo ich bin eine idw!")
' Case DocumentTypeEnum.kAssemblyDocumentObject
' MessageBox.Show("Hallo ich bin eine iam!")
' Case DocumentTypeEnum.kPartDocumentObject
' MessageBox.Show("Hallo ich bin eine ipt!")
' Case Else
' MessageBox.Show("Hallo ich weiss nicht was ich bin!")
'End Select
'oApp = Nothing
End Sub
Private Sub m_DocEvents_OnSave(BeforeOrAfter As Inventor.EventTimingEnum, Context As Inventor.NameValueMap, ByRef HandlingCode As Inventor.HandlingCodeEnum) Handles m_DocEvents.OnSave
Dim oApp As Inventor.Application
oApp = Marshal.GetActiveObject("Inventor.Application")
If oApp.ActiveDocumentType = DocumentTypeEnum.kDrawingDocumentObject Then
Select Case BeforeOrAfter
Case EventTimingEnum.kBefore 'Event fired BEFORE native processing.
'MsgBox("VOR dem Speichern: irgendetwas machen", vbInformation, "AppEvent")
Call WriteScalesToTitleblock()
Call UpdateIndexes()
oApp.StatusBarText = "myInvDrwEvents: vor dem Speichern --> WriteScalesToTitleblock; UpdateIndexes"
Case EventTimingEnum.kAfter 'Event fired AFTER native processing.
'MsgBox("NACH dem Speichern: irgendetwas anderes machen", vbInformation, "AppEvent")
oApp.StatusBarText = "myInvDrwEvents: nach dem Speichern --> derzeit keine Aktionen"
Case EventTimingEnum.kAbort 'Event fired if the native processing ABORTED
'MsgBox("Speichervorgang abgebrochen", vbInformation, "AppEvent")
Call WriteScalesToTitleblock()
Call UpdateIndexes()
oApp.StatusBarText = "myInvDrwEvents: Speichern abgebrochen --> WriteScalesToTitleblock; UpdateIndexes"
End Select
End If
oApp = Nothing
End Sub
Shared Sub UpdateIndexes()
Dim oApp As Inventor.Application
Dim oDoc As Document
Dim oSkdSym As SketchedSymbol, oTxtBox As Inventor.TextBox, sIndex As String = ""
'Objekt herstellen
oApp = Marshal.GetActiveObject("Inventor.Application")
oDoc = oApp.ActiveDocument
'Funktioniert nur, wenn Drawing und mindestens eine Ansicht vorhanden ist:
If oDoc.DocumentType <> DocumentTypeEnum.kDrawingDocumentObject Then Exit Sub
If oDoc.ActiveSheet.DrawingViews.Count = 0 Then Exit Sub
For Each oSkdSym In oDoc.ActiveSheet.SketchedSymbols
With oSkdSym
If .Name = "Index" Then
For Each oTxtBox In .Definition.Sketch.TextBoxes
If Len(oTxtBox.Text) = 2 Then
'Debug.Print oSkdSym.GetResultText(oTxtBox)
If .GetResultText(oTxtBox) > sIndex Then sIndex = .GetResultText(oTxtBox)
End If
Next
End If
End With
Next
oDoc.PropertySets.Item("Design Tracking - Eigenschaften").Item("User Status").Value = sIndex
oDoc.Update()
oTxtBox = Nothing
oSkdSym = Nothing
oDoc = Nothing
oApp = Nothing
End Sub
Shared Sub WriteScalesToTitleblock()
Dim oApp As Inventor.Application
Dim oDoc As Document
Dim i, j, k As Integer
Dim dblMainScale As Double, dblMoreScales As Double, dblSiteScales(10) As Double
Dim sMainScale As String, sMoreScales As String
'Objekt herstellen
oApp = Marshal.GetActiveObject("Inventor.Application")
oDoc = oApp.ActiveDocument
'Funktioniert nur, wenn Drawing und mindestens eine Ansicht vorhanden ist:
If oDoc.DocumentType <> DocumentTypeEnum.kDrawingDocumentObject Then Exit Sub
If oDoc.ActiveSheet.DrawingViews.Count = 0 Then Exit Sub
'Ermittle die Hauptansicht und Hauptmaßstab
dblMainScale = oDoc.ActiveSheet.DrawingViews(1).Scale
'Ermittle weitere Ansichten
j = 0
For i = 1 To oDoc.ActiveSheet.DrawingViews.Count
'Ermittle weitere Maßstäbe
dblMoreScales = oDoc.ActiveSheet.DrawingViews(i).Scale
'Prüfe, ob gleich hauptmaßstab
If dblMoreScales <> dblMainScale Then
'Prüfe, ob schon als Nebenmaßstab vorhanden
If j > 0 Then
For k = 0 To j
If dblMoreScales = dblSiteScales(k) Then
dblMoreScales = 0
Exit For
End If
Next k
End If
If dblMoreScales <> 0 Then
'Nimm in die Liste auf
dblSiteScales(j) = dblMoreScales
j = j + 1
'Die liste ist begrenzt...
If j = 11 Then Exit For
End If
End If
Next i
'Grundmasstab setzen
sMainScale = EE_FormatScale(dblMainScale)
'weitere Massstäbe setzen
sMoreScales = ""
If j > 0 Then
For i = 0 To j - 1
sMoreScales = sMoreScales + EE_FormatScale(dblSiteScales(i))
If Not i = j - 1 Then sMoreScales = sMoreScales + ","
Next i
sMoreScales = "(" + sMoreScales + ")"
sMoreScales = Replace(sMoreScales, ",", ", ", 1, -1, vbTextCompare)
End If
Call WriteToTextBox("<Maßstab>", sMainScale)
Call WriteToTextBox("<weitere Maßstäbe>", sMoreScales)
oDoc = Nothing
oApp = Nothing
End Sub
Private Shared Function EE_FormatScale(ByVal S As Double) As String
If S >= 1 Then
If (10 * S Mod 10) = 0 Then
EE_FormatScale = Format(S, "0") + ":1"
Else
EE_FormatScale = Format(S, "0.0") + ":1"
End If
Else
If (10 * (1 / S) Mod 10) = 0 Then
EE_FormatScale = "1:" + Format(1 / S, "0")
Else
EE_FormatScale = "1:" + Format(1 / S, "0.0")
End If
End If
End Function
Shared Sub WriteToTextBox(sTBname As String, sTBvalue As String)
Dim oApp As Inventor.Application
Dim oDoc As Document, oTB As TitleBlock, oTxtBox As Inventor.TextBox
oApp = Marshal.GetActiveObject("Inventor.Application")
oDoc = oApp.ActiveDocument
oTB = oDoc.Sheets(1).TitleBlock
For Each oTxtBox In oTB.Definition.Sketch.TextBoxes
If oTxtBox.Text = sTBname Then
Call oTB.SetPromptResultText(oTxtBox, sTBvalue)
Exit For
End If
Next oTxtBox
oTxtBox = Nothing
oTB = Nothing
oDoc = Nothing
oApp = Nothing
End Sub
#End Region
End Class
End Namespace
Public Module Globals
' Inventor application object.
Public g_inventorApplication As Inventor.Application
#Region "Function to get the add-in client ID."
' This function uses reflection to get the GuidAttribute associated with the add-in.
Public Function AddInClientID() As String
Dim guid As String = ""
Try
Dim t As Type = GetType(myInvDrwEvents.StandardAddInServer)
Dim customAttributes() As Object = t.GetCustomAttributes(GetType(GuidAttribute), False)
Dim guidAttribute As GuidAttribute = CType(customAttributes(0), GuidAttribute)
guid = "{" + guidAttribute.Value.ToString() + "}"
Catch ex As Exception
End Try
Return guid
End Function
#End Region
#Region "hWnd Wrapper Class"
' This class is used to wrap a Win32 hWnd as a .Net IWind32Window class.
' This is primarily used for parenting a dialog to the Inventor window.
'
' For example:
' myForm.Show(New WindowWrapper(g_inventorApplication.MainFrameHWND))
'
Public Class WindowWrapper
Implements System.Windows.Forms.IWin32Window
Public Sub New(ByVal handle As IntPtr)
_hwnd = handle
End Sub
Public ReadOnly Property Handle() As IntPtr _
Implements System.Windows.Forms.IWin32Window.Handle
Get
Return _hwnd
End Get
End Property
Private _hwnd As IntPtr
End Class
#End Region
#Region "Image Converter"
' Class used to convert bitmaps and icons from their .Net native types into
' an IPictureDisp object which is what the Inventor API requires. A typical
' usage is shown below where MyIcon is a bitmap or icon that's available
' as a resource of the project.
'
' Dim smallIcon As stdole.IPictureDisp = PictureDispConverter.ToIPictureDisp(My.Resources.MyIcon)
Public NotInheritable Class PictureDispConverter
<DllImport("OleAut32.dll", EntryPoint:="OleCreatePictureIndirect", ExactSpelling:=True, PreserveSig:=False)>
Private Shared Function OleCreatePictureIndirect(
<MarshalAs(UnmanagedType.AsAny)> ByVal picdesc As Object,
ByRef iid As Guid,
<MarshalAs(UnmanagedType.Bool)> ByVal fOwn As Boolean) As stdole.IPictureDisp
End Function
Shared iPictureDispGuid As Guid = GetType(stdole.IPictureDisp).GUID
Private NotInheritable Class PICTDESC
Private Sub New()
End Sub
'Picture Types
Public Const PICTYPE_BITMAP As Short = 1
Public Const PICTYPE_ICON As Short = 3
<StructLayout(LayoutKind.Sequential)> _
Public Class Icon
Friend cbSizeOfStruct As Integer = Marshal.SizeOf(GetType(PICTDESC.Icon))
Friend picType As Integer = PICTDESC.PICTYPE_ICON
Friend hicon As IntPtr = IntPtr.Zero
Friend unused1 As Integer
Friend unused2 As Integer
Friend Sub New(ByVal icon As System.Drawing.Icon)
Me.hicon = icon.ToBitmap().GetHicon()
End Sub
End Class
<StructLayout(LayoutKind.Sequential)> _
Public Class Bitmap
Friend cbSizeOfStruct As Integer = Marshal.SizeOf(GetType(PICTDESC.Bitmap))
Friend picType As Integer = PICTDESC.PICTYPE_BITMAP
Friend hbitmap As IntPtr = IntPtr.Zero
Friend hpal As IntPtr = IntPtr.Zero
Friend unused As Integer
Friend Sub New(ByVal bitmap As System.Drawing.Bitmap)
Me.hbitmap = bitmap.GetHbitmap()
End Sub
End Class
End Class
Public Shared Function ToIPictureDisp(ByVal icon As System.Drawing.Icon) As stdole.IPictureDisp
Dim pictIcon As New PICTDESC.Icon(icon)
Return OleCreatePictureIndirect(pictIcon, iPictureDispGuid, True)
End Function
Public Shared Function ToIPictureDisp(ByVal bmp As System.Drawing.Bitmap) As stdole.IPictureDisp
Dim pictBmp As New PICTDESC.Bitmap(bmp)
Return OleCreatePictureIndirect(pictBmp, iPictureDispGuid, True)
End Function
End Class
#End Region
End Module