from pyautocad import Autocad, APoint
# Initialize AutoCAD
acad = Autocad(create_if_not_exists=True)
acad.prompt("Hello, AutoCAD from Python\n")
# Function to draw a line
def draw_line(point1, point2):
acad.model.AddLine(point1, point2)
# Function to draw circle
def draw_circle(center, radius):
acad.model.AddCircle(center, radius)
# Function to draw the tree
def draw_tree(base_x, base_y, trunk_height, trunk_width, canopy_radius):
# Define base points
base_point1 = APoint(base_x, base_y)
base_point2 = APoint(base_x + trunk_width, base_y)
top_point1 = APoint(base_x + trunk_width / 2, base_y + trunk_height)
# Draw trunk (as a rectangle)
draw_line(base_point1, APoint(base_x, base_y + trunk_height))
draw_line(APoint(base_x, base_y + trunk_height), APoint(base_x + trunk_width, base_y + trunk_height))
draw_line(APoint(base_x + trunk_width, base_y + trunk_height), base_point2)
draw_line(base_point2, base_point1)
# Draw canopy (as a circle)
canopy_center = APoint(base_x + trunk_width / 2, base_y + trunk_height + canopy_radius / 2)
draw_circle(canopy_center, canopy_radius)
# Draw a tree at position (10,10) with a trunk height of 20 and width of 5, and a canopy radius of 10
draw_tree(10, 10, 20, 5, 10)