Message 1 of 5
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
I want to delete the OIL OUTLET object as shown in the picture but when running the code, it gives an error at the line occPatternElem.occurrences.item(i).Delete2 (False)
Need expert help or is there another way, iLogic or VBA is fine.
Option Explicit
Sub SuppressPatternOccurrencesByName()
Dim asmDoc As AssemblyDocument
Dim asmDef As AssemblyComponentDefinition
Dim occPattern As OccurrencePattern
Dim targetName As String
Dim i As Integer
Dim rectPattern As RectangularOccurrencePattern
Dim circPattern As CircularOccurrencePattern
Dim compOcc As ComponentOccurrence
Dim occPatternElem As OccurrencePatternElement
targetName = "OIL OUTLET"
Set asmDoc = ThisApplication.ActiveDocument
If asmDoc.DocumentType <> kAssemblyDocumentObject Then
MsgBox "Please open an Assembly file before running this macro!", vbExclamation
Exit Sub
End If
Set asmDef = asmDoc.ComponentDefinition
For Each occPattern In asmDef.OccurrencePatterns
If TypeOf occPattern Is RectangularOccurrencePattern Then
Set rectPattern = occPattern
For Each occPatternElem In rectPattern.OccurrencePatternElements
For i = occPatternElem.occurrences.count To 1 Step -1
If InStr(1, occPatternElem.occurrences.item(i).name, targetName, vbTextCompare) <> 0 Then
occPatternElem.occurrences.item(i).Delete2 (False)
End If
Next i
Next occPatternElem
End If
Next occPattern
End Sub
Solved! Go to Solution.