Hi @get2dpk. That behavior has been a pain for a long time. The DVR (DesignViewRepresentation) does have the Locked property, but that does not exactly seem to fit this need. It just prevents changes to that DVR from being saved in that DVR when you save the document. It would be nice to have an additional property for another type of lock on that DVR, which would prevent any other components from showing up in it. But that may not be feasible for the folks at Autodesk to provide a solution for, and enforce.
Below is another similar iLogic rule example that you should be able to run as many times as you want to keep a DVR for each component, and keep that component the only one visible in that DVR. I chose to go the loop route, instead of the Try...Catch statement for ensuring the needed DVR exists, simply because we can, and it is the proper way (even if I do not follow my own advise all the time 😉). It gets all collections first, then starts iterating the components. If a component is suppressed, we can not do much with it, without it throwing errors, so we check for that status first, and skip over those. (If we need to deal with those too, then we may need to add in some extra code for handling that.) Then we try to find an existing DVR with the same name as the component, by iterating the existing DVR's and checking their name against the name of the current component. If it was not found, it will get created. Then that DVR is activated, all components hidden, and that one component's visibility turned on. Then we activate the originally active DVR, to avoid disruption of what you were doing before. Then update the assembly, if needed. Give this a try, and see if it does what you need it to. And if needed, we may want to use a helper event handler to automate this rule to run when certain events happen.
Sub Main
If ThisDoc.Document.DocumentType <> DocumentTypeEnum.kAssemblyDocumentObject Then Return
Dim oADoc As AssemblyDocument = ThisDoc.Document
Dim oADef As AssemblyComponentDefinition = oADoc.ComponentDefinition
Dim oOccs As ComponentOccurrences = oADef.Occurrences
Dim oRepsMgr As RepresentationsManager = oADef.RepresentationsManager
Dim oDVRs As DesignViewRepresentations = oRepsMgr.DesignViewRepresentations
Dim oOrigDVR As DesignViewRepresentation = oRepsMgr.ActiveDesignViewRepresentation
For Each oOcc As ComponentOccurrence In oOccs
If oOcc.Suppressed Then Continue For
Dim oOccDVR As DesignViewRepresentation = Nothing
For Each oDVR As DesignViewRepresentation In oDVRs
If oDVR.Name = oOcc.Name Then
oOccDVR = oDVR
Exit For
End If
Next 'oDVR
If oOccDVR Is Nothing Then
oOccDVR = oDVRs.Add(oOcc.Name)
End If
oOccDVR.Activate
oOccDVR.HideAll
oOcc.Visible = True
Next 'oOcc
oOrigDVR.Activate 'restore originally active DVR
If oADoc.RequiresUpdate Then oADoc.Update2(True)
'If oADoc.Dirty Then oADoc.Save2(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)