Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Welds the points of a cube so that it looks like a tent.
"""Weld Cube Points
Welds cube points together.
Usage Instructions:
1. Create some cubes.
2. Make them editable
3. Run this script.
import c4d
def SquishPoints(cube):
"""Welds the top 4 points of a polygon Cube."""
if (cube is None) or (not cube.IsInstanceOf(c4d.Opolygon)):
points = cube.GetAllPoints()
point_id_groups = [[1,3],[5,7]] # 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
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.
# Squish together the points for all selected objects
for obj in active_objects:
doc.AddUndo(c4d.UNDOTYPE_CHANGE, obj)
# Use the optimize command to weld them
c4d.CallCommand(14039, 14039) # Optimize...
# Let C4D know that something has happened and it should redraw.
if __name__=='__main__':
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.