I adjusted the code , you have to create cube , add segment in the y axis , make editable then run the script .
this way you won't need to extrude
import c4d
from c4d import utils
def SquishPoints(cube):
"""Welds the top 4 points of a polygon Cube."""
cube.GetTag(c4d.Tphong)[c4d.PHONGTAG_PHONG_ANGLE] = utils.Rad(40)
if (cube is None) or (not cube.IsInstanceOf(c4d.Opolygon)):
return
points = cube.GetAllPoints()
point_id_groups = [[11,8],[5,2]] # Split into sub-lists so each can be welded in turn.
# Go through each set of points to weld.
for point_id_group in point_id_groups:
# Weld command isn't easily called via script, so we'll move the points we want to weld
# to the same position, then call the Optimize command.
# Calculate the center of the points
point_position_sum = c4d.Vector(0.0)
for point_id in point_id_group:
point_position_sum += points[point_id]
number_of_points = len(point_id_group)
center_point = point_position_sum / number_of_points
# Move points to the center
for point_id in point_id_group:
points[point_id] = center_point
# Store the changed points
cube.SetAllPoints(points)
def main():
# Get a list of active objects.
active_objects = doc.GetActiveObjects(flags=c4d.GETACTIVEOBJECTFLAGS_0)
# Start recording changes you'll later want to undo.
doc.StartUndo()
# Squish together the points for all selected objects
for obj in active_objects:
doc.AddUndo(c4d.UNDOTYPE_CHANGE, obj)
SquishPoints(obj)
# Use the optimize command to weld them
c4d.CallCommand(14039, 14039) # Optimize...
# Let C4D know that something has happened and it should redraw.
doc.EndUndo()
c4d.EventAdd()
if __name__=='__main__':
main()