Rounding objects position

Hi all,

I'm looking for a way to round up the z position of a large number of objects (10,000), to say, the nearest 20mm, or perhaps to the grid (please see attached image). I'm assuming this should be a relatively easy thing to do, can anyone help?

John

AttachmentSize
rounded.jpg132.88 KB

Comments

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
rgby's picture

Not exactly :-) What I have

Not exactly :-)

What I have is roughly 8000-10000 objects, in this case cylinders, that are positioned in plan into a random, non-intersecting arrangement (think trees in a forest).
All of these objects have then been dropped onto an organic surface plane to create an interesting height pattern that is smooth (like hills).

This is all fine, but obviously the objects will intersect the surface plane at almost all unique positions, i.e. Z-887.366, Z-851.263, etc.
What I'm after is to then run a script that will transform all my objects locally up or down to the nearest 20mm (for example). So those last two height values would become Z-880, Z-860, etc.

I hope that makes sense?

pixamoon's picture

`

ah so u want to make it other way: from smooth to rough :p that's definitely easier, will post it post it afternoon

pixamoon's picture

`

oki,

this should work (just change n value to whatever you need)

n = 20  --- up or down to the nearest 20
for o in selection do (
	a = (o.pos.z as float / n as float)
	b = (if (a - (a as integer) as float) > 0.5 then ceil a else floor a)
	o.pos.z = b * n
)

This one is moving to the nearest only in Z axis
Have fun :)

rgby's picture

Just noticed this is rounding

Just noticed this is rounding negative numbers the wrong way, so -51 rounded to nearest 10 becomes -60.
I can make it work for only objects in negative space, but is there a smart way to rewrite this so that it works for both positive and negative Z values in the selection?

rgby's picture

Perfect! I think this is

Perfect!

I think this is exactly what I needed, thank you pixamoon. :-)

pixamoon's picture

`

sure, no prob, this was much easier then other way (smooching :p)

pixamoon's picture

`

hey,
If you draw spline than it is very easy to read z pos from it. Is it ok this way ?

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.