You gave me the answer, but I don't understand why I can't make it work.
When I run the code, I get;
System.Runtime.InteropServices.COMException (0x80004005): Unspecified error (Exception from HRESULT: 0x80004005 (E_FAIL))
at System.RuntimeType.ForwardCallToInvokeMember(String memberName, BindingFlags flags, Object target, Int32[] aWrapperTypes, MessageData& msgData)
at Inventor.ParameterTables.AddExcelTable(String ExcelDocument, String StartCell, Boolean Link)
at ThisRule.Main() in external rule: Initialize:line 84
at Autodesk.iLogic.Exec.AppDomExec.ExecRuleInAssembly(Assembly assem)
at iLogic.RuleEvalContainer.ExecRuleEval(String execRule)
The selected file shows in the browser under 3rd Party, but the spreadsheet doesn't show up in parameters.
Dim rDoc As Document = ThisApplication.ActiveDocument
Dim pDoc As Inventor.PartDocument
Dim aDoc As Inventor.AssemblyDocument
Dim PType As Boolean
Dim Qtn As System.Windows.Forms.DialogResult
If rDoc.DocumentType = kPartDocumentObject Then
PType = True
pDoc = ThisApplication.ActiveEditDocument
Else
PType = False
Try
aDoc = ThisApplication.ActiveEditDocument
Catch
GoTo TheEnd
End Try
End If
'... do some things, then we get to my link file section
Dim RefFile As Inventor.ReferencedOLEFileDescriptor
Dim Params As Parameters
Dim ParamTable As ParameterTable
Dim FName As String
If PType Then
Params = pDoc.ComponentDefinition.Parameters
MessageBox.Show("Part", "Debug")
Else
Params = aDoc.ComponentDefinition.Parameters
Messagebox.Show("Assy", "Debug")
End If
'if no file is linked, lets add
If rDoc.ReferencedOLEFileDescriptors.Count = 0 Then
Qtn = MessageBox.Show("Load Spreadsheet?", "Add External OLE", MessageBoxButtons.YesNo)
If Qtn = vbYes Then
Dim FDialog As Inventor.FileDialog = Nothing
InventorVb.Application.CreateFileDialog(FDialog)
'our files are stored on a NAS, I tried referencing the file both ways shown below, this makes no difference
'I don't think this is the problem as I can edit the file through the browser as it gets linked even though the command fails
'FDialog.InitialDirectory = "P:\CAD\" '<-way1
FDialog.InitialDirectory = "\\192.168.1.153\Serverdata\CAD\" '<-way2
FDialog.Filter = "Excel Files (*.xlsx)|*.xlsx"
FDialog.CancelError = True
FDialog.ShowOpen()
FName = FDialog.FileName
If FName <> "" Then
'MessageBox.Show("Name: " & FDialog.FileName, "Debug")
ParamTable = Params.ParameterTables.AddExcelTable(FName, "A1", True)
' it also fails if i try the following
'Params.ParameterTables.AddExcelTable(FName, "A1", True)
'
End If
End If
End If
If rDoc.ReferencedOLEFileDescriptors.Count > 0 Then
MessageBox.Show("loaded")
end if
TheEnd :
I can manually add the table fine, and I have confirmed "A1" is how inventor references the starting cell. Trying "A2" doesn't help. Neither does setting the 'Link' boolean to False
I'm currently on 2022
In the error I see this;
at Autodesk.iLogic.Exec.AppDomExec.ExecRuleInAssembly(Assembly assem)
I am currently debugging a part file.