0

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.

batFINGER
  • 84,216
  • 10
  • 108
  • 233
flobo02
  • 41
  • 5
  • Sorry, the format`s code is wrong – flobo02 May 25 '20 at 01:45
  • https://blender.stackexchange.com/questions/22888/how-to-place-any-object-on-the-floor-of-a-scene/117188#117188 – flobo02 May 25 '20 at 01:48
  • 3
    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. – Ray Mairlot May 25 '20 at 02:07
  • 1
    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) – batFINGER May 25 '20 at 08:51
  • @batFINGER thank you very much for your help – flobo02 May 25 '20 at 14:46
  • ok, finally create the operator an simple panel, as directed by blender's templates, tough i wish add it in 3D view>object>snap How can do it? Thanks in advance – flobo02 May 26 '20 at 13:36

1 Answers1

0

My answer in

[1]How to place any object on the 'floor' of a scene?

My addon append one item in Object>Snap menu

flobo02
  • 41
  • 5