Nachricht 1 von 4
VBA Occurence Modellparameter auslesen
- Als neu kennzeichnen
- Lesezeichen
- Abonnieren
- Stummschalten
- RSS-Feed abonnieren
- Kennzeichnen
- Melden
Hallo zusammen,
ich versuche mit einem VBA-Skript mehrere ähnliche Bauteile, deren Reihenfolge in einer Excel-Tabelle steht, nebeneinandergereiht in eine Baugruppe einzufügen. Der Abstand der Bauteile ergibt sich durch deren Modellparameter "d0". Ich füge das Bauteil als Occurrence ein, aber wie komme ich an den Modellparameter dieser Occurrence? (Zeile 60). Mit Hilfe der API-Dokumentation habe ich das nicht hinbekommen. Wie komme ich an diesen Wert?
Grüße,
Rene
Ich nutze Inventor 2023
Public Sub Klemmleistengenerator()
Dim excelApp As Excel.Application
Set excelApp = CreateObject("Excel.Application")
If Err Then
MsgBox "Cannot access excel."
Exit Sub
End If
' Open the spreadsheet.
Dim wb As Workbook
Set wb = excelApp.Workbooks.Open("C:\xxx\Mappe1.xlsx")
If Err Then
MsgBox "Unable to open the Excel document."
Exit Sub
End If
' Access a certain sheet.
Dim ws As WorkSheet
Set ws = wb.Worksheets.Item("Tabelle1")
If Err Then
MsgBox "Unable to get the worksheet."
Exit Sub
End If
Dim row As Integer
Dim oAsmCompDef As AssemblyComponentDefinition
Set oAsmCompDef = ThisApplication.ActiveDocument.ComponentDefinition
' Set a reference to the transient geometry object.
Dim oTG As TransientGeometry
Set oTG = ThisApplication.TransientGeometry
' Create a matrix. A new matrix is initialized with an identity matrix.
Dim oMatrix As Matrix
Set oMatrix = oTG.CreateMatrix
Dim oOcc As ComponentOccurrence
Dim subPath As String
Dim kSeries As String
Dim kType As String
Dim klemmenPos As Double
For row = 1 To 100
If (ws.Cells(row, 1) = "") Then
Exit For
Else
subPath = ws.Cells(row, 1)
kSeries = Split(subPath, "-")(0)
kType = Split(subPath, "-")(1)
Call oMatrix.SetTranslation(oTG.CreateVector(0, 0, 5.2 * row / 10))
' Add the occurrence.
If IsFile("D:\xxx\" + kSeries + "\" + subPath + ".ipt") Then
Set oOcc = oAsmCompDef.Occurrences.Add("D:\xxx\" + kSeries + "\" + subPath + ".ipt", oMatrix)
' Hier möchte ich den Modellparameter "d0" vpn oOcc
Else
MsgBox "Klemme " + subPath + " nicht gefunden"
GoTo QuitAll
End If
End If
Next row
QuitAll:
wb.Close
excelApp.Quit