Programmatically set the block visibility
I have found the solution, set the visibility configuration by the following function using $menuLinkItem->uuid().


  function setVisibilityConfig($instance_id, array $configuration)


$block-&gt;setVisibilityConfig('_menu_position', array('id' =&gt; '_menu_position',
        '_menu_position'=&gt; [
              'main:menu_link_content:'.$menuLinkItem-&gt;uuid() =&gt; 'main:menu_link_content:'.$menuLinkItem-&gt;uuid()
            ],
        'negate' =&gt; null,
        )
    );


Thanks, @SumitMadan for helping out to understand the visibility concept.