Message 1 of 6
Unexpected error While running iLogic Code
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
I get a unexpected error while running a iLogic rule in a big assembly.
Error on line 34 in rule: Quantity, in document: assembly.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.PropertySet.Add(Object PropValue, Object Name, Object PropId)
at iLogic.CadPropertiesInRule.InvPropertyInSets(PropertySets propSets, String setName, String propName, Boolean createCustom)
at iLogic.CadPropertiesInRule.InvProperty(Document doc, String setName, String propName, Boolean createCustom)
at iLogic.CadPropertiesInRule.set_Value(Object compoOrDocName, String setName, String propName, Object value)
at ThisRule.PurgeBatchQTY(Document oDoc) in external rule: Quantity:line 34
at ThisRule.Main() in external rule: Quantity:line 21
at Autodesk.iLogic.Exec.AppDomExec.ExecRuleInAssembly(Assembly assem)
at iLogic.RuleEvalContainer.ExecRuleEval(String execRule)
This is the iLogic code I'm running:
Sub Main
If ThisDoc.Document.DocumentType <> kAssemblyDocumentObject Then MsgBox("Rule can only run in assembly files!"): Exit Sub
If ThisDoc.Document.FullFileName = "" Then MsgBox("Assembly not saved yet!" & vbLf & vbLf & "Aborting!"): Exit Sub
Dim oGADoc As AssemblyDocument
oGADoc = ThisDoc.Document
BatchQTY = InputBox("ENTER TOTAL QTY OF ASSEMBLY", "ASSEMBLY QTY", "")
iProperties.Value("Custom", "Aantal") = BatchQTY
Dim oBOM As BOM
oBOM = oGADoc.ComponentDefinition.BOM
With oBOM
.PartsOnlyViewEnabled = True
.StructuredViewEnabled = True
.StructuredViewFirstLevelOnly = False
End With
Call PurgeBatchQTY(oGADoc)
Dim oBOMViewPO As BOMView = oBOM.BOMViews.Item("Parts Only")
Call SetBatchPartQTYs(oBOMViewPO, BatchQTY)
Dim oBOMViewStruc As BOMView = oBOM.BOMViews.Item("Structured")
Call SetBatchAssemblyQTYs(oBOMViewStruc.BOMRows, BatchQTY)
End Sub
Sub PurgeBatchQTY(oDoc As Document)
For Each oSubDoc In oDoc.AllReferencedDocuments
If oSubDoc.IsModifiable = True Then
iProperties.Value(System.IO.Path.GetFileName(oSubDoc.FullFileName), "Custom", "Aantal") = 0
End If
Next
End Sub
Sub SetBatchPartQTYs(ByVal oBOMViewPO As BOMView, ByVal BatchQTY As Integer)
For Each oBOMRowPO In oBOMViewPO.BOMRows
oCompDef = oBOMRowPO.ComponentDefinitions.Item(1)
oRowDoc = oCompDef.Document
Dim Qty As Integer = oBOMRowPO.TotalQuantity
If oRowDoc.IsModifiable = True Then
iProperties.Value(System.IO.Path.GetFileName(oRowDoc.FullFileName), "Custom", "Aantal") = Qty * BatchQTY
End If
Next
End Sub
Private Sub SetBatchAssemblyQTYs(oBOMRows As BOMRowsEnumerator, oParentQty As Integer)
Dim oQty As Integer
For Each oBOMRowStruct In oBOMRows
oCompDef = oBOMRowStruct.ComponentDefinitions.Item(1)
oRowDoc = oCompDef.Document
'Single line Check + Continues:
If Not (TypeOf oCompDef Is AssemblyComponentDefinition And oCompDef.BOMStructure = BOMStructureEnum.kNormalBOMStructure) Then Continue For
If oRowDoc.IsModifiable = False Then Continue For
'Resume functionality
oQty = oBOMRowStruct.ItemQuantity * oParentQty
iProperties.Value(System.IO.Path.GetFileName(oRowDoc.FullFileName), "Custom", "Aantal") = oQty + iProperties.Value(System.IO.Path.GetFileName(oRowDoc.FullFileName), "Custom", "Aantal")
If Not (oBOMRowStruct.ChildRows Is Nothing) Then
Call SetBatchAssemblyQTYs(oBOMRowStruct.ChildRows, oQty)
End If
Next
End Sub
The script works perfectly in small assemblies but has the error when I use it in a big assembly (+10000 occurrences)