from pyautocad import Autocad, APoint
# Initialize a connection to AutoCAD
acad = Autocad(create_if_not_exists=True)
# Function to draw a line in AutoCAD
def draw_line(start_point, end_point):
return acad.model.AddLine(APoint(start_point[0], start_point[1]), APoint(end_point[0], end_point[1]))
# Function to draw a simple tree
def draw_tree(base_x, base_y, trunk_height):
# Draw trunk
trunk_start = (base_x, base_y)
trunk_end = (base_x, base_y + trunk_height)
draw_line(trunk_start, trunk_end)
# Draw branches
branch_length = trunk_height / 2
left_branch_end = (base_x - branch_length, base_y + trunk_height + branch_length)
right_branch_end = (base_x + branch_length, base_y + trunk_height + branch_length)
# Draw left branch
draw_line(trunk_end, left_branch_end)
# Draw right branch
draw_line(trunk_end, right_branch_end)
# Coordinates for the base of the tree
base_x = 0
base_y = 0
# Height of the trunk
trunk_height = 15
# Draw the tree
draw_tree(base_x, base_y, trunk_height)
Note: Ensure AutoCAD is open and ready to accept commands from your script when you run this code. You might need administrative privileges to interact with AutoCAD using PyAutoCAD. Additionally, PyAutoCAD must be properly installed and configured.