Code:
Imports System.Windows
Imports System.Collections.GenericPublic Class frmZeichnePunkte
Private Const SPALTE_ELEMENT_BEZEICHNUNG As Integer = 4
Private Const SPALTE_TRASSE As Integer = 5
Private Const SPALTE_RHO As Integer = 10
Private Const SPALTE_SMOK As Integer = 11
Private Const SPALTE_FSL As Integer = 14
Private Const SPALTE_FSR As Integer = 17
Private Const SPALTE_TR As Integer = 20
Private mDaten As Object(,)
Private mApplication As Inventor.Application
Private mDocument As Inventor.Document
Private mTransactionManager As Inventor.TransactionManager
Private mTransaction As Inventor.Transaction
Private mWarteschlange As New LinkedList(Of Object())
Public Sub New(oApplication As Inventor.Application, oDocument As Inventor.Document, oDaten As Object(,))
' Dieser Aufruf ist für den Designer erforderlich.
InitializeComponent()
FuelleForm()
' Initialisierung von Inventor
mApplication = oApplication
mDocument = oDocument
mTransactionManager = oApplication.TransactionManager
mTransaction = mTransactionManager.StartTransaction(oDocument, "zeichne Punkte für Raster")
mDaten = oDaten
BaWorkZeichnen.RunWorkerAsync()
End Sub
Private Sub berechnePunkte()
Dim neuerTag As Object() = {}
Dim data As Object(,), count as Long = 0
data = getDaten(CoBox_Standard_Von.SelectedIndex, CoBox_Standard_Bis.SelectedIndex, count)
If count = 0 Then _
Exit Sub
mTransaction.Abort()
mTransaction = mTransactionManager.StartTransaction(mDocument, "zeichne Punkte für Raster")
mWarteschlange.AddLast({data, count})
End Sub
Private Sub CoBox_SelectedIndexChanged(sender As Object, e As EventArgs) Handles TaConEinstellung.SelectedIndexChanged,
CoBox_Standard_Von.TextChanged, CoBox_Standard_Bis.TextChanged, ChBox_Standard_Ausrichtung.TextChanged, CoBox_Standard_Ausrichtung.SelectedIndexChanged, TeBox_Standard_Ausrichtung.TextChanged,
CoBox_Benutzerdefiniert_Von.TextChanged, CoBox_Benutzerdefiniert_Bis.TextChanged,
ChBox_Vorschau.CheckedChanged
Dim state As Boolean = CoBox_Standard_Von.SelectedIndex >= 0 AndAlso CoBox_Standard_Bis.SelectedIndex >= 0
CoBut_Anwenden.Enabled = state
' Vorschau ggf. aktualisieren
If ChBox_Vorschau.Checked AndAlso state Then _
erstellePunkte()
End Sub
Private Sub BaWorkZeichnen_DoWork(sender As Object, e As ComponentModel.DoWorkEventArgs) Handles BaWorkZeichnen.DoWork
Dim oTransientGeometry As Inventor.TransientGeometry = mApplication.TransientGeometry
Dim oTransactionManager As Inventor.TransactionManager = mApplication.TransactionManager
Do
If mWarteschlange.Count = 0 Then
Threading.Thread.Sleep(100)
Else
Dim data As Object(,), count As Long
Do
Dim akt As Object() = mWarteschlange.First.Value : mWarteschlange.RemoveFirst()
data = akt(0)
count = akt(1)
Loop While mWarteschlange.Count > 0
Dim oTransaction As Inventor.Transaction = oTransactionManager.StartTransaction(mDocument, "zeichne Punkte")
Dim oFrmFortschritt As New frmFortschritt("0 von " & count & " Punkte eingefügt")
Dim oWorkPoints As Inventor.WorkPoints = ermittleWorkPoints(mDocument)
'mApplication.ScreenUpdating = False
For i = 0 To count - 1
Dim oPoint As Inventor.Point = oTransientGeometry.CreatePoint(data(i, 1) / 10, data(i, 2) / 10, data(i, 3) / 10)
Dim verschoben As Boolean = False
Dim oWorkPoint As Inventor.WorkPoint = Nothing
For Each oWorkPoint In oWorkPoints
Dim punktname As String = ""
' Try
punktname = oWorkPoint.Name
' Catch ex As Exception
' MsgBox("WP-Name nicht zugreifbar")
' punktname = ""
' End Try
If Not punktname = "" AndAlso punktname = data(i, 0) Then
Dim oFixedWorkPointDef As Inventor.FixedWorkPointDef = DirectCast(oWorkPoint.Definition, Inventor.FixedWorkPointDef)
oFixedWorkPointDef.Point = oPoint
verschoben = True
Exit For
End If
Next
If Not verschoben Then
oWorkPoint = oWorkPoints.AddFixed(oPoint)
oWorkPoint.Name = data(i, 0)
oWorkPoint.Grounded = True
End If
oFrmFortschritt.setzeFortschritt((i + 1) / count, i + 1 & " von " & count & " Punkte eingefügt/verschoben")
If oFrmFortschritt.Abbruch OrElse mWarteschlange.Count > 0 Then
MsgBox("Warteschlange erweitert")
oTransaction.Abort()
oFrmFortschritt.Close()
mApplication.ScreenUpdating = True
Continue Do
End If
Next
oTransaction.End()
oFrmFortschritt.Close()
mApplication.ScreenUpdating = True
mDocument.Update()
updateBrowserPane(mDocument)
End If
Loop
End Sub