how to set the tag to an object in code ?

Post Reply
stasKanRich
Posts: 12
Joined: Tue Jun 05, 2018 12:10 pm

how to set the tag to an object in code ?

Post by stasKanRich »

Hi all,

having an issue with finding a way to associate tags with objects in a script.

getTagByName returns a GlobalDataItem representing the tag, thats the only way i found i can find tags without explicitly pointing them out in Globals.Tags...

if i would want to use script to set the tag in the object (multiplr times to same object), how would i do this?
is there a get set pair for this?

Code: Select all


	void MyScreen_Opened(System.Object sender, System.EventArgs e)
		{
			
			object.SETTAG(  getTagByName("MY_TAG_NAME")    );
			GlobalDataItem TAG_FROM_OBJECT =  object.GETTAG();
		
		}

I am talking about this tag in hte options, I want to do this via script:
Image
anyone knows how can i get to these get/set for all objects?

prichlin
Posts: 18
Joined: Thu Feb 20, 2020 7:59 am

Re: how to set the tag to an object in code ?

Post by prichlin »

Hello stasKanRich,
Yes, you are correct that you can access the tag associated with that object through Globals.Tags.

Example:

Code: Select all

void MyScreen_Opened(System.Object sender, System.EventArgs e)
{
	Globals.Tags.OVRD_STATE_CV25.Value = true;
	//Globals.Tags.OVRD_STATE_CV25.Value = false;
}

If you want to run this multiple times, one way would be to build a method in a custom script module and call it from the object's actions.

Example:

Code: Select all

namespace Neo.ApplicationFramework.Generated
{
    using System.Windows.Forms;
    using System;
    using System.Drawing;
    using Neo.ApplicationFramework.Tools;
    using Neo.ApplicationFramework.Common.Graphics.Logic;
    using Neo.ApplicationFramework.Controls;
    using Neo.ApplicationFramework.Interfaces;
    
    
    public partial class MyScript
    {
		public void UpdateMyTagsMethod()
		{
			//Globals.Tags.etc
		}
    }
}
Hope this helps!

stasKanRich
Posts: 12
Joined: Tue Jun 05, 2018 12:10 pm

Re: how to set the tag to an object in code ?

Post by stasKanRich »

Hi,
Thank you for the reply.

I think you missed the question I was trying to ask. I dont know the tag name so i cant use globals, what i want is to find out what tag is associated or bounded to a specific object without hard coding it.
i want to ask the object what tag it has and then replace it with a different tag.
I am sure its a result of me not know knowing c# that good and the fact that there is literally no documentation in iXdev software so i am using the wrong words to describe what i want.
but they are doing it somehow in the back end so there must be a way
in other words:
How can I get/set a tag from an object without knowing the tag name in the object, but knowing the object name?
how can i get to the red boxed area in the script with no hard coding, ie set a different pointer there?

stasKanRich
Posts: 12
Joined: Tue Jun 05, 2018 12:10 pm

Re: how to set the tag to an object in code ?

Post by stasKanRich »

So here is where i am at....
I feel like i am trying to milk a cow using a D9 bulldoser.....that i drive with my feet......in a pitch black cave.....while on fire...
(maybe its just me)
i got it to work i think...

Code: Select all

int numbs = ((Neo.ApplicationFramework.Controls.Controls.Button)valueField).DataBindings.Count;
MessageBox.Show("000:" + numbs.ToString());
((Neo.ApplicationFramework.Controls.Controls.Button)valueField).DataBindings.Clear();
numbs = ((Neo.ApplicationFramework.Controls.Controls.Button)valueField).DataBindings.Count;
MessageBox.Show("010:" + numbs.ToString());
Neo.ApplicationFramework.Common.Data.DynamicBinding dynamicBinding1 = new 

Neo.ApplicationFramework.Common.Data.DynamicBinding("Value", Neo.ApplicationFramework.Common.Data.DataItemProxyFactory.CreateProxy("Tags.B_CV22"), "Value", true, System.Windows.Forms.DataSourceUpdateMode.Never, Neo.ApplicationFramework.Common.Dynamics.VariantValueConverterCF.Default);
			((Neo.ApplicationFramework.Controls.Controls.Button)valueField).DataBindings.Add(dynamicBinding1);
numbs = ((Neo.ApplicationFramework.Controls.Controls.Button)valueField).DataBindings.Count;
MessageBox.Show("020:" + numbs.ToString());


the above shows that the tag is there removed and then a new one added.... (start with a tag chosen in the UI

to anyone looking at this here is a human explanation of how tags are connected as far as i figured out:
the objects passed to you on the screen(sender and so on) are adapted and there are no way to get tag data from them... so you need to go back through the screen to the actual object using its name / pointer.
then u use what i can only describe as a C# chainsaw to get to the bindings... like so:

Code: Select all

//in the screen use this.Button7(or what ever name you have) but inside the object you can use sender, be sure to cast it.
var itemName = this.Button7.Name ;
Type typeOfThis = this.GetType(); // screen
FieldInfo thisFieldInfo = typeOfThis.GetField(itemName, BindingFlags.NonPublic | BindingFlags.Instance);
//MessageBox.Show( thisFieldInfo.GetType().ToString());
var valueField = thisFieldInfo.GetValue(this);
not sure how i got here.. but after many many hours of reading .type() prints it works...

valueField.DataBindings. add/remove/clear with change the tag linked on the object..

not sure yet how it changes the screen hooks and stuff. use at own risk :)

Post Reply