Hi @boris. It looks like you changed the name of the DVR on Line 8, but should have also commented out Line 7, since you no longer need that one. Then on Line 13, you should have switched out that variable from "oActiveDVR" to "oOtherDVR". It is throwing the error on Line 15 because that is where that option is being applied, but it contained the other DVR object that may have not worked correctly. Plus, I have heard others say that if there were already some filters set in the same PartsList, we may have to clear those out first, before adding another one. Not sure.
But I can change the layout of the rule to suit your additional specifications, now that I know more about it.
Sub Main
Dim oDDoc As DrawingDocument = TryCast(ThisDoc.Document, Inventor.DrawingDocument)
If oDDoc Is Nothing Then Return
Dim oSheet As Inventor.Sheet = oDDoc.Sheets.Item(1)
oSheet.Activate
If oSheet.PartsLists.Count = 0 Then Return
Dim oPList As PartsList = oSheet.PartsLists.Item(1)
Dim oView As DrawingView = oSheet.DrawingViews.Item(1)
'this next line show how to 'get' the which DVR this view is currently set to (ReadOnly property)
'Dim sViewDVR As String = oView.DesignViewRepresentation
'this next line shows how to 'set' the DVR that you want this view set to (a Sub type method)
'oView.SetDesignViewRepresentation(sDVRName, bAssociativeBoolean) 'for setting the DVR of the View
'<<< get the DVR from 'the model' document >>>
Dim oViewDoc As Inventor.Document = oView.ReferencedDocumentDescriptor.ReferencedDocument
Dim oRepsMgr As RepresentationsManager = oViewDoc.ComponentDefinition.RepresentationsManager
'this will fail if the DVR named here is not found
Dim oDVR As DesignViewRepresentation = oRepsMgr.DesignViewRepresentations.Item("U-100-1")
'get the filter settings of the PartsList
Dim oFSettings As PartsListFilterSettings = oPList.FilterSettings
'make sure the main PartsList filters check box is checked
oFSettings.Enabled = True
'<<< clear any existing filters >>>
If oFSettings.Count > 0 Then
For i As Integer = 1 To oFSettings.Count
oFSettings.Item(i).Delete
Next
End If
'may need to do an update here, not sure
'<<< create 'options' for a new filter (to filter by assembly DVR, and visible only) >>>
Dim oNVM As NameValueMap = ThisApplication.TransientObjects.CreateNameValueMap
oNVM.Add(“AssemblyViewRepresentation”, oDVR)
oNVM.Add(“LimitQTYToVisibleComponentsOnly”, True)
'<<< add the filter, with the options >>>
Dim oFilterItem As PartsListFilterItem = oFSettings.Add(PartsListFilterItemTypeEnum.kAssemblyViewRepresentationFilterItem, oNVM)
'make sure this new filter is enabled
oFilterItem.Enabled = True
oSheet.Update
If oDDoc.RequiresUpdate Then oDDoc.Update2(True)
End Sub
If this solved your problem, or answered your question, please click ACCEPT SOLUTION .
Or, if this helped you, please click (LIKE or KUDOS) 👍.
Wesley Crihfield

(Not an Autodesk Employee)