Thank you @J-Camper . I knew I had seen that exact blog before somewhere, maybe a year or so ago, I just couldn't recall where I had seen it.
My code already had a similar section of code in it, I was getting a message saying it couldn't find a certain .dll file, which I knew wasn't the problem with the code.
The NamedRangeValue was just being recognized as an Object, and therefore its only options were ToString.
So, after some trial & error tweaking, I tried defining the NamedRangeValue as an Array, then the iLogic Rule Editor recognised it and showed all the options, including the GetLength option.
That made the .dll message go away.
But, even after figuring that portion out, something was still not working.
I was still getting a message saying "Object reference not set to an instance of an object."
But after more trial & error tweaking, I finally got it to work.
It turns out, that I just needed to add a 'If-Then-Else-End If' statement right before the oList.Add statement to weed out any empty cell within the NamedRangeValue.
That eliminated the object reference message, and fixed it.
My code is basically to search for a specific UserParameter, if found, offer to update its values, if not found create it and set its values from the excel reference.
This code needed to work for both Parts & Assemblies, so I included the DocumentType filter at the top.
Below is my final working code.
Dim oDocType As DocumentTypeEnum = ThisApplication.ActiveDocumentType
Dim oPDoc As PartDocument
Dim oPDef As PartComponentDefinition
Dim oADoc As AssemblyDocument
Dim oADef As AssemblyComponentDefinition
Dim oParams As Parameters
If oDocType = DocumentTypeEnum.kPartDocumentObject Then
oPDoc = ThisApplication.ActiveDocument
oPDef = oPDoc.ComponentDefinition
oParams = oPDef.Parameters
ElseIf oDocType = DocumentTypeEnum.kAssemblyDocumentObject Then
oADoc = ThisApplication.ActiveDocument
oADef = oADoc.ComponentDefinition
oParams = oADef.Parameters
Else
MessageBox.Show("This rule '" & iLogicVb.RuleName & "' only works on Part or Assembly Documents.", "WRONG DOCUMENT TYPE")
Return
End If
Dim oUParams As UserParameters = oParams.UserParameters
Dim oParamName As String = "CHASSIS"
Dim oExists As Boolean = False
Dim oFile As String = "S:\Engineering\Shared Standard Parameters.xlsx"
Dim oSheet As String = "CHASSIS NAMES & CAB HEIGHTS"
Dim oRangeName As String = "CHASSIS_NAMES"
GoExcel.Open(oFile, oSheet)
GoExcel.DisplayAlerts = False
Dim oNamedRange As Array = GoExcel.NamedRangeValue(oRangeName)
Dim oRowsCount As Integer = oNamedRange.GetLength(0) 'counts rows in named range
Dim oColCount As Integer = oNamedRange.GetLength(1) 'counts colmuns in named range
Dim oRowIndex As Integer
Dim oColIndex As Integer
Dim oList As New List(Of String)
For oRowIndex = 1 To oRowsCount
For oColIndex = 1 To oColCount
If oNamedRange(oRowIndex, oColIndex) = "" Then
Else
oList.Add(oNamedRange(oRowIndex, oColIndex))
End If
Next
Next
For Each oUParam As UserParameter In oUParams
If oUParam.Name = oParamName Then
oExists = True
oAnswer = MessageBox.Show("The user parameter named " & oParamName & " already exists." & vbNewLine &
"Do you want to overwrite its values?", "PARAMETER EXISTS", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2)
If oAnswer = vbNo Then
Return
ElseIf oAnswer = vbYes Then
MultiValue.List(oParamName) = oList
End If
End If
Next
If oExists = False Then
Dim oNewParam As UserParameter = oUParams.AddByValue(oParamName, "FORD E-SERIES", "text")
MultiValue.List(oParamName) = oList
oNewParam.Comment = "CHOOSE ONE"
oNewParam.IsKey = True
End If
GoExcel.Close
'Output Parameters values from this rule to the Model. (Use this before Document Update)
RuleParametersOutput()
'Immediately update the current document.
InventorVb.DocumentUpdate()
I hope this helps others the the future, if they attempt to do this.
I have been using NamedRangeValue for quite a while, but always as a single cell, which always worked just fine without having to redefine it.
Wesley Crihfield

(Not an Autodesk Employee)