from pyautocad import Autocad, APoint
# Initialize AutoCAD instance
acad = Autocad(create_if_not_exists=True)
acad.prompt("Hello, AutoCAD from Python\n")
# Function to draw a line
def draw_line(start, end):
acad.model.AddLine(APoint(*start), APoint(*end))
# Draw the trunk (represented as a rectangle here for simplicity)
def draw_trunk(base_point, height, width):
# Bottom left to bottom right
draw_line(base_point, (base_point[0] + width, base_point[1]))
# Bottom right to top right
draw_line((base_point[0] + width, base_point[1]), (base_point[0] + width, base_point[1] + height))
# Top right to top left
draw_line((base_point[0] + width, base_point[1] + height), (base_point[0], base_point[1] + height))
# Top left to bottom left
draw_line((base_point[0], base_point[1] + height), base_point)
# Draw the foliage (leaves)
def draw_foliage(center_point, radius):
acad.model.AddCircle(APoint(*center_point), radius)
# Define trunk and foliage sizes
trunk_base = (5, 1)
trunk_height = 4
trunk_width = 1
foliage_center = (5.5, 5.5)
foliage_radius = 3
# Draw the tree
draw_trunk(trunk_base, trunk_height, trunk_width)
draw_foliage(foliage_center, foliage_radius)
print("Tree drawn in AutoCAD.")