雪恋星灵草 发表于 2019-5-21 17:13:13

inventor的Fx参数表如何导出到EXCEL中?

欲将inventor中fx参数表中的模型参数及用户参数的内容导出到Excel表格内使用,有什么办法可以做到吗?

远祥 发表于 2019-5-22 19:26:53

参数化设置?

雪恋星灵草 发表于 2019-6-12 11:18:41

远祥 发表于 2019-5-22 19:26
参数化设置?

是的,有办法导入表格中么?

雪恋星灵草 发表于 2019-6-12 11:22:24

网上搜索到如下方法,暂未验证,谨慎使用
1、VBA编程法--- Sanjay Ramaswamy



用法就是新建一个空的Excel表格, 然后再VBA 编辑器里面复制下面的代码,然后add a reference to “Microsoft Excel 12.0 Object Library”。 运行即可。



Public Sub ExportParameters()

   

    Err.Clear

    Dim oExcel As Excel.Application

    Set oExcel = GetObject(, "Excel.Application")

    If Err <> 0 Then

      MsgBox "Excel must be running"

      Exit Sub

    End If

   

    Err.Clear

    Dim oSheet As Excel.WorkSheet

    Set oSheet = oExcel.ActiveSheet

    If Err <> 0 Then

      MsgBox "An empty must be active in Excel"

      Exit Sub

    End If

   

    Dim oDoc As Document

    Set oDoc = ThisApplication.ActiveDocument

   

    oSheet.Cells(1, 1).Value = "Name"

    oSheet.Cells(1, 2).Value = "Units"

    oSheet.Cells(1, 3).Value = "Equation"

    oSheet.Cells(1, 4).Value = "Value (cm)"

   

    oSheet.Cells(1, 1).HorizontalAlignment = Excel.xlCenter

    oSheet.Cells(1, 2).HorizontalAlignment = Excel.xlCenter

    oSheet.Cells(1, 3).HorizontalAlignment = Excel.xlCenter

    oSheet.Cells(1, 4).HorizontalAlignment = Excel.xlCenter

    oSheet.Cells(1, 1).Font.Bold = True

    oSheet.Cells(1, 2).Font.Bold = True

    oSheet.Cells(1, 3).Font.Bold = True

    oSheet.Cells(1, 4).Font.Bold = True

   

    oSheet.Cells(3, 1).Value = "Model Parameters"

    oSheet.Cells(3, 1).Font.Bold = True

   

    Dim i As Long

    i = 4

    Dim oModelParam As ModelParameter

    For Each oModelParam In oDoc.ComponentDefinition.Parameters.ModelParameters

      

      oSheet.Cells(i, 1).Value = oModelParam.Name

      oSheet.Cells(i, 2).Value = oModelParam.Units

      oSheet.Cells(i, 3).Value = oModelParam.Expression

      oSheet.Cells(i, 4).Value = oModelParam.Value

      

      i = i + 1

    Next

   

    i = i + 1

    oSheet.Cells(i, 1).Value = "Reference Parameters"

    oSheet.Cells(i, 1).Font.Bold = True

    i = i + 1

   

    Dim oRefParam As ReferenceParameter

    For Each oRefParam In oDoc.ComponentDefinition.Parameters.ReferenceParameters

      

      oSheet.Cells(i, 1).Value = oRefParam.Name

      oSheet.Cells(i, 2).Value = oRefParam.Units

      oSheet.Cells(i, 3).Value = oRefParam.Expression

      oSheet.Cells(i, 4).Value = oRefParam.Value

      

      i = i + 1

    Next

   

    i = i + 1

    oSheet.Cells(i, 1).Value = "User Parameters"

    oSheet.Cells(i, 1).Font.Bold = True

    i = i + 1

   

    Dim oUserParam As UserParameter

    For Each oUserParam In oDoc.ComponentDefinition.Parameters.UserParameters

      

      oSheet.Cells(i, 1).Value = oUserParam.Name

      oSheet.Cells(i, 2).Value = oUserParam.Units

      oSheet.Cells(i, 3).Value = oUserParam.Expression

      oSheet.Cells(i, 4).Value = oUserParam.Value

      

      i = i + 1

    Next

   

    Dim oParamTable As ParameterTable

    For Each oParamTable In oDoc.ComponentDefinition.Parameters.ParameterTables

      

      i = i + 1

      oSheet.Cells(i, 1).Value = "Table Parameters - " & oParamTable.FileName

      oSheet.Cells(i, 1).Font.Bold = True

      i = i + 1

   

      Dim oTableParam As TableParameter

      For Each oTableParam In oParamTable.TableParameters

         

            oSheet.Cells(i, 1).Value = oTableParam.Name

            oSheet.Cells(i, 2).Value = oTableParam.Units

            oSheet.Cells(i, 3).Value = oTableParam.Expression

            oSheet.Cells(i, 4).Value = oTableParam.Value

         

            i = i + 1

      Next

    Next

   

    Dim oDerivedParamTable As DerivedParameterTable

    For Each oDerivedParamTable In oDoc.ComponentDefinition.Parameters.DerivedParameterTables

      

      i = i + 1

      oSheet.Cells(i, 1).Value = "Derived Parameters - " & oDerivedParamTable.ReferencedDocumentDescriptor.FullDocumentName

      oSheet.Cells(i, 1).Font.Bold = True

      i = i + 1

   

      Dim oDerivedParam As DerivedParameter

      For Each oDerivedParam In oDerivedParamTable.DerivedParameters

         

            oSheet.Cells(i, 1).Value = oDerivedParam.Name

            oSheet.Cells(i, 2).Value = oDerivedParam.Units

            oSheet.Cells(i, 3).Value = oDerivedParam.Expression

            oSheet.Cells(i, 4).Value = oDerivedParam.Value

         

            i = i + 1

      Next

    Next

End Sub





第二个方法--- iLogic方法 , 感谢xiaodong Liang



用法,新建一个test.xlsx在C盘下面,然后复制下面内容到一个规则里面。运行即可。





'Open Excel
GoExcel.Open("c:test.xlsx", "Sheet1")

'Title of column
GoExcel.CellValue("c:test.xlsx", "Sheet1", "A1") = "Name"
GoExcel.CellValue("c:test.xlsx", "Sheet1", "B1") = "Units"
GoExcel.CellValue("c:test.xlsx", "Sheet1", "C1") = "Equation"
GoExcel.CellValue("c:test.xlsx", "Sheet1", "D1") = "Value (cm)"

'Model Parameters
Dim oCurrentIndex As Long = 3
GoExcel.CellValue("c:test.xlsx", "Sheet1", "A" & CStr(oCurrentIndex)) = "Model Parameters"

Dim index As Long
Dim oIndexStr As String

Dim oModelPs
oModelPs = ThisApplication.Activedocument.ComponentDefinition.Parameters.ModelParameters

For index = 1 To oModelPs.Count


oIndexStr = "A" & CStr(oCurrentIndex + index)
GoExcel.CellValue("c:test.xlsx", "Sheet1", oIndexStr) = oModelPs(index).Name

oIndexStr = "B" & CStr(oCurrentIndex + index)
GoExcel.CellValue("c:test.xlsx", "Sheet1", oIndexStr) = oModelPs(index).Units

oIndexStr = "C" & CStr(oCurrentIndex + index)
GoExcel.CellValue("c:test.xlsx", "Sheet1", oIndexStr) = oModelPs(index).Expression

oIndexStr = "D" & CStr(oCurrentIndex + index)
GoExcel.CellValue("c:test.xlsx", "Sheet1", oIndexStr) = oModelPs(index).Value
Next

'Reference Parameters
oCurrentIndex = oCurrentIndex + oModelPs.Count + 1
GoExcel.CellValue("c:test.xlsx", "Sheet1", "A" & CStr(oCurrentIndex) ) = "Reference Parameters"

Dim oRefPs
oRefPs = ThisApplication.Activedocument.ComponentDefinition.Parameters.ReferenceParameters

For index = 1 To oRefPs.Count

oIndexStr = "A" & CStr(oCurrentIndex + index)
GoExcel.CellValue("c:test.xlsx", "Sheet1", oIndexStr) = oRefPs(index).Name

   oIndexStr = "B" & CStr(oCurrentIndex + index)
GoExcel.CellValue("c:test.xlsx", "Sheet1", oIndexStr) = oRefPs(index).Units

oIndexStr = "C" & CStr(oCurrentIndex + index)
GoExcel.CellValue("c:test.xlsx", "Sheet1", oIndexStr) = oRefPs(index).Expression

oIndexStr = "D" & CStr(oCurrentIndex + index)
GoExcel.CellValue("c:test.xlsx", "Sheet1", oIndexStr) = oRefPs(index).Value
Next

'User Parameters
oCurrentIndex = oCurrentIndex +oRefPs.Count + 1
GoExcel.CellValue("c:test.xlsx", "Sheet1", "A" & CStr(oCurrentIndex) ) = "User Parameters"

Dim oUserPs
oUserPs = ThisApplication.Activedocument.ComponentDefinition.Parameters.UserParameters

For index = 1 To oUserPs.Count

oIndexStr = "A" & CStr(oCurrentIndex + index)
GoExcel.CellValue("c:test.xlsx", "Sheet1", oIndexStr) = oUserPs(index).Name

oIndexStr = "B" & CStr(oCurrentIndex + index)
GoExcel.CellValue("c:test.xlsx", "Sheet1", oIndexStr) = oUserPs(index).Units

oIndexStr = "C" & CStr(oCurrentIndex + index)
GoExcel.CellValue("c:test.xlsx", "Sheet1", oIndexStr) = oUserPs(index).Expression

oIndexStr = "D" & CStr(oCurrentIndex + index)
GoExcel.CellValue("c:test.xlsx", "Sheet1", oIndexStr) = oUserPs(index).Value
Next


'ParameterTables
oCurrentIndex = oCurrentIndex +oUserPs.Count+ 1
GoExcel.CellValue("c:test.xlsx", "Sheet1", "A" & CStr(oCurrentIndex) ) = "Parameter Table"

Dim oPTables
oPTables = ThisApplication.Activedocument.ComponentDefinition.Parameters.ParameterTables

Fori = 1 To oPTables.Count

   Dim oEachPTable
   oEachPTable = oPTables(i)

   Dim oPTableParas
   oPTableParas = oEachPTable.TableParameters

   oCurrentIndex = oCurrentIndex + 1
   GoExcel.CellValue("c:test.xlsx", "Sheet1", "A" & CStr(oCurrentIndex) ) = "Table Parameters - " & oEachPTable.FileName

   For index= 1 TooPTableParas.Count
   
Dim oEachP
oEachP = oPTableParas(index)

oIndexStr = "A" & CStr(index + oCurrentIndex)
   GoExcel.CellValue("c:test.xlsx", "Sheet1", oIndexStr) = oEachP.Name

oIndexStr = "B" & CStr(index +oCurrentIndex)
   GoExcel.CellValue("c:test.xlsx", "Sheet1", oIndexStr) = oEachP.Units

   oIndexStr = "C" & CStr(index +oCurrentIndex)
   GoExcel.CellValue("c:test.xlsx", "Sheet1", oIndexStr) = oEachP.Expression

   oIndexStr = "D" & CStr(index + oCurrentIndex)
   GoExcel.CellValue("c:test.xlsx", "Sheet1", oIndexStr) = oEachP.Value   
   Next

   oCurrentIndex = oCurrentIndex + oPTableParas.Count

Next

'Derived Parameter Table
oCurrentIndex = oCurrentIndex + 1
GoExcel.CellValue("c:test.xlsx", "Sheet1", "A" & CStr(oCurrentIndex) ) = "Derived Parameter Table"

Dim oDTables
oDTables = ThisApplication.Activedocument.ComponentDefinition.Parameters.DerivedParameterTables

Fori = 1 To oDTables.Count

   Dim oEachDTable
   oEachDTable = oDTables(i)

   Dim oDTableParas
   oDTableParas = oEachDTable.DerivedParameters   

   oCurrentIndex = oCurrentIndex + 1
   GoExcel.CellValue("c:test.xlsx", "Sheet1", "A" & CStr(oCurrentIndex) ) = "Table Parameters - " & oEachDTable.ReferencedDocumentDescriptor.FullDocumentName

   For index= 1 TooDTableParas.Count
   
Dim oEachDP
oEachDP = oDTableParas(index)

oIndexStr = "A" & CStr(index + oCurrentIndex)
   GoExcel.CellValue("c:test.xlsx", "Sheet1", oIndexStr) = oEachDP.Name

oIndexStr = "B" & CStr(index +oCurrentIndex)
   GoExcel.CellValue("c:test.xlsx", "Sheet1", oIndexStr) = oEachDP.Units

   oIndexStr = "C" & CStr(index +oCurrentIndex)
   GoExcel.CellValue("c:test.xlsx", "Sheet1", oIndexStr) = oEachDP.Expression

   oIndexStr = "D" & CStr(index + oCurrentIndex)
   GoExcel.CellValue("c:test.xlsx", "Sheet1", oIndexStr) = oEachDP.Value   
   Next
    oCurrentIndex = oCurrentIndex + oDTableParas.Count

Next



GoExcel.Save
GoExcel.Close
页: [1]
查看完整版本: inventor的Fx参数表如何导出到EXCEL中?