How to delete Node(Link) when switch to other tab except 'Model'

I want to delete Node(Link) with .Net script.
link list

When I switch to ‘Model’, it works.

But if I switch to other tab except ‘Model’, even if I set context, failed.



Is there any way to solve it?

Code:

    private void deleteLink(ISimComponent component, List<string> linkList)
    {
        foreach (var link in linkList)
        {
            IoC.Get<IApplicationContext>().SetContext("Author");
            component.RootNode.Children[0].Delete();
            
            //component.FindNode(link).Dispose();
            //component.FindNode(link).Delete();

            //component.Rebuild();
            //component.UpdateAttributes();
            //component.Update();
            //component.RootNode.Rebuild();
        }
    }

vcmx:
无属性装配组件.vcmx (48.3 KB)

You could try to empty the selection first:
IoC.Get<ISelectionManager>().Clear();
And set the context after deleting all links you want to delete.

Hope it helps

It didn’t work.

                    IoC.Get<ISelectionManager>().Clear();
                    IoC.Get<ISelectionManager>().SetSelection(component);
                    //删除连接
                    deleteLink(component, linkList);

I was thinking something like:

IoC.Get<ISelectionManager>().Clear();
deleteLink(component, linkList);
IoC.Get<ISelectionManager>().SetSelection(component);

Can you share your plugin?

This could be a version issue. I got the error on 4.2.1 but not on 4.2.2.

-k

1 Like