Showing results for 
Search instead for 
Do you mean 
Reply
Solved! Go to solution

Block Styler:: Change the Value of a Integer Box (From Array of Integers)

 

Hi 

 

I have a Integer Block whose value i need to change based on the option to selected from other String Block as explained below.

 

String Block                    Value 1

                                      Value 2

                                      Value 3

 

Integer Block                   1

                                       2

                                       3

                                       4

                                       5

                                       6

                                       7

                                       8

                                       9

Both integer and String options have been set to combo options.

 

If user selects 

            a. "Value 1" from String Block then value of Integer should be 2. 

                       -> No Issue as there should only be one value for integer

            b. "Value 2" from String Block then value of Integer should be 4. 

                       -> No Issue as there should only be one value for integer

            c. "Value 3" from String Block then value of Integer should be set to 1. 

                       -> Here user should have the option of selecting the value he wants.

                           So Integer block should have all values from 1 to 9 and 

                           user can select any value from them.

                          Problem here is, the value of the integer block should be set to some value (not the first value i.e. 1, it should be 5 in this case) but still user has the option of selecting the different value from the combo's drop down).

 

 

the code is as below.

sStringValue = this.blkString.GetProperties().GetString("Value").ToUpper();

int iArrayCountOfIntgerBlock = 1;
if (sStringValue == "Value 1")
{
	iIntValueSelected = 2;
}
else if (sStringValue == "Value 1")
{
	iIntValueSelected = 4;
}
else if (sStringValue == "Value 3")
{
	iIntValueSelected = 5; 
	iArrayCountOfIntgerBlock = 9;
}


if (iArrayCountOfIntgerBlock == 1)
{ 
	blockInteger.Value = iIntValueSelected;
}
else if (iArrayCountOfIntgerBlock > 1)
{
	int[] arrIntegerBlockValues = new int[iArrayCountOfIntgerBlock];
	for (int i = 0; i < iArrayCountOfIntgerBlock; i++)
	{
		arrIntegerBlockValues.SetValue(i+1, i);
	}
	blockInteger.SetComboOptions(arrIntegerBlockValues);
	
	// here need to set some default value.
	blockInteger.Value = arrIntegerBlockValues[4];
}

 

Regards,

Maddy

 

 

 

Windows 7 x64
NX 8.5, NX 9.0. And also NX 7.5
Visual Studio 2010 SP1, 2012 Update 4
5 REPLIES

Re: Block Styler:: Change the Value of a Integer Box (From Array of Integers)

[ Edited ]

What language is this? C#?

In the first section of your code you get the string value and convert it to all upper case. But then compare it to a mixed case string, so you'll never get a match:

sStringValue = this.blkString.GetProperties().GetString("Value").ToUpper(); <- Forced to upper case

int iArrayCountOfIntgerBlock = 1;
if (sStringValue == "Value 1") <- Compare to a mixed case string
{
	iIntValueSelected = 2;
}
else if (sStringValue == "Value 1")
{
	iIntValueSelected = 4;
}
else if (sStringValue == "Value 3")
{
	iIntValueSelected = 5; 
	iArrayCountOfIntgerBlock = 9;
}

I don't use C# all that much but as far as I recall you should compare strings using .Equals() the same as in Java. So your if statements should probably look more like this:

if (sStringValue.Equals("VALUE 1"))

 

Graham Inchley Snr R&D Engineer (Systems Development), Sandvik Coromant
Lenovo ThinkPad W540, Win7, 16GB. Developing in: Java | C | C# | KF
Production: NX8.5.3.3 MP11 64bit Testing: NX9.0.2.5

Re: Block Styler:: Change the Value of a Integer Box (From Array of Integers)

And when you get the code correct, put it in the update_cb function

I would not make the "list of integers" element selectable until the "string list" item has been selected.

Ken Akerboom Sr CAx Systems Engr, Moog, Inc.
Production: NX10.0.3.5 MP5 + patch/TC11.2
I'd rather be e-steemed than e-diseaseled


Re: Block Styler:: Change the Value of a Integer Box (From Array of Integers)

 

@Inch

if (sStringValue.Equals("VALUE 1")) 
OR
if (sStringValue == "VALUE 1")

  i mistakenly typed the "Value 1" instead of "VALUE 1".

 

@Ken_A

Please refer my problem mentioned in bold.

 

c. "Value 3" from String Block then value of Integer should be set to 1. 

                       -> Here user should have the option of selecting the value he wants.

                           So Integer block should have all values from 1 to 9 and 

                           user can select any value from them.

                          Problem here is, the value of the integer block should be set to some value (not the first value i.e. 1, it should be 5 in this case) but still user has the option of selecting the different value from the combo's drop down).

 

I'm able to set INTEGER BLOCK values to array if "VALUE 3" is selected from String Block using 

blockInteger.SetComboOptions(arrIntegerBlockValues);

But Im not able to set some default value to INTEGER BLOCK from these drop down values. 

If i use Value property of Integer Block, Drop down values will not be available.

 

I want the drop down values available and the value of the block set to one of the value from these drop down values.

Like how you select a value from a Combo Drop Down

 

 

 

Windows 7 x64
NX 8.5, NX 9.0. And also NX 7.5
Visual Studio 2010 SP1, 2012 Update 4
Solution
Solution
Accepted by topic author Maddy
‎08-26-2015 04:32 AM

Re: Block Styler:: Change the Value of a Integer Box (From Array of Integers)

You don't seem to set the int block to have only a single value for "VALUE 1" and "VALUE 2".

How about the code below. It sets up the required value and the number of options to display, then builds an array of the required options (only a single one for "VALUE 1" and "VALUE 2"). Then sets the int block to use those options and finally sets the int blocks value to the required one. I haven't tested this exact code, but I have proved that the concept of setting an int blocks value after changing its combo options does work.

sStringValue = this.blkString.GetProperties().GetString("Value").ToUpper();

int iArrayCountOfIntgerBlock = 1;
if (sStringValue == "VALUE 1")
{
	iIntValueSelected = 2;
}
else if (sStringValue == "VALUE 1")
{
	iIntValueSelected = 4;
}
else if (sStringValue == "VALUE 3")
{
	iIntValueSelected = 5; 
	iArrayCountOfIntgerBlock = 9;
}

// Create an array of the required number of combo options
int[] arrIntegerBlockValues = new int[iArrayCountOfIntgerBlock];

// If there is only one value required..
if (iArrayCountOfIntgerBlock == 1)
{ 
	// Add the required value to the array at position 0
	arrIntegerBlockValues.SetValue(iIntValueSelected, 0);
}
// If more than one value required..
else if (iArrayCountOfIntgerBlock > 1)
{
	// Build the array
	for (int i = 0; i < iArrayCountOfIntgerBlock; i++)
	{
		arrIntegerBlockValues.SetValue(i+1, i);
	}
}
// Set the int block to use the list of options
blockInteger.SetComboOptions(arrIntegerBlockValues);
// Set the int block to use the required value
blockInteger.Value = iIntValueSelected;
Graham Inchley Snr R&D Engineer (Systems Development), Sandvik Coromant
Lenovo ThinkPad W540, Win7, 16GB. Developing in: Java | C | C# | KF
Production: NX8.5.3.3 MP11 64bit Testing: NX9.0.2.5

Re: Block Styler:: Change the Value of a Integer Box (From Array of Integers)

 

Thanks Inch.

 

Regards,

Maddy

Windows 7 x64
NX 8.5, NX 9.0. And also NX 7.5
Visual Studio 2010 SP1, 2012 Update 4