from pyautocad import Autocad, APoint
import math
# Set up AutoCAD
acad = Autocad(create_if_not_exists=True)
print(f"Connected to AutoCAD: {acad.doc.Name}")
# Define a function to draw a line in AutoCAD
def draw_line(start, end):
acad.model.AddLine(APoint(*start), APoint(*end))
# Define a function to draw a circle in AutoCAD
def draw_circle(center, radius):
acad.model.AddCircle(APoint(*center), radius)
# Parameters for the tree
trunk_base = (0, 0)
trunk_height = 5
trunk_width = 0.5
tree_top = (trunk_base[0], trunk_base[1] + trunk_height)
branch_angle = math.radians(30)
branch_length = 4
leaf_radius = 0.75
# Draw the trunk
draw_line(trunk_base, tree_top)
# Draw branches
left_branch_end = (
tree_top[0] - branch_length * math.sin(branch_angle),
tree_top[1] + branch_length * math.cos(branch_angle)
)
right_branch_end = (
tree_top[0] + branch_length * math.sin(branch_angle),
tree_top[1] + branch_length * math.cos(branch_angle)
)
draw_line(tree_top, left_branch_end)
draw_line(tree_top, right_branch_end)
# Draw leaves as circles at the end of each branch
draw_circle(left_branch_end, leaf_radius)
draw_circle(right_branch_end, leaf_radius)
print("Tree has been drawn in AutoCAD.")
This script is basic; you can modify parameters like branch angles, lengths, and add more branches or leaves to create a more complex tree structure.