OK. I think I may have something for you. This iLogic rule will first attempt to get the first Parts List in your drawing document, from whichever sheet it may be on, if any. If it doesn't find one, it will let you know and exit the rule. It then starts looping through each sheet, and each view on the sheet, retrieving the model document's Part Number, then attempting to search through the Parts List found earlier for that Part Number. If it is not found, it will attempt to delete that drawing view.
Here's the iLogic rule code:
Sub Main
If ThisApplication.ActiveDocumentType <> DocumentTypeEnum.kDrawingDocumentObject Then
MsgBox("A Drawing Document must be active for this rule to work. Exiting.",vbOKOnly+vbCritical, "WRONG DOCUMENT TYPE")
Exit Sub
End If
Dim oDDoc As DrawingDocument = ThisApplication.ActiveDocument
Dim oSheet As Sheet
' get Parts List to reference
Dim oPList As PartsList
For Each oSheet In oDDoc.Sheets
If oSheet.PartsLists.Count > 0 Then
oPList = oSheet.PartsLists.Item(1)
Exit For
End If
Next
If IsNothing(oPList) Then
MsgBox("No Parts List found. Exiting.", , "")
Exit Sub
End If
'now start checking views on all sheets
For Each oSheet In oDDoc.Sheets
For Each oView As DrawingView In oSheet.DrawingViews
'get Part Number of document in that view
Dim oDoc As Document = oView.ReferencedDocumentDescriptor.ReferencedDocument
Dim oPN As String = oDoc.PropertySets(3).Item("Part Number").Value
'check for it in the Parts List
If Not PNinPList(oPN, oPList) Then
Try
oView.Delete
Catch
MsgBox("The attempt to delete the view failed.",,"")
End Try
End If
Next
Next
End Sub
Function PNinPList(ByVal oPNum As String, oPtList As PartsList) As Boolean
Dim oResult As Boolean = False
'check if specified Part Number (oPNum) is found in the specified Parts List (oPtList)
'I don't know if you have a column for Part Number or how you may have it labeled,
'so I'll retrieve the Part Number from each row the hard way to be sure
For Each oRow As PartsListRow In oPtList.PartsListRows
If oRow.ReferencedRows.Count > 0 Then
Dim oRefRow As DrawingBOMRow = oRow.ReferencedRows.Item(1)
If oRefRow.BOMRow.ComponentDefinitions.Count > 0 Then
Dim oRefDoc As Document = oRefRow.BOMRow.ComponentDefinitions.Item(1).Document
If oPNum = oRefDoc.PropertySets(3).Item("Part Number").Value Then
oResult = True
End If
End If
End If
Next
Return oResult
End Function
If this solved your problem, or answered your question, please click ACCEPT SOLUTION.
Or, if this helped you, please click (LIKE or KUDOS) 👍.
If you want and have time, I would appreciate your Vote(s) for My IDEAS 💡or you can Explore My CONTRIBUTIONS
Wesley Crihfield

(Not an Autodesk Employee)