Simple Parameter Issue

Simple Parameter Issue

Anonymous
Not applicable
549 Views
6 Replies
Message 1 of 7

Simple Parameter Issue

Anonymous
Not applicable

Hi all,

 

I am trying to create a form where I have 2 co-dependent parameters that update each other based on which field is changed.

For example, if I have 2 parameters x and y with the relation x = 2y, how can I write a rule so that if someone changes the value of x, it automatically changes y and if someone changes the value of y, it automatically changes x?

 

If I simply write:

x = 2y

y = x/2

And if someone changes the x field, it will change x back to the previous value since it calculates x before y

 

Currently, I have to set a check box for them to specify which field they want to change (i.e. "Do you want to specify x or y?") but I am trying to reduce clutter on my form and delete unecessary parameters.

0 Likes
Accepted solutions (1)
550 Views
6 Replies
Replies (6)
Message 2 of 7

Owner2229
Advisor
Advisor

Hi,

you can make a form with two rows and on each of them add your parameter and rule (and change it's name to e.g. "Change x" and "Change y"), so it would look like:

 

<Parameter 1>   <Rule 1>

<Parameter 2>   <Rule 2>

 

Then each of the rules would look like:

 

Rule 1 (Let's say Parameter 1 is your "x". It dont need even need to be iProperty, it can be diameter or something, whatever you need to use it for...)

iProperties.Value("Custom", "Parameter 2") = iProperties.Value("Custom", "Parameter 1")/2

 

Rule 2 

iProperties.Value("Custom", "Parameter 1") = iProperties.Value("Custom", "Parameter 2")*2

 

--------------------------------

You can even make it as global form so you can use it in other parts, but then u have to look for it in your system (It's located in your "Design data (styles...)"\iLogic\UI\ folder) and edit it as folowing (You would also need to save your rules in external files. In this example it is "C:\My Rules\Rule-1.iLogicVb"):

 

<UiElementSpec xsi:type="iLogicExternalRuleControlSpec">
      <Name>Change x</Name>
      <Font>
        <FamilyName>Tahoma</FamilyName>
        <Size>12</Size>
        <Bold>true</Bold>
        <Italic>false</Italic>
      </Font>
      <TextLocation>Left</TextLocation>
      <Image>
        <BitmapByteArray />
      </Image>
      <TextVisible>true</TextVisible>
      <RuleName>Rule-1</RuleName>
      <RuleButtonBehavior>RunRule</RuleButtonBehavior>
      <Path>C:\My Rules\Rule-1.iLogicVb</Path>
    </UiElementSpec>

 

May it be some use for you ! It's probably not the best solution, but it's the only that came on my mind at the moment.

Consider using "Accept as Solution" / "Kudos" if you find this helpful.
- - - - - - - - - - - - - - -
Regards,
Mike

"Always code as if the guy who ends up maintaining your code will be a violent psychopath who knows where you live." - John F. Woods
0 Likes
Message 3 of 7

Anonymous
Not applicable

This could work, but then I would feel like I would still be cluttering the form with buttons and rules. In addition, if I wanted to add more options later, that would mean an additional button and rule for each option. I guess I am looking for a piece of code that can recognize if a parameter has just been changed by user input or not. Then a simple "If" rule can be used with this code to update the other fields.

 

I guess a good example of what can be shown here.

 

https://www.google.com/webhp?sourceid=chrome-instant&ion=1&espv=2&ie=UTF-8#safe=strict&q=usd+to+eur

 

Google's currency converter automatically updates the other field based on which field you change. I feel like the answer is simple but it just isn't coming to me.

0 Likes
Message 4 of 7

Owner2229
Advisor
Advisor

Hi, to do what you wish you would need form with apply button, but then can both of the parameters be changed at once so the script wont know which to use (even if you'll change just one of them), so I think this dont have a solution in a form, except the one I posted. I think it could be done by rules themself, but it would be tricky.

The form can't "recognize" by itself that you have changed a parameter, you will always have to hit a button to do so.

And to that Google's converter... that's quite different story, it's controled by totaly diferent programing language, so it cant aply in Inventor.

You could do this in an Add-In, but that'll require someone who knows VBA...

Consider using "Accept as Solution" / "Kudos" if you find this helpful.
- - - - - - - - - - - - - - -
Regards,
Mike

"Always code as if the guy who ends up maintaining your code will be a violent psychopath who knows where you live." - John F. Woods
0 Likes
Message 5 of 7

Anonymous
Not applicable

Hi, thanks for your answer.

 

In response to your statement that the form doesn't recognize when a parameter has been changed, I don't know about that. My form does not have an apply button, only a done button, and every time I change a parameter in the form, it automatically updates my model and all my other values. That is why I believe there must be some way to accomplish this, using VBA within a rule.

0 Likes
Message 6 of 7

Owner2229
Advisor
Advisor
Accepted solution

Alright, I have digged some info for you:

You can use this folowing code (one rule for each parameter, without any event specifed to this rules):

 

Rule 1: (changes "y" if "x" changes)

 

s = x
Parameter("y")=Parameter("x")/2

Rule 2(changes "x" if "y" changes)

 

s = y
Parameter("x")=Parameter("y")*2

That's it, I have tested it and it works for me. 

Consider using "Accept as Solution" / "Kudos" if you find this helpful.
- - - - - - - - - - - - - - -
Regards,
Mike

"Always code as if the guy who ends up maintaining your code will be a violent psychopath who knows where you live." - John F. Woods
0 Likes
Message 7 of 7

Anonymous
Not applicable

Excellent! Thank you so much!

0 Likes