Below is an example Python script using pyautocad to draw a simple representation of a tree, which consists of a trunk (a rectangle) and a crown (a circle). Be sure to have both AutoCAD and its active drawing open before running the script.
from pyautocad import Autocad, APoint
# Initialize AutoCAD application
acad = Autocad(create_if_not_exists=True)
acad.prompt("Hello! AutoCAD from Python\n")
# Define coordinates for the tree trunk and crown
trunk_base_point = APoint(0, 0)
trunk_width = 5
trunk_height = 20
crown_center_point = APoint(trunk_base_point.x + trunk_width / 2, trunk_base_point.y + trunk_height + 10)
crown_radius = 15
# Draw the trunk of the tree as a rectangle
p1 = trunk_base_point
p2 = APoint(trunk_base_point.x + trunk_width, trunk_base_point.y)
p3 = APoint(trunk_base_point.x + trunk_width, trunk_base_point.y + trunk_height)
p4 = APoint(trunk_base_point.x, trunk_base_point.y + trunk_height)
acad.model.AddLine(p1, p2)
acad.model.AddLine(p2, p3)
acad.model.AddLine(p3, p4)
acad.model.AddLine(p4, p1)
# Draw the crown of the tree as a circle
acad.model.AddCircle(crown_center_point, crown_radius)
print("Tree has been drawn in AutoCAD!")
Feel free to modify coordinates, dimensions, or the shapes used to create a more complex tree, if needed!