Center pivot with round number
Hi!
I would like to ask for help to alter a script that I use to center pivot and move it to the bottom of the object.
if selection.count != 0 then selection.pivot = [selection.center.x, selection.center.y, selection.min.z] else messagebox "Pick at least one object!" title:"Warning" beep:false
Before going further, I would like to address a flaw in this script - It won't work on multiple selected items, so if someone can fix that, I would be very thankful.
Now, to the request, if I may :)
I would like to do the pivot-align, but with a clean and rounded value, to the closest 1mm, 1cm, 1 dm or 1m.
Thanks!
Comments
.
And yet another question is how to gain more control over the rounded value, ie if I have a value like 113,15 cm and I want:
round to closet 1mm: 113,2
round to closest 1cm: 113
round to closet 1 dm: 110
round to closest m: 100
Also, can we have the script work independent from the system-units like if I tell it to round up to closest 1 dm, I can have the system units as 1 mm, 1 cm or 1 m and it would still work?
Kind regards
Haider
www.haider.se
.
Thank you @Vusta, you fixed that issue.
@Jahman, thanks for your code as well. I can see that it does round up the object coordinates, but I cannot understand the logic of those values.
Could you please explain to me the "+ 0.5" part?
Kind regards
Haider
www.haider.se
.
it is for down/up value rounding
to make it clear
assume we have 1.23 as our value
int 1.23 returns 1.0
int (1.23 + 0.5) will still give us 1.0
now if we have 1.51
int 1.51 returns 1.0
int (1.51 + 0.5) will give us 2.0 since 1.51 + 0.5 = 2.01
...
Or you can use "floor" or "ceil" functions
bga
.
sure, but how do you know which one to use?
...
@jahman
By using #4 example is the answer
bga
.
I mean why bother to know which one to use at all?
It's almost three times as quick
Time: 0.212sec. Mem: 1697944L
Time: 0.641sec. Mem: 2695776L
...
Here are some examples. p.s. "dp" argument is short for decimal places
#1
#2
#3
#4
bga
.
Thank you Barigazy
What if I want to round 111.1589 to 110 or to 100?
The idea is to have a script that places the pivot to a mm, dm, cm or m-grid, or any other given target, eg closest 5cm no matter what the system units are. In other words, you might work in 1m system units, but want to center pivots to the nearest cm.
Kind regards
Haider
www.haider.se
quickie...
if selection.count != 0 then
for o in selection do o.pivot = [o.center.x, o.center.y, o.min.z]
else messagebox "Pick at least one object!" title:"Warning" beep:false
dunno about 'round number'...