0

代码的总体目标是能够在 Autodesk Inventor 中通过扫描功能从 Microsoft Access 中选择的节点坐标生成模型管道,这些坐标已被导入 Excel,因此 Excel 充当“中间-男人”。换句话说,尝试将 Excel 连接到 Inventor 以从 Excel 导入坐标。

我创建的现有代码将根据节点坐标和手动手动输入 VBA 的弯曲值生成管道。

我曾多次尝试将 Excel 连接到 Inventor,但均未成功。我在下面展示的最有希望的一个,旨在选择一个 excel 文件,尽管我尝试从单元格 A5 中提取值并将其插入到我手动估算的坐标中不起作用。

我尝试过的其他方法包括导入点(事实证明 API 不支持这一点)和操作以下链接中的代码:

https://reinventinginventor.wordpress.com/vba-code-for-exporting-inventor-parts-list-to-excel-with-thumbnails/

但是,无济于事。

'Set up 3D sketch
Dim Sketch2 As Sketch3D
Set Sketch2 = partDef.Sketches3D.Add


'Identify File address path
Dim Path1 As String
Path1 = InputBox("Enter Excel file Path e.g         C:\SapWorkDir\Inventor\UpdateOpen.xlsx", "Excel file Path")


' Get the Excel file
Dim Excel As Excel.Application
Dim wb As Workbook
Dim ws As WorkSheet
Set Excel = New Excel.Application'Set wb = Excel.Workbooks.Open(Path1)
Set ws = wb.Sheets(1)

Dim Test As Integer
Test = ws.Range("A5").Select





'input coordinate values (CURRENTLY MANUAL)
Dim oCoor(1 To 8) As WorkPoint
Set oCoor(1) = partDef.WorkPoints.AddFixed(tg.CreatePoint(0, 0, 0))
Set oCoor(2) = partDef.WorkPoints.AddFixed(tg.CreatePoint(100, 100, 0))
Set oCoor(3) = partDef.WorkPoints.AddFixed(tg.CreatePoint(100, 50, 30))
Set oCoor(4) = partDef.WorkPoints.AddFixed(tg.CreatePoint(200, 700, 30))
Set oCoor(5) = partDef.WorkPoints.AddFixed(tg.CreatePoint(600, 700, 70))
Set oCoor(6) = partDef.WorkPoints.AddFixed(tg.CreatePoint(600, 700, 500))
Set oCoor(7) = partDef.WorkPoints.AddFixed(tg.CreatePoint(600, 900, 500))
Set oCoor(8) = partDef.WorkPoints.AddFixed(tg.CreatePoint(600, 2000, 500))
'

这种方法显然不起作用,因为我无法将值“A5”调用到我手动输入的任何坐标值中。

我假设我无法通过这种方法连接到 Excel,那么有人知道怎么做吗?

4

1 回答 1

0

您可以将 Excel 库导入 Inventor 的 VBA 以使 VBA 了解 Excel 及其 API。使用工具菜单中的“引用...”命令,然后从列表中选中“Microsoft Excel 16.0 对象库”旁边的复选框,如下所示。

引用 Excel 库

您现在可以使用如下所示的代码来访问 Excel,然后使用其完整的 API 从单元格中提取值。我喜欢可以轻松指定行和列的 Cells 方法。

Public Sub ConnectToExcel()
    ' Connect to Excel
    Dim excelApp As Excel.Application
    Set excelApp = GetObject(, "Excel.Application")

    ' Run this line if you want to see Excel.  By default it is invisible.
    ' excelApp.Visible = True

    ' Open the workbook.
    Dim workBook As workBook
    Set workBook = excelApp.Workbooks.Open("C:\Temp\Test.xlsx")

    ' Get the sheet.
    Dim sheet As WorkSheet
    Set sheet = workBook.Sheets.Item("Sizes")

    ' Get some values.
    Dim val1 As String
    val1 = sheet.Cells(1, 1)
    Dim val2 As String
    val2 = sheet.Cells(1, 2)

    ' Close it down.
    excelApp.Quit
End Sub
于 2019-03-26T18:54:39.950 回答