AutoCAD animation in Python

Here is an example Python code for a small AutoCAD animation that creates a pyramid object and moves it back and forth along the x-axis:

import win32com.client
import pythoncom
import time

# AutoCAD application object
acad = win32com.client.GetActiveObject("AutoCAD.Application")

# Pyramid instance and properties
pyramid = acad.ActiveDocument.ModelSpace.Add3DPoly(
    [(0, 0, 0), (10, 0, 0), (5, 5, 5), (0, 0, 10), (0, 0, 0)])

pyramid.Update()
pyramid.BaseWidth = 5
pyramid.BaseHeight = 5
pyramid.Height = 10

for i in range(20):
    x = i * 5
    pyramid.Move(pyramid.InsertionPoint, (x, 0, 0))
    time.sleep(0.5)