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.
- Activate proportional editing.
- Switch the Transform Pivot Point to 3D Cursor.
- Center the 3D cursor by pressing Shift+C.
- Select the vertices you want to affect.
- Scale to zero along the z-axis by pressing S > Z > 0.
- Scroll the mouse wheel to increase or decrease the affected area around the selected vertices.
I attached two screenshots to help illustrate this.
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)