Accessing parameters from an Excel spreadsheet

Accessing parameters from an Excel spreadsheet

Anonymous
Not applicable
397 Views
3 Replies
Message 1 of 4

Accessing parameters from an Excel spreadsheet

Anonymous
Not applicable
This code comes from IV samples illustrating how to access values from an Excel file. When I use it I get "Type Mismatch" error. Is anyone using this functionality and if so what must be changed to make it work?

Public Sub TableParameters()
Dim oPartDoc As Inventor.PartDocument
' Obtain the active document, this assumes that
' a part document is active in Inventor
Set oPartDoc = ThisApplication.ActiveDocument

'Obtain the Parameters collection
Dim oParams As Parameters
Set oParams = oPartDoc.ComponentDefinition.Parameters

' Add a parameter table using an existing spreadsheet.
oParams.ParameterTables.AddExcelTable "C:\Temp\params.xls", "A1", True

' Accessing a parameters in a linked/embedded file
Dim oParamTableFiles As ParameterTables
Set oParamTableFiles = oParams.ParameterTables

' Traverse through the collection of linked files
Dim oParamTableFile As ParameterTable
For Each oParamTableFile In oParamTableFiles
' Change the linked file to another file
If LCase(oParamTableFile.FileName) = "c:\temp\params.xls" Then
oParamTableFile.FileName = "C:\Temp\newparams.xls"
End If

' Get the Parameters collection from the file
Dim oTableParams As TableParameters
Set oTableParams = oParamTableFile.TableParameters

' Traverse through the table parameters collection and display them
Dim iNumTableParams As Long
Debug.Print "TABLE PARAMETER VALUES"
For iNumTableParams = 1 To oTableParams.Count
' Display the name
Debug.Print " Name: " & oTableParams.Item(iNumTableParams).Name

' Display the expression
Debug.Print " Expression: " & oTableParams.Item(iNumTableParams).Expression

' Display the value. This will be in database units.
Debug.Print " Value: " & oTableParams.Item(iNumTableParams).Value
Next iNumTableParams
Next
End Sub


Thanks,
Jon
0 Likes
398 Views
3 Replies
Replies (3)
Message 2 of 4

Anonymous
Not applicable
When you get an runtime error msg box, click on the debug button and it will
show you where the error is (yellow highlight)
CVA

--
www.CVAengineering.com

IV11 Pro. sp2 and IV2008
Window XP Pro sp2
Pentium 3.2 Ghz, 3.0 GB of RAM
NVIDIA FX 3400 91.85
SpacePilot V 3.3.6
wrote in message news:5630689@discussion.autodesk.com...
This code comes from IV samples illustrating how to access values from an
Excel file. When I use it I get "Type Mismatch" error. Is anyone using this
functionality and if so what must be changed to make it work?

Public Sub TableParameters()
Dim oPartDoc As Inventor.PartDocument
' Obtain the active document, this assumes that
' a part document is active in Inventor
Set oPartDoc = ThisApplication.ActiveDocument

'Obtain the Parameters collection
Dim oParams As Parameters
Set oParams = oPartDoc.ComponentDefinition.Parameters

' Add a parameter table using an existing spreadsheet.
oParams.ParameterTables.AddExcelTable "C:\Temp\params.xls", "A1", True

' Accessing a parameters in a linked/embedded file
Dim oParamTableFiles As ParameterTables
Set oParamTableFiles = oParams.ParameterTables

' Traverse through the collection of linked files
Dim oParamTableFile As ParameterTable
For Each oParamTableFile In oParamTableFiles
' Change the linked file to another file
If LCase(oParamTableFile.FileName) = "c:\temp\params.xls" Then
oParamTableFile.FileName = "C:\Temp\newparams.xls"
End If

' Get the Parameters collection from the file
Dim oTableParams As TableParameters
Set oTableParams = oParamTableFile.TableParameters

' Traverse through the table parameters collection and display them
Dim iNumTableParams As Long
Debug.Print "TABLE PARAMETER VALUES"
For iNumTableParams = 1 To oTableParams.Count
' Display the name
Debug.Print " Name: " & oTableParams.Item(iNumTableParams).Name

' Display the expression
Debug.Print " Expression: " &
oTableParams.Item(iNumTableParams).Expression

' Display the value. This will be in database units.
Debug.Print " Value: " &
oTableParams.Item(iNumTableParams).Value
Next iNumTableParams
Next
End Sub


Thanks,
Jon
0 Likes
Message 3 of 4

Anonymous
Not applicable
Set oPartDoc = ThisApplication.ActiveDocument

This is the highlighted line of code, but what does this tell me? I have an active document .xls with the name params, just as the path indicates in the code. Is it the variable type in the file which is being questioned??

Jon
0 Likes
Message 4 of 4

Anonymous
Not applicable
I guess you declared your active document as a part document and run the
program while an assembly is active?
CVA

--
www.CVAengineering.com

IV11 Pro. sp2 and IV2008
Window XP Pro sp2
Pentium 3.2 Ghz, 3.0 GB of RAM
NVIDIA FX 3400 91.85
SpacePilot V 3.3.6
wrote in message news:5630961@discussion.autodesk.com...
Set oPartDoc = ThisApplication.ActiveDocument

This is the highlighted line of code, but what does this tell me? I have an
active document .xls with the name params, just as the path indicates in the
code. Is it the variable type in the file which is being questioned??

Jon
0 Likes