ComponentAdded Event

Hi,

I have another (admitedly very basic) question. How do you access the Component property from the ComponentAddedEventArgs?

I serched the forum, watched the tutorials and the webinars dealing with event handling but couldn’t find an example where the EventArgs are accesed.

Could someone please give me an example (or point me in the right direction) of how to for example print out the name of the component that was added to the layout?

Thanks,

Jure

var app = IoC.Get< IApplication>();
var msger = IoC.Get< IMessageService>();
app.World.ComponentAdded += when_component_added;

private void when_component_added(object sender, ComponentAddedEventArgs e)
{
var component = e.Component;
var name = component.GetProperty(“Name”).Value;
msger.AppendMessage($“Component added: {name}”, MessageLevel.Warning);
}

1 Like

Thank you!

I almost had it, but was using the wrong EventArgs constructor :).

1 Like

Hi,

I was wondering if anyone knows how to do this correctly in VC 5.0?

Documentation says that IApplication.World is obsolete and you should use ISimWorldManager.ActiveWorld or ISimWorldManager.StaticSimWorld instead.

However I was not able to successfully get a handle on this class/interface. If I use inverison of control I either get an error or the plugin fails to load. I was not successfull with other import methods either.

Thanks in advance for any help.

Use IApplication.WorldManager to get the ISimWorldManager.

Great, it works. Thank you very much!