min() max() parameter toggle positive/negative

min() max() parameter toggle positive/negative

nClarke0101
Contributor Contributor
573 Views
4 Replies
Message 1 of 5

min() max() parameter toggle positive/negative

nClarke0101
Contributor
Contributor

I am trying to use user parameters to toggle between a positive and negative value

When toggle is on 1 the offset value should be 37mm

Then when toggle is set to 0 offset should change to -37mm

Currently when the offset just changes from 0mm - 37mm

Is it possible to do this with a math function?

 

Screenshot 2022-07-09 233816.png

0 Likes
Accepted solutions (1)
574 Views
4 Replies
Replies (4)
Message 2 of 5

KristianLaholm
Advocate
Advocate

I'd only use basic math if the value is the same and only the sign changes.
toggleNegPos.jpg

0 Likes
Message 3 of 5

nClarke0101
Contributor
Contributor

That seems good, only problem is that if the toggle is set higher then one could bring problems.

 

This seems to work though

min(max(( ( 37 * ( 2 * toggle - 1 ) ) * 1 mm ); -37 mm); 37 mm)

 

I am not to good with my math.

0 Likes
Message 4 of 5

KristianLaholm
Advocate
Advocate
Accepted solution

The sign() function is an easy error checker in this case.
Anything <=0 will return 0, anything > 0 will return 1.

And your solution with min/max looks correct.

toggle witherrorcheck.jpg

 

But your solution with min/max looks correct.

Use the one you find easy to remember, if you need to go back and edit the file.

0 Likes
Message 5 of 5

nClarke0101
Contributor
Contributor

Thankyou 

0 Likes