from pyautocad import Autocad, APoint
def draw_tree():
acad = Autocad(create_if_not_exists=True)
acad.prompt("Creating a tree...\n")
# Define points for the trunk
trunk_bottom = APoint(0, 0)
trunk_top = APoint(0, 50) # 50 units high trunk
trunk_width = 10
# Draw the rectangle for the trunk
acad.model.AddLine(trunk_bottom, trunk_top)
acad.model.AddLine(trunk_top, APoint(trunk_top.x + trunk_width, trunk_top.y))
acad.model.AddLine(APoint(trunk_top.x + trunk_width, trunk_top.y), APoint(trunk_bottom.x + trunk_width, trunk_bottom.y))
acad.model.AddLine(APoint(trunk_bottom.x + trunk_width, trunk_bottom.y), trunk_bottom)
# Define points for the canopy (using circles)
canopy_center = APoint(trunk_bottom.x + (trunk_width / 2), trunk_top.y + 20)
canopy_radius = 30
# Draw circles for the canopy
for i in range(3):
acad.model.AddCircle(APoint(canopy_center.x - 20 + (i * 20), canopy_center.y), canopy_radius)
if __name__ == "__main__":
draw_tree()
You can further expand this by adding more complexity to the shapes, and customizing the size and position according to your needs. AutoCAD needs to be running for this script to execute successfully.