0
$\begingroup$

Is there a way to go from here: Mesh with some selected vertices

to here:

Selected vertices raised to Z = 0, with proportional edit ...using a script?

Trying to be clear: I have a mesh (possibly very big) with some vertices selected. I want to write a script that brings all selected vertices up to the same level (Z = 0). The catch is that I want to do it with proportional edit so that nearby vertices are also raised a bit (not illustrated in the images).

Since the selected vertices are all on different Z at the start I can't just do a translation (with proportinal edit activated). On the other hand, if I just set the Z coordinate to 0 I wouldn't get proportional editing at all. If I translate them one by one with proportional edit I would still end up with some of them higher than 0 (since nearby vertices would mutually raise each other a bit extra).

Maybe I could solve it with cloth simulation or something but it would be tough to do on a big scale.

How can I solve this?

$\endgroup$
2
  • $\begingroup$ Have you tried the scale (resize) operator to 0 with proportional edit activated? docs.blender.org/api/current/… $\endgroup$
    – Psyonic
    Commented Dec 3, 2023 at 0:58
  • $\begingroup$ Thanks! Scale operator was the missing piece. Now it seems so obvious. $\endgroup$
    – lurvas
    Commented Dec 4, 2023 at 9:38

1 Answer 1

0
$\begingroup$

This is a simple operation that shouldn't require a script, but if you need a script for it, please let me know. The steps are as follows.

  1. Activate proportional editing.
  2. Switch the Transform Pivot Point to 3D Cursor.
  3. Center the 3D cursor by pressing Shift+C.
  4. Select the vertices you want to affect.
  5. Scale to zero along the z-axis by pressing S > Z > 0.
  6. Scroll the mouse wheel to increase or decrease the affected area around the selected vertices.

I attached two screenshots to help illustrate this.

1

2


Edit: The following is a script to achieve the same results as the steps above. It's simpler, because most of the setup can be achieved by passing parameters to the operator.

import bpy

# The parameters were exposed here to make it easier to customize the results.
# The scale components set to 1.0 will prevent the selected points from moving along the respective axes. Since we only want the z position of the selected points to move, we set the z-component of the scale to zero (in addition to customizing the center as shown below).
scale = (1.0, 1.0, 0.0)
# falloff and proportional_size determine how the neighboring vertices will move.
falloff = 'SMOOTH'
proportional_size = 3.0
# The center of scaling determines where the selected points will end up when scaled to zero. The x and y-components will not have any effect as we set the scale components along those axes to 1.0.
center = (0.0, 0.0, 0.0)

# Store current mode
mode = bpy.context.active_object.mode

# Switch to edit mode
bpy.ops.object.mode_set(mode='EDIT')

# Perform the scaling operation using the parameters
bpy.ops.transform.resize(value=scale, 
                         orient_type='LOCAL', 
                         use_proportional_edit=True, 
                         proportional_edit_falloff=falloff, 
                         proportional_size=proportional_size, 
                         center_override=center)

# Restore mode
bpy.ops.object.mode_set(mode=mode)
$\endgroup$
2
  • $\begingroup$ Scale to Z 0. Of course. Why didn't I think of that? Yes, it has to be a script. Can all these steps be done via script? I guess they can. $\endgroup$
    – lurvas
    Commented Dec 3, 2023 at 20:10
  • $\begingroup$ I added the script to the answer. $\endgroup$
    – Mr A
    Commented Dec 4, 2023 at 0:22

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .