Hi @danielius_samsonas. Just to clarify, you have an occurrence of a single part type component within the top level of your assembly, but also have an occurrence of that same part component down within a sub assembly, and you want to turn off the visibility of the occurrence in the top level of the assembly, without turning off the visibility of the occurrence down within the sub assembly, correct? Well, that should be the simplest scenario to control, or make happen. How do you want/need to be able to specify which component that is? I assume that you do not want to manually select that top level component with your mouse, because then this ability is right in the right-click menu from there, and a code based rule would not be necessary. So, do you want to specify it by the name you see in the model browser tree (including the usual ":1" Index number, which would be needed), or do you want to find it by its Part Number value? Are there multiple instances/occurrences of that same part in the top level of the assembly, or just the one? If specifying which one to get by Part Number or File Name, and not by its unique model browser tree name, then it may find multiple instances/occurrences if there are multiple in the top level of the assembly.
Essentially it is always the DesignViewRepresentations (DVRs) that record whether or not components have their 'visibility' turned on or off, as well as their appearance/color. When we insert a component occurrence (ComponentOccurrence) into an assembly, that occurrence has its own independent settings for things like which DesignViewRepresentation (DVR) it is set to (ComponentOccurrence.SetDesignViewRepresentation), and which ModelState it is set to (ComponentOccurrence.ActiveModelState). When we set an occurrence to a DVR, we can make that setting 'associative', which means, if its appearance/color changes in the part file, then it will automatically update to match that in the assembly. However, if we just go changing how a component looks in a parent level assembly without keeping that DVR setting in mind, it will 'break' that DVR association functionality.
So, we would only really need to change the value of one property: ComponentOccurrence.Visible , for that one occurrence in the context of the main assembly, and that should not really have any effect on any other occurrences, because that visibility change is being recorded by the currently active DVR of the main assembly.
Wesley Crihfield

(Not an Autodesk Employee)