Announcements
Attention for Customers without Multi-Factor Authentication or Single Sign-On - OTP Verification rolls out April 2025. Read all about it here.
RNDinov8r
388 Views, 2 Replies

Error on iLogic code - not obvious how to fix

Here is the code i have. I have commented out the error that I get when I go to run it. The intent is to run some iLogic to delete suppressed parts and assembly after running a form where the user would choose which options to include. Those options not used, would be suppressed, and then ultimately deleted.

 

Sub Main()
  Dim doc As AssemblyDocument
  doc = ThisApplication.ActiveDocument

  Dim acd As AssemblyComponentDefinition
  acd = doc.ComponentDefinition

  Call DeleteSuppressedComponent(acd.Occurrences)
End Sub

Sub DeleteSuppressedComponent(occs As ComponentOccurrences)
  Dim occ As ComponentOccurrence
  For Each occ In occs
     If occ.Suppressed Then
         occ.Delete
     Else
         Call DeleteSuppressedComponent(occ.SubOccurrences)
     End If
   Next
End Sub

'System.ArgumentException: The Parameter Is incorrect. (Exception From HRESULT: 0x80070057 (E_INVALIDARG))
   'at System.RuntimeType.ForwardCallToInvokeMember(String memberName, BindingFlags flags, Object target, Int32[] aWrapperTypes, MessageData& msgData)
   'at Inventor.ComponentOccurrence.Delete()
   'at ThisRule.DeleteSuppressedComponent(ComponentOccurrences occs)
   'at ThisRule.Main()
   'at Autodesk.iLogic.Exec.AppDomExec.ExecRuleInAssembly(Assembly assem)
   'at iLogic.RuleEvalContainer.ExecRuleEval(String execRule)