from pyautocad import Autocad, APoint
# Initialize AutoCAD
acad = Autocad(create_if_not_exists=True)
print("Using AutoCAD version:", acad.app.Version)
# Function to draw a line given start and end points
def draw_line(start, end):
acad.model.AddLine(APoint(*start), APoint(*end))
# Function to draw a simple tree
def draw_tree(base_point, trunk_height, trunk_width, branch_height, branch_width):
# Draw the trunk
trunk_top = (base_point[0], base_point[1] + trunk_height)
draw_line(base_point, trunk_top)
# Draw branches
branch_left = (trunk_top[0] - branch_width / 2, trunk_top[1] + branch_height)
branch_right = (trunk_top[0] + branch_width / 2, trunk_top[1] + branch_height)
# Left branch
draw_line(trunk_top, branch_left)
# Right branch
draw_line(trunk_top, branch_right)
# Parameters for the tree
base_point = (0, 0) # Base of the trunk at the origin
trunk_height = 50
trunk_width = 5 # Unused here, but you can adjust line width in AutoCAD directly
branch_height = 20
branch_width = 40
# Draw the tree
draw_tree(base_point, trunk_height, trunk_width, branch_height, branch_width)
Please ensure that AutoCAD is running when you execute this script, as PyAutoCAD will interface with it directly. This example provides a very basic structure; more complex representations can be built using additional AutoCAD shapes and objects.