(iLogic) Part rule not accessing excel file from assembly.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
GOAL:
I am currently trying to have a part file change one of it's parameters based on three other components it is paired with in an assembly. The method I found for referencing which parameter value to choose was a linked Excel file. It's probably worth noting that I already managed to get the rule to run from the assembly file without issues, but I want to avoid having to add user parameters and rules to each assembly when only the one text value needs to change.
ISSUE:
I keep getting the "Object reference not set to an instance of an object." error message when trying to access the Excel file. In all cases I get a Parse error when linking the excel file, but assemblies can still run the rule fine.
More Info:
System.NullReferenceException: Object reference not set to an instance of an object.
at iLogic.CadAssemblyUtil.FindComponentOccurrence(Document rootDoc, Object compoName, Boolean topLevelOnly, Boolean inTopLevelContext)
at iLogic.CadCompoOrDoc..ctor(Document rootDoc, Object oName)
at iLogic.ParamDynamicFinder.GetParameterInCompoOrDoc(Object compoOrDocName, String paramName)
at iLogic.ParamDynamic.set_Item(Object compoOrDocName, String paramName, Object value)
at LmiRuleScript.Main()
at Autodesk.iLogic.Exec.AppDomExec.ExecRuleInAssembly(Assembly assem)
at iLogic.RuleEvalContainer.ExecRuleEval(String execRule)
NOTE:
I essentially mashed snippets of code I found by searching through other forum solutions (which is why everything looks a little disjointed), so I would greatly appreciate any feedback on alternative approaches; I just need to contain the work within the part file to run on open or iTrigger in an assembly (I have been using the Event Triggers and an identifying method also found in forums). I apologize if this is a previously solved issue.
CODE CHECKS:
There are numerous message box outputs I have been using to check where my code goes bad, and they all return expected values until the excel code comes into play. I also placed a random Excel edit to check if I simply misaligned the start cell; the cell does NOT change, however Excel does prompt me on whether I would like to save changes
VERSION:
Inventor Professional 2015
SyntaxEditor Code Snippet
Case "Assembly" If oDoc.DocumentType = kAssemblyDocumentObject Then MsgBox("Assembly was picked") ' BODY ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' oOccurrences = ThisDoc.Document.ComponentDefinition.Occurrences For Each oComp As ComponentOccurrence In oOccurrences oCompName = oComp.Name If InStr(oCompName, "001") > 0 Then TypeI = 1 ElseIf InStr(oCompName, "002") > 0 Then TypeI = 2 End If Next For Each oComp As ComponentOccurrence In oOccurrences oCompName = oComp.Name If InStr(oCompName, "003") > 0 Then TypeC = 3 ElseIf InStr(oCompName, "004") > 0 Then TypeC = 4 ElseIf InStr(oCompName, "005") > 0 Then TypeC = 5 End If Next For Each oComp As ComponentOccurrence In oOccurrences oCompName = oComp.Name If InStr(oCompName, "006-0") > 0 Then Type = 60 ElseIf InStr(oCompName, "006-1") > 0 Then Type = 61 ElseIf InStr(oCompName, "007-0") > 0 Then Type = 70 ElseIf InStr(oCompName, "007-1") > 0 Then Type = 71 End If Next End If MsgBox(Type)
'ALL OUTPUTS AND VALUES ARE WORKING TO THIS POINT
' TEXT EDIT ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' GoExcel.Open("84_HP_010_LabelAdjust.xlsx", "Sheet1") GoExcel.TitleRow = 1 GoExcel.FindRowStart = 2 'i = GoExcel.FindRow("3rd Party:Embedding 5", "Sheet1", "Orifice Plate", "=", Type, "Whirl Plate", "=", TypeC) GoExcel.CellValue("84_HP_010_LabelAdjust.xlsx", "Sheet1", "H3") = 7 'SAVE PROMPT WITHOUT VALUE CHANGE i = GoExcel.FindRow("84_HP_010_LabelAdjust.xlsx", "Sheet1", "Orifice", "=", Type, "Whirl", "=", TypeC, "Inlet", "=", TypeI) MsgBox(i) Name = GoExcel.CurrentRowValue("Text") 'MsgBox(Name) ' FINAL OUTPUT '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' Parameter("84-HP-009:1", "OrificeLabel") = Name Return End Select RuleParametersOutput() InventorVb.DocumentUpdate()