# Snap objects to floor [duplicate]

I'm a beginner in blender scripting, in How to place any object on the 'floor' of a scene?, @MACHIN3 wrote this simple but smart code. Can you explain me the meaning of every line?

import bpy
context = bpy.context

for obj in context.selected_objects:
mx = obj.matrix_world
minz = min((mx @ v.co)[2] for v in obj.data.vertices)
mx.translation.z -= minz


In the same question the topic of how can integrate this code in Blender as a button is very interesting, can you help me with this? Actually I'm working with tutorials, Manuals, etc. but I'm afraid my knowledge is not enough.

• Sorry, the formats code is wrong May 25 '20 at 1:45
• blender.stackexchange.com/questions/22888/… May 25 '20 at 1:48
• Hi. If someone wrote the code in another question you should comment on the answer and ask them to explain it there. Also, please only ask one question at a time. Thanks. May 25 '20 at 2:07
• Finds the minimum global coordinate of all vertices, translate the matrix such that this is on global z = 0. Look at the simple operator template in Text Editor > Templates > Python Replace the innards of main(context)` with body of code above (ie the for loop) May 25 '20 at 8:51
• @batFINGER thank you very much for your help May 25 '20 at 14:46

## 1 Answer

My answer in

My addon append one item in Object>Snap menu