Imports Inventor Public Class Form1 Private inCustomDlg As Boolean Private WithEvents oEvents As FileUIEvents Private ofd As New OpenFileDialog With {.Multiselect = True, .InitialDirectory = "G:\900-Inv-Kataloge\001-INV-64-2015\Templates\Heitz\", .CheckFileExists = True, .Filter = "Inventor-Dateien|*.idw|Alle" & "Dateien|*.*"} Dim path As String = "" Dim idw As String = "" Dim Model As String = "" Dim filelist As New List(Of String) Dim openFileDialog1 As New OpenFileDialog() Dim FolderBrowser As New FolderBrowserDialog Dim WithEvents btnDateiöffnen As New Button With {.Parent = Me, .Width = 200, .Text = "ipt Öffnen"} Dim WithEvents btnVorlagewählen As New Button With {.Parent = Me, .Top = 40, .Width = 200, .Text = "idv Vorlage wählen"} Dim WithEvents cboVorlage As New ComboBox With {.Parent = Me, .DropDownStyle = ComboBoxStyle.DropDownList, .Top = 80, .Width = 200} Dim WithEvents cboModel As New ComboBox With {.Parent = Me, .DropDownStyle = ComboBoxStyle.DropDownList, .Top = 120, .Width = 200} Dim WithEvents btnZeichnungerstellen As New Button With {.Parent = Me, .Top = 160, .Width = 200, .Text = "Zeichnung erstellen"} Private Sub btnDateiöffne_Click(sender As Object, e As System.EventArgs) Handles btnDateiöffnen.Click ' Überprüfen ob Inventor geöffnet ist. Try Dim invApp As Application = System.Runtime.InteropServices.Marshal.GetActiveObject("Inventor.Application") Catch ex As Exception MessageBox.Show("Inventor must Gestartet sein.", "Fehler", MessageBoxButtons.OK, MessageBoxIcon.Error) Exit Sub End Try ' Bauteil unsichtbar Öffnen Dim m_inventorApp As Application = System.Runtime.InteropServices.Marshal.GetActiveObject("Inventor.Application") Dim oDesignProjectMgr As DesignProjectManager oDesignProjectMgr = m_inventorApp.DesignProjectManager Dim Arbeitsbereich As String Arbeitsbereich = oDesignProjectMgr.ActiveDesignProject.WorkspacePath FolderBrowser.Description = "idw Ordner wählen ..." FolderBrowser.ShowNewFolderButton = True FolderBrowser.RootFolder = System.Environment.SpecialFolder.Desktop FolderBrowser.SelectedPath = Arbeitsbereich openFileDialog1.Filter = "Inventor Files (*.iam;*.ipt)|*.iam;*.ipt|All Files (*.*)|*.*" openFileDialog1.Title = "Datei Öffnen" openFileDialog1.InitialDirectory = Arbeitsbereich openFileDialog1.Multiselect = True With openFileDialog1 If openFileDialog1.ShowDialog() = System.Windows.Forms.DialogResult.Cancel Then Exit Sub If .FileNames.Count = 0 Then Exit Sub filelist.Clear() cboModel.DataSource = Nothing path = IO.Path.GetDirectoryName(.FileNames(0)) For i As Integer = 0 To .FileNames.Count - 1 filelist.Add(IO.Path.GetFileName(.FileNames(i))) Next i cboModel.DataSource = filelist Dim oDoc As Document oDoc = m_inventorApp.Documents.Open(openFileDialog1.FileName, False) End With End Sub Private Sub cboModel_SelectedIndexChanged(sender As Object, e As System.EventArgs) Handles cboModel.SelectedIndexChanged With cboModel For i As Integer = 0 To .SelectedIndex = -1 If .SelectedIndex = -1 Then Exit Sub Model = path & "\" & filelist(.SelectedIndex) Next i End With End Sub Private Sub btnVorlagewählens_Click(sender As Object, e As System.EventArgs) Handles btnVorlagewählen.Click ' Überprüfen ob Inventor geöffnet ist. Try Dim invApp As Inventor.Application = System.Runtime.InteropServices.Marshal.GetActiveObject("Inventor.Application") Catch ex As Exception MessageBox.Show("Inventor must Gestartet sein.", "Fehler", MessageBoxButtons.OK, MessageBoxIcon.Error) Exit Sub End Try With ofd If .ShowDialog = Windows.Forms.DialogResult.Cancel Then Exit Sub If .FileNames.Count = 0 Then Exit Sub filelist.Clear() cboVorlage.DataSource = Nothing path = IO.Path.GetDirectoryName(.FileNames(0)) For i As Integer = 0 To .FileNames.Count - 1 filelist.Add(IO.Path.GetFileName(.FileNames(i))) Next cboVorlage.DataSource = filelist End With End Sub Private Sub cboVorlage_SelectedIndexChanged(sender As Object, e As System.EventArgs) Handles cboVorlage.SelectedIndexChanged With cboVorlage If .SelectedIndex = -1 Then Exit Sub idw = path & "\" & filelist(.SelectedIndex) End With End Sub Private Sub btnZeichnungerstellen_Click(sender As Object, e As System.EventArgs) Handles btnZeichnungerstellen.Click ' Überprüfen ob Inventor geöffnet ist. Try Dim invApp As Inventor.Application = System.Runtime.InteropServices.Marshal.GetActiveObject("Inventor.Application") Catch ex As Exception MessageBox.Show("Inventor must Gestartet sein.", "Fehler", MessageBoxButtons.OK, MessageBoxIcon.Error) Exit Sub End Try With cboVorlage If .SelectedIndex = -1 Then Exit Sub End With ' Öffne Zeichnungsforlage Dim m_inventorApp As Application = System.Runtime.InteropServices.Marshal.GetActiveObject("Inventor.Application") Dim oDrawDoc As DrawingDocument oDrawDoc = m_inventorApp.Documents.Add(DocumentTypeEnum.kDrawingDocumentObject, idw) Dim oSheet As Sheet oSheet = oDrawDoc.ActiveSheet 'Öffne Bauteil Try Dim oPartDoc As PartDocument = m_inventorApp.Documents.Open(Model, False) Dim oTG As TransientGeometry oTG = m_inventorApp.TransientGeometry 'Erstelle Hauptansicht Dim oFrontView As DrawingView oFrontView = oSheet.DrawingViews.AddBaseView(oPartDoc, oTG.CreatePoint2d(10, 10), 1 / 2, ViewOrientationTypeEnum.kFrontViewOrientation, DrawingViewStyleEnum.kHiddenLineDrawingViewStyle) ' Erstellt die obere, rechte und iso Blick. Dim oTopView As DrawingView oTopView = oSheet.DrawingViews.AddProjectedView(oFrontView, oTG.CreatePoint2d(10, 17), DrawingViewStyleEnum.kFromBaseDrawingViewStyle) Dim oIsoView As DrawingView oIsoView = oSheet.DrawingViews.AddProjectedView(oFrontView, oTG.CreatePoint2d(23, 8), DrawingViewStyleEnum.kFromBaseDrawingViewStyle) Catch ex As Exception MessageBox.Show("Kein Bauteil geöffnet.", "Fehler", MessageBoxButtons.OK, MessageBoxIcon.Error) Exit Sub End Try 'Auto Mittellinie Dim i As Long For i = 1 To oDrawDoc.ActiveSheet.DrawingViews.Count Call oDrawDoc.ActiveSheet.DrawingViews(i).SetAutomatedCenterlineSettings() Next 'alle Maße der Hauptansicht Dim oDrawView As DrawingView oDrawView = oSheet.DrawingViews(1) Dim oAllRetrievableDims As ObjectCollection oAllRetrievableDims = oSheet.DrawingDimensions.GeneralDimensions.GetRetrievableDimensions(oDrawView) Call oSheet.DrawingDimensions.GeneralDimensions.Retrieve(oDrawView, oAllRetrievableDims) ' Maße der Seittenansicht Dim SpecificDims As ObjectCollection Dim DrawView As DrawingView DrawView = oSheet.DrawingViews(3) Dim AllRetrievableDims As ObjectCollection AllRetrievableDims = oSheet.DrawingDimensions.GeneralDimensions.GetRetrievableDimensions(DrawView) SpecificDims = m_inventorApp.TransientObjects.CreateObjectCollection Call SpecificDims.Add(AllRetrievableDims.Item(1)) Call oSheet.DrawingDimensions.GeneralDimensions.Retrieve(DrawView, SpecificDims) 'Bemaßungstext zentrieren Dim oDrawingDim As Inventor.DrawingDimension For Each oDrawingDim In oSheet.DrawingDimensions If TypeOf oDrawingDim Is LinearGeneralDimension Or _ TypeOf oDrawingDim Is AngularGeneralDimension Then Call oDrawingDim.CenterText() End If Next 'Bemaßung zentrieren oDrawDoc = m_inventorApp.ActiveDocument oSheet = oDrawDoc.ActiveSheet Dim oPMitteLinie As Point2d Dim oPCenterText As Point2d Dim dmaxHeight As Double, dminHeight As Double, dmaxWidth As Double, dminWidth As Double dmaxHeight = oSheet.Height - 0.7 dminHeight = 0.7 dmaxWidth = oSheet.Width - 0.7 dminWidth = 0.7 For Each oDrawingDim In oSheet.DrawingDimensions oPMitteLinie = Nothing 'On Error Resume Next oPMitteLinie = oDrawingDim.DimensionLine.MidPoint If Not (oPMitteLinie Is Nothing) Then oPCenterText = oDrawingDim.Text.Origin If oDrawingDim.DimensionLine.Direction.x = 0 Then oPCenterText.Y = oPMitteLinie.Y If oPCenterText.X > dmaxWidth Then dmaxWidth = dmaxWidth - 1 oPCenterText.X = dmaxWidth ElseIf oPCenterText.X < dminWidth Then dminWidth = dminWidth + 1 oPCenterText.X = dminWidth End If ElseIf oDrawingDim.DimensionLine.Direction.y = 0 Then oPCenterText.X = oPMitteLinie.X If oPCenterText.Y > dmaxHeight Then dmaxHeight = dmaxHeight - 1 oPCenterText.Y = dmaxHeight ElseIf oPCenterText.Y < dminHeight Then dminHeight = dminHeight + 1 oPCenterText.Y = dminHeight End If Else ' Bemassung ist schräg End If oDrawingDim.Text.Origin = oPCenterText End If Next End Sub End Class