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

Delete all components and constraints from an assembly

harvey_craig2RCUH
Advocate

Delete all components and constraints from an assembly

harvey_craig2RCUH
Advocate
Advocate

Hi all, 

I want to make a rule that deletes all the components and constraints in an assembly before running another rule. I know you can do this individually* but as I add to the project, I will have to continuously update this list. How do I make this select all components and constraints in the assembly?

*Individually:

Components.Delete("hosetail")
Components.Delete("HexRawMaterial")
Constraints.Delete("Mate:1")
Constraints.Delete("Mate:2")

 Thanks,

Harvey

0 Likes
Reply
Accepted solutions (1)
226 Views
2 Replies
Replies (2)

Andrii_Humeniuk
Advisor
Advisor
Accepted solution

Hi @harvey_craig2RCUH . This iLogic rule deletes all patterns and all occurrences in your assembly.

Dim oADoc As AssemblyDocument = ThisDoc.Document
Dim oDef As AssemblyComponentDefinition = oADoc.ComponentDefinition
Do 
	For Each oPOcc As OccurrencePattern In oDef.OccurrencePatterns
		Try : oPOcc.Delete() : Catch : End Try
	Next
Loop While oDef.OccurrencePatterns.Count > 0
For Each oOcc As ComponentOccurrence In oDef.Occurrences
	oOcc.Delete2(True)
Next

 

 

Andrii Humeniuk - CAD Coordinator, Autodesk Certified Instructor

LinkedIn | My free Inventor Addin | My Repositories

Did you find this reply helpful ? If so please use the Accept as Solution/Like.

EESignature

0 Likes

harvey_craig2RCUH
Advocate
Advocate

Thank you, very helpful!

0 Likes