Tagged: .net c# IApplication
07/05/2019 at 10:11 #14184
I created a custom component with the .net addon and I’d like to bind some additional objects to each node of it. Is there any way to do that?
You need to login in order to like this post: click here07/05/2019 at 10:23 #14190
To attach components to a parent node you can use ISimNode.AttachTo() method. So this snippet would attach comp2 to comp1:Python123ISimComponent comp1 = app.World.FindComponent("comp1");ISimComponent comp2 = app.World.FindComponent("comp2");comp2.RootNode.AttachTo(comp1.RootNode);
You need to login in order to like this post: click here07/05/2019 at 12:35 #14194
Thanks for replying. But what I want is to add some data to a node.
for example:Python12ISimComponent comp2 = app.World.FindComponent("comp2");comp2.RootNode.AddData(key, jsonData); //I'm finding some method like 'AddData' here
You need to login in order to like this post: click here07/05/2019 at 13:03 #14197
Well there are many ways you could store data in a node. You could use for example a property or a note behaviour. Note behaviour might be more suitable for large strings. Here’s a small snippet to create a string property and a note behaviour:Python12345IProperty prop = comp1.CreateProperty(typeof(string), PropertyConstraintType.NotSpecified, "Data");prop.Value = "Your data";INote note = comp1.RootNode.CreateBehaviorByType(BehaviorType.Note) as INote;note.Note = "Your data";
To access existing properies and note behaviours use ISimComponent.GetProperty() and ISimComponent.FindBehaviour() methods. IBehavior needs to be cast to INote type for accessing its contents on (INote.Note).
You need to login in order to like this post: click here08/05/2019 at 11:00 #14231
Another way, if there is no need for data persistancy, is by using IApplication.SetSessionValue() method. In there you can store any object like, for example, a Dictionary which you can use to link some data to an ISimNode
You need to login in order to like this post: click here09/05/2019 at 04:33 #14240
You must be logged in to reply to this topic.