iLogic rule to delete a pattern and its occurrences in an assembly

iLogic rule to delete a pattern and its occurrences in an assembly

Anonymous
Not applicable
2,524 Views
4 Replies
Message 1 of 5

iLogic rule to delete a pattern and its occurrences in an assembly

Anonymous
Not applicable

Couple of years ago, someone helped me for following code to delete a pattern and its occurrences in an assembly. It worked fine before.

 

SyntaxEditor Code Snippet

    Dim oDoc As Document 
    oDoc = ThisDoc.Document

    Dim oComp As ComponentOccurrence
    Dim oComps As ComponentOccurrences 
    oComps = oDoc.ComponentDefinition.Occurrences 
    For Each oComp In oComps 
        If Component.IsActive(oComp.Name) = False Then 
          oComp.Delete
        End If
    Next

But recently, I found it does not work now. The statement "oComp.Delete" has following error.

 

The parameter is incorrect. (Exception from HRESULT: 0x80070057 (E_INVALIDARG))

 

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 LmiRuleScript.deleteComponents()
at LmiRuleScript.Main()
at Autodesk.iLogic.Exec.AppDomExec.ExecRuleInAssembly(Assembly assem)
at iLogic.RuleEvalContainer.ExecRuleEval(String execRule)

 

Does anyone know what it is happened? And I can I fix it?

 

I do not know how many pattern in the assembly and do not know their names also. I need delete all suppressed occurrences and patterns.

 

If you could provide modified code, it will be much appreciated.

 

0 Likes
Accepted solutions (1)
2,525 Views
4 Replies
Replies (4)
Message 2 of 5

MechMachineMan
Advisor
Advisor
Accepted solution

This should work.

Sub Main()
	Dim oDoc as Document
	oDoc = ThisDoc.Document
	
	Dim oAsmCD As AssemblyComponentDefinition
	oAsmCD = oDoc.ComponentDefinition
	
	Dim oObjToDelete As Object
	
	On Error Resume Next
	
	Dim oOcc As ComponentOccurrence
	For Each oOcc in oAsmCD.Occurrences
		If oOcc.Suppressed = True
			oObjToDelete = GetAssyLevelItemToDelete(oOcc)
			oObjToDelete.Delete
			oOcc.Delete
		End If
	Next

End Sub

Function GetAssyLevelItemToDelete(oOcc As Object) As Object
	If oOcc.IsPatternElement 
		oOcc = oOcc.PatternElement.Parent
		oOcc = GetAssyLevelItemToDelete(oOcc)	
	End If
	Return oOcc
End Function

 

 


--------------------------------------
Did you find this reply helpful ? If so please use the 'Accept as Solution' or 'Like' button below.

Justin K
Inventor 2018.2.3, Build 227 | Excel 2013+ VBA
ERP/CAD Communication | Custom Scripting
Machine Design | Process Optimization


iLogic/Inventor API: Autodesk Online Help | API Shortcut In Google Chrome | iLogic API Documentation
Vb.Net/VBA Programming: MSDN | Stackoverflow | Excel Object Model
Inventor API/VBA/Vb.Net Learning Resources: Forum Thread

Sample Solutions:Debugging in iLogic ( and Batch PDF Export Sample ) | API HasSaveCopyAs Issues |
BOM Export & Column Reorder | Reorient Skewed Part | Add Internal Profile Dogbones |
Run iLogic From VBA | Batch File Renaming| Continuous Pick/Rename Objects

Local Help: %PUBLIC%\Documents\Autodesk\Inventor 2018\Local Help

Ideas: Dockable/Customizable Property Browser | Section Line API/Thread Feature in Assembly/PartsList API Static Cells | Fourth BOM Type
Message 3 of 5

Anonymous
Not applicable

Great!

Thanks lot.

0 Likes
Message 4 of 5

idealogicERZYZ
Advocate
Advocate

Hello
Is it possible to put "My property - Title - File name" in the occurence? So that you can update it when you open the file and when saving the file.
E

0 Likes
Message 5 of 5

filippo.costantin3HZMT
Advocate
Advocate

Hi I have the same problem, but I need to delete only the occurrences. 

How can I do that?

 

Thanks

0 Likes