Hi @steveh3. I'm still using Inv 2021.2.2, so I don't currently have access to ModelStates, but since you only want the code to effect the 'current' view rep / model state, it doesn't seem like a problem to me, as long as they are not 'locked'. I know that design view reps can be locked, and I know that model states have an 'edit member scope' setting to be aware of. I am assuming that if a model state is currently active, it shouldn't be 'out of scope', but the scope may be set to 'all' or 'a specific set', so that is something I'm guessing you would need to keep in mind. I also know that individual components within the assembly can be set to their own representations, and that they can be 'associatively' set to a view rep defined within them. This setting may be a problem when attempting to change the visibility of the component. I don't recall if it throws an error, or just breaks that 'associative' setting automatically to make the visibility change happen.
Have you tried something simple like this to see if it works?
If ThisApplication.ActiveDocumentType <> DocumentTypeEnum.kAssemblyDocumentObject Then
MsgBox("An Assembly Document must be active for this rule to work. Exiting.",vbCritical, "WRONG DOCUMENT TYPE")
Exit Sub
End If
Dim oADoc As AssemblyDocument = ThisApplication.ActiveDocument
Dim oADef As AssemblyComponentDefinition = oADoc.ComponentDefinition
'oVRep = oADef.RepresentationsManager.ActiveDesignViewRepresentation
'oMS = oADef.ModelStates.ActiveModelState
For Each oComp As ComponentOccurrence In oADef.Occurrences
Try
If oComp.BOMStructure = BOMStructureEnum.kReferenceBOMStructure Then
'check if this component is associatively set to a view rep defined within itself
'if so, then changing its visibility may 'break' this setting
'If oComp.IsAssociativeToDesignViewRepresentation Then
' oComp.IsAssociativeToDesignViewRepresentation = False
'End If
oComp.Visible = False
End If
Catch e As Exception
MsgBox(e.Message & vbCrLf & e.StackTrace, , "")
End Try
Next
Wesley Crihfield

(Not an Autodesk Employee)