from pyautocad import Autocad, APoint
# Initialize AutoCAD
acad = Autocad(create_if_not_exists=True)
acad.prompt("Hello! AutoCAD from Python\n")
# Function to create the trunk of the tree
def draw_trunk(base_point, width, height):
p1 = base_point
p2 = APoint(base_point.x + width, base_point.y)
p3 = APoint(base_point.x + width, base_point.y + height)
p4 = APoint(base_point.x, base_point.y + height)
acad.model.AddPolyline([p1, p2, p3, p4, p1])
# Function to create the canopy of the tree
def draw_canopy(center_point, radius, layers):
for i in range(layers):
offset = i * radius * 0.75
center = APoint(center_point.x, center_point.y + offset)
acad.model.AddCircle(center, radius - (i * radius * 0.1))
# Coordinates for the base of the tree trunk
trunk_base = APoint(0, 0)
trunk_width = 2
trunk_height = 10
# Draw the tree trunk
draw_trunk(trunk_base, trunk_width, trunk_height)
# Coordinates for the center of the canopy
canopy_center = APoint(trunk_base.x + trunk_width / 2, trunk_base.y + trunk_height)
canopy_radius = 5
canopy_layers = 3
# Draw the tree canopy
draw_canopy(canopy_center, canopy_radius, canopy_layers)
print("Tree has been drawn in AutoCAD.")
This script is quite basic and creates only a rudimentary representation of a tree. Depending on your needs, you might want to create a more detailed or specific portrayal of a tree. Adjust the parameters like trunk width/height and canopy radius/layers to modify the appearance. Always ensure AutoCAD is open and running while executing the script to see the results.