Round the dimensions of a DC to nearest 5

Hi everyone!

I have this DC which is a simple Tube, i cant set the dimension directly from the attribute editor, or with the scale tool.

This tubes, in real life, can only be cut in dimensions that are multiples of 5. For instance: the tube lenght is : 332, it has to be cut at 330. if it is 334, it has to be 335.

In summary, is there a way to set this component in order to it can always adjust to that condition? And above all, that could work with the scale tool?

Hello SykSy
You have to use the Nearest function and compare the current length with the floor length and the ceiling length.
The current function result is in inches. If you work in centimeters, you must multiply by 2.54 to get the correct length.

I can’t find the tutorial or explenation.
But i thought there was also an option to increase the lenght by using the scale tool and set an increment of 5 mm up/down with a minimum and maximum length.
Any clue how that was settup and where to find a sample?

You can use the int function to calculate the value of the parent component (the name is assumed to be A), such as the total width of the parent component Lenx, adding a custom attribute, which can be named “num”, the formula is =int(lenx/5), that is, to round down and nest a child component B in the parent component, which The total width of the component is the formula = 5*A! The content of num, subcomponent B is your pipeline. This can support scaling.

In the specific case of SykSy, it does not refer to a nested component, but a simple DC.
Int only returns integer values and does not work for decimal steps.
she could use the int function but with the following calculation for a simple component

lenx = int(current("lenx")*2.54/5)*5
lenx = Floor(current("lenx")*2.54 , 5)

The component would automatically resize to the nearest multiple of 5 down.
With the nearest function is either up or down. The closest wins.

The more concise formula

lenx = Nearest( Current("lenx")*2.54, Floor( Current("lenx")*2.54, 5), Ceiling( Current("lenx")*2.54, 5) )

You have all been amazing ! I will try this functions and let you know as soon as possible!

THIS has worked PERFECTLY, i would give you a hug, THANKS

1 Like