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

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

Anonymous
Not applicable
351 Views
1 Reply
Message 1 of 2

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

Anonymous
Not applicable

 

 

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()

 

0 Likes
352 Views
1 Reply
Reply (1)
Message 2 of 2

Owner2229
Advisor
Advisor

Hi, first of: Why are you running the component-occurrence loop three times?

The first two seems to be useless, and even if not, change your code to be like this:

 

For Each oComp As ComponentOccurrence In oOccurrences
	If ... Then
	   ...
	ElseIf ... Then
	   ...
	End If

	If ... Then
	   ...
	ElseIf ... Then
	   ...
	End If
Next

Second, you have "oDoc" declared (somewhere in the part of your code that you didn't post), so stick to it.

There's no reason for using "ThisDoc.Document".

 

And finaly, you need to specify full path in your "GoExcel" command:

 

GoExcel.Open("C:\MyPath\84_HP_010_LabelAdjust.xlsx", "Sheet1")

 

Be aware that the sheet name ("Sheet1") must mach with the one in the sheet.

 

If you want to preserve your changes to the Excel file, than you muss add this line at the end:

GoExcel.Save

And you ALWAYS must add this line:

GoExcel.Close
Consider using "Accept as Solution" / "Kudos" if you find this helpful.
- - - - - - - - - - - - - - -
Regards,
Mike

"Always code as if the guy who ends up maintaining your code will be a violent psychopath who knows where you live." - John F. Woods
0 Likes