It's based of another post and modified. Essentially i'm having to set the visibility, etc of all the pieces of a circular pattern.
The rule works completely fine in the assembly it's written in. This assembly inserted into another assembly. When saving all files in the upper level assembly, it generates and error on this rule in the sub assembly.
The code:
Dim oDoc As AssemblyDocument oDoc = ThisApplication.ActiveDocument Dim oPattern As OccurrencePattern oPattern = oDoc.ComponentDefinition.OccurrencePatterns.Item("FRS_Pattern 3:1") Dim oPatternElement As OccurrencePatternElement For Each oPatternElement In oPattern.OccurrencePatternElements Dim oOcc As ComponentOccurrence For Each oOcc In oPatternElement.Occurrences If FRS_SEGMENTS= 1 then oOcc.Enabled = False oOcc.Visible = False oOcc.BOMStructure = 51972 else oOcc.Enabled = True oOcc.Visible = True oOcc.BOMStructure = 51969 End if Next Next
The error:
iLogic Rule Error in rule: FRS_YN, in document: U_TIP_BODY_ASSY.iam
Unspecified error (Exception from HRESULT: 0x80004005 (E_FAIL))
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.OccurrencePatterns.get_Item(Object Index)
at LmiRuleScript.Main()
at Autodesk.iLogic.Exec.AppDomExec.ExecRuleInAssembly(Assembly assem)
at e.a(String A_0)
Solved! Go to Solution.
Solved by wowens63. Go to Solution.
just thinking out loud..if you set oDoc = ThisApplication.ActiveDocument your setting the oDoc = to the upper and not = to the assembly the code is writen in?
I think that's right.
I changed it to ThisDoc.Document and it's passed the few tests i've thrown at it thus far.
Fingers crossed that it lasts. 🙂
After posting i went back and stared at it and was thinking the same thing.