Hi everyone,
I am currently working on a C# plugin that deletes dynamic components on command. I have provided two ways to do this.
The first one includes an additional panel where all components are displayed in a list and can be selected by the user. If the user presses a button, a function is executed, which leads via detours to the fact that the component is deleted from the 3D world.
This is the code for this:
int _id = Convert.ToInt32(someStringContainingTheId); // _id is the _ISimComponent.GetHashCode()
ISimComponent _component = null;
foreach (var _comp in App.World.Components) // find component by the ID
{
if (_comp.GetHashCode() == _id)
{
if (_component == null)
{
_component = _comp;
}
}
}
if (_component != null)
{
_component.RootNode.Delete(); // delete the component as recommended in other topic
App.Simulation.Update();
}
Under normal circumstances this works perfectly fine.
As a second way I want to make it possible to select a ISimComponent in the 3D world an than press another button. The effect should be the same.
this is the code:
ISimComponent _simComponent = null;
foreach (var _comp in App.World.Components)
{
if (_comp != null)
{
if (_comp.IsHighlighted)
{
_simComponent = _comp;
}
}
}
if(_simComponent != null)
{
_simComponent.RootNode.Delete();
App.Simulation.Update();
}
This approach does not wor at all. The Plugin seems to be stuck in a Loop or somewere it should not be, since VC done not a single thing after calling ‘_simComponent.RootNode.Delete();’. It never makes it to the ’ App.Simulation.Update();'.
I tested a few things and the selection of the component in 3D seems to be the root of my problem, since the first approach also does not work if I select the component in 3D, even though I would not need to.
After that realization I tryed to unselect the component in the code befor deleting it:
if (_component.IsHighlighted)
{
ISelectionManager _sm = App.SelectionManager;
_sm.Clear();
}
Now the problem occurs at the line ‘_sm.Clear();’, it dose not make it to the delete()-function.Therefore I think that the ISelectionManager is not working properly.
Can someone please tell me, what I am doing wrong and how to fix this.
Best Regards