Error on iLogic code - not obvious how to fix

Error on iLogic code - not obvious how to fix

RNDinov8r
Collaborator Collaborator
436 Views
2 Replies
Message 1 of 3

Error on iLogic code - not obvious how to fix

RNDinov8r
Collaborator
Collaborator

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)
0 Likes
Accepted solutions (1)
437 Views
2 Replies
Replies (2)
Message 2 of 3

DRoam
Mentor
Mentor
Accepted solution

I was able to get this error by running your code on an assembly where an occurrence within a component pattern was suppressed. Could that be the issue for you?

 

If so, you could solve the issue by making sure the suppressed occurrence is not part of a pattern, and if it is, leave it alone. This tweak will do that:

 

If occ.Suppressed Then
	If Not occ.IsPatternElement Then
		occ.Delete
	End If
Else
	Call DeleteSuppressedComponent(occ.SubOccurrences)
End If

 

0 Likes
Message 3 of 3

RNDinov8r
Collaborator
Collaborator

That looks like it. I had inadvertantly suppressed a part in a pattern. Thanks for the help

0 Likes