Delete Pattern With Name

Delete Pattern With Name

mark.almack
Enthusiast Enthusiast
419 Views
1 Reply
Message 1 of 2

Delete Pattern With Name

mark.almack
Enthusiast
Enthusiast

I have a rule to delete my suppressed patterns (see below), but can't figure out how to delete a pattern (and all its children) which has name "Terry"

 

I need something like 

If oOcc.PatternElement.Parent.Name = "Terry

oOcc.Delete

End If

 

Help Much Apreciated.

 

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

 

0 Likes
420 Views
1 Reply
Reply (1)
Message 2 of 2

WCrihfield
Mentor
Mentor

Would something like this work for you?

One thing I'm thinking might go wrong, is that it might not let you delete the initial (source) component of a pattern, without deleting the pattern.  If so, you may be able to check the Index of the element (as I started to do) to make sure you delete all but the first one, then if you still can't delete the last component, just delete the parent pattern first, then you will likely be able to delete that last pesky component.

If ThisApplication.ActiveDocumentType <> DocumentTypeEnum.kAssemblyDocumentObject Then
	MsgBox("An Assembly Document must be active for this rule (" & iLogicVb.RuleName & ") to work. Exiting.",vbOKOnly+vbCritical, "WRONG DOCUMENT TYPE")
	Exit Sub
End If
Dim oADoc As AssemblyDocument = ThisAssembly.Document
Dim oADef As AssemblyComponentDefinition = oADoc.ComponentDefinition

For Each oOccPatt As OccurrencePattern In oADef.OccurrencePatterns
	If oOccPatt.Name = "Terry" Then
		For Each oOccPattElmt As OccurrencePatternElement In oOccPatt.OccurrencePatternElements
			'If oOccPattElmt.Index > 1 Then
			oOccPattElmt.Occurrences.Item(1).Delete
		Next
		oOccPatt.Delete
	End If
Next

If this solved your problem, or answered your question, please click ACCEPT SOLUTION.
Or, if this helped you, please click 'LIKE' 👍.

If you have time, please... Vote For My IDEAS 💡or you can Explore My CONTRIBUTIONS

Inventor 2021 Help | Inventor Forum | Inventor Customization Forum | Inventor Ideas Forum

 

Wesley Crihfield

EESignature

(Not an Autodesk Employee)