By Adam Nagy
It’s possible to call GoExcel directly, but it’s not documented and we don’t support it. For Excel functionality you can use the Excel COM API directly instead of going through iLogic. That's what iLogic is using too and that should provide access to all Excel functionality, not only those exposed in iLogic.
If you want to use GoExcel from anywhere (.NET AddIn or even external application) then you could wrap the functionality you need inside e.g. an external rule with arguments. The arguments are in the form of an Inventor NameValueMap. You can use this “rule with arguments” method to indirectly call any of the iLogic functions from an exe or addin.
Here’s a sample rule with some GoExcel code:
' In this case the code is saved ' in "C:\Test3\iLogicExcelTest.iLogicVb" Dim filePath As String = RuleArguments("FilePath") Dim sheetName As String = RuleArguments("Sheet") Dim dia As Double = RuleArguments("Dia") Dim length As Double = RuleArguments("Length") Dim rowNum As Integer = GoExcel.FindRow( _ filePath, sheetName, "Dia", "=", dia, "Length", "=", length) If (rowNum > 0) Then Dim outputs As NameValueMap = _ ThisServer.TransientObjects.CreateNameValueMap() outputs.Add("PartNumber", GoExcel.CurrentRowValue("PartNumber")) RuleArguments.Arguments.Add("Outputs", outputs) End If
And here’s sample code to run that rule from e.g. a VB exe or addin:
Public Sub Test()' m_app is a member variable of type Inventor.Application Dim arguments As NameValueMap = _ m_app.TransientObjects.CreateNameValueMap() arguments.Add("FilePath", "C:\Test3\Data.xlsx") arguments.Add("Sheet", "Sheet1") arguments.Add("Dia", 0.2) arguments.Add("Length", 4.5) Dim document As Document = m_app.ActiveDocument Dim externalRulePath = "C:\Test3\iLogicExcelTest.iLogicVb"' m_iLogicAuto is a late-bound variable of type Object. ' It implements the IiLogicAutomation interface ' (defined in Autodesk.iLogic.Interfaces.dll). ' See below GetiLogicAutomation() function to get ' it from the application m_iLogicAuto.RunExternalRuleWithArguments( _ document, externalRulePath, arguments) Dim outputs As NameValueMap = Nothing Try outputs = arguments.Value("Outputs") If (outputs IsNot Nothing) Then MessageBox.Show( _ String.Format("PartNumber = {0}", _ outputs.Value("PartNumber")), "ExcelTest") End If Catch ex As Exception MessageBox.Show(String.Format("Exception in Test: {0}", ex), _"ExcelTest") End Try End Sub
Function GetiLogicAutomation(ByVal app As Inventor.Application) _ As Object Dim addIn As Inventor.ApplicationAddIn = Nothing Try addIn = app.ApplicationAddIns.ItemById( _"{3bdd8d79-2179-4b11-8a5a-257b1c0263ac}") Catch ex As Exception Return Nothing End Try Return addIn.Automation End Function