Changing Text color based on instance id number

A forum devoted to the discussion of all topics having to do with scripting and other advanced programming using iX Developer.
Post Reply
jmkowol
Posts: 13
Joined: Wed Jul 31, 2013 10:23 am

Changing Text color based on instance id number

Post by jmkowol »

Hello
I am fairly new to the iX Developer and have a question.

I have a screen used in 2 instances (ans aliases) and would like to change the color attributes of some of the Text entries or other visualization elements based on instance.
I know I could create "Dummy variables" for each instance use them like constants and than using the number in the Variable as value for color change in the #Alias on the screen.
Is there a more "elegant" and a rather more straight way to do so using script functions.
Thanks in Advance
J

mark.monroe
Posts: 824
Joined: Tue Mar 13, 2012 9:53 am

Re: Changing Text color based on instance id number

Post by mark.monroe »

You would have to somehow execute code that checks to see what instance you are on. You can execute via a button push or when a screen is opened. Then I would set a tag based on the instance.

The tag could then be used in the Dynamics of a on screen control to change the color.
Best Regards,
Mark Monroe

Beijer Electronics, Inc. | Applications Engineer

jmkowol
Posts: 13
Joined: Wed Jul 31, 2013 10:23 am

Re: Changing Text color based on instance id number

Post by jmkowol »

Well,
What code checks for the active instance?
Sorry for the stupid question. But I am really new to the iX developer. :)

mark.monroe
Posts: 824
Joined: Tue Mar 13, 2012 9:53 am

Re: Changing Text color based on instance id number

Post by mark.monroe »

This code gets the active instance: this.InstanceName;

Unfortunately I cannot provide you with C# programming consulting services. I can only help with iX Developer related C# questions. Writing if statements and the such are out of this forums scope.

If you have never programmed in C# I suggest you take a course on it.
Best Regards,
Mark Monroe

Beijer Electronics, Inc. | Applications Engineer

jmkowol
Posts: 13
Joined: Wed Jul 31, 2013 10:23 am

Re: Changing Text color based on instance id number

Post by jmkowol »

Thank, you . This was what I needed to know.

User avatar
Edmund
Posts: 92
Joined: Thu Nov 29, 2012 2:27 pm

Re: Changing Text color based on instance id number

Post by Edmund »

Hi!

Here is a little example with changing things based on instance with scripts.

The Motor_Faceplate has three instance (Motor_1, Motor_2, Motor_3).

In the example we change the Name, Font Color of the Name, The Fill Color of the Name, The Motor base color and Hide the Analog Setpoint for the Motor 2.
Motor_Popup.png
Motor_Popup.png (80.91 KiB) Viewed 14905 times
The first image from left is the base faceplate, second Motor 1 and so on...

Code: Select all

 public partial class Motor_Faceplate
    {
		
		void Motor_Faceplate_Opened(System.Object sender, System.EventArgs e)
		{
			// Set Instance Name to Header (remove underscore)
			txtMotorName.Text = this.InstanceName.Replace('_', ' ');
			
			
			// Check instance
			switch(this.InstanceName)
			{
				case "Motor_1": 
					txtMotorName.FontColor = new BrushCF(Color.Blue);
					txtMotorName.Fill = new BrushCF(Color.DarkGray);
					recMotorBase.Fill = new BrushCF(Color.Blue);
					break;
				
				case "Motor_2": 
					txtMotorName.FontColor = new BrushCF(Color.Green);
					txtMotorName.Fill = new BrushCF(Color.Red);
					recMotorBase.Fill = new BrushCF(Color.Green);
					txtSetpoint.Visible = false;
					break;
				
				case "Motor_3": 
					txtMotorName.FontColor = new BrushCF(Color.Aqua);
					txtMotorName.Fill = new BrushCF(Color.White);
					recMotorBase.Fill = new BrushCF(Color.Aqua);
					break;
				
			}		
		}
    }
Sorry for the ugly color combinations ;)

Best Regards
Edmund Andersson

AITECH AB

Part of Beijer Integrator Group

jmkowol
Posts: 13
Joined: Wed Jul 31, 2013 10:23 am

Re: Changing Text color based on instance id number

Post by jmkowol »

Edmund,
Thanks a lot :D
J

Post Reply