AutoLISP Tutorial 2: Custom Circle Drawer in AutoCAD

In today’s session, we’ll craft a specialized function aimed at enhancing the circle-drawing experience in AutoCAD. Whether you’ve had previous interactions with AutoLISP or you’re just starting, this guide has been meticulously designed to ensure a clear, easy-to-follow progression.


Your challenge is to develop a tailored function within AutoCAD’s AutoLISP environment that simplifies the process of creating circles for users.

Task Overview

  1. Starting Point: Begin by devising a function which will later house all the necessary instructions.
  2. User Engagement: Your function should communicate with the user to gather three key details:
    • The preferred size (diameter) for their circle.
    • The specific layer they’d like their circle to reside on.
    • The desired position on the screen that will serve as the circle’s center.
  3. Layer Management: In cases where the specified layer doesn’t exist, it’s your function’s duty to bring it into existence. All newly minted layers should be distinguishable by a unique hue – in this case, red.
  4. Action Phase: Your function should then swing into action, instructing AutoCAD to etch out a circle. It should be the right size, positioned correctly, and be on the right layer – all based on the user’s inputs.
  5. User Experience Considerations: A hallmark of great software is its seamlessness. Begin your function by minimizing any command-related distractions in AutoCAD. Once all tasks are complete, ensure everything returns to its regular state.

Helpful Tips

  • Keep your user in mind: clarity in prompts can greatly enhance the user experience.
  • After crafting your function, it’s imperative to test it. Try out different inputs to ensure your function is both robust and flexible.
  • Keep an eye out for details – they can make all the difference!

Once you’re satisfied with your creation, please submit it for review. Emphasis will be placed on functionality, user experience, and adherence to the provided guidelines.

AutoLISP Tutorial 2 Solution: Creating a Custom Circle Drawer in AutoCAD

Drawing circles in AutoCAD is a common task, but with our tailored function, we aim to simplify this process and enhance user experience. Below, you’ll find the complete function designed for this purpose. After presenting the full program, we’ll walk through its components step-by-step to ensure a solid understanding.

Complete Program

(defun C:DRAWCIRCLE1 ( )
(setq svcm (getvar “cmdecho”))
(setvar “cmdecho” 0)
(setq dia1 (getreal “\nEnter diameter of circle: “))
(setq layn (getstring “\nEnter Layer name: “))
(setq pnt1 (getpoint “\nEnter the center point for circle: “))
(command “LAYER” “m” layn “c” “red” layn “”)
(command “CIRCLE” pnt1 dia1)
(setvar “cmdecho” svcm)

Line-by-Line Explanation

(defun C:DRAWCIRCLE1 ( ): This is where we initiate the definition of our function. The name C:DRAWCIRCLE1 ensures that the function is callable directly from the AutoCAD command line.

(setq svcm (getvar “cmdecho”)): This instruction preserves the current status of the command echo by storing it in the variable svcm. It’s essential for restoring the default setting once our function completes its tasks.

(setvar “cmdecho” 0): For a clean user interaction, we mute the command echo here. This step ensures the command line won’t display internal operations.

(setq dia1 (getreal “\nEnter diameter of circle: “)): This step prompts the user to specify the circle’s diameter. We save their response in the dia1 variable.

(setq layn (getstring “\nEnter Layer name: “)): Here, we’re collecting the user’s preferred layer name. Their choice is stored in the layn variable.

(setq pnt1 (getpoint “\nEnter the center point for circle: “)): To determine the circle’s position, we ask the user to select a center point on the screen, saving this location in the pnt1 variable.

(command “LAYER” “m” layn “c” “red” layn “”): Layers in AutoCAD help organize drawings. This line checks if the user’s specified layer exists. If not, the function creates it and assigns a red color to distinguish it.

(command “CIRCLE” pnt1 dia1): All details in place, the function now commands AutoCAD to craft a circle using the previously specified center point and diameter.

(setvar “cmdecho” svcm): As a finishing touch, we restore the command echo’s original state. This ensures we leave the AutoCAD environment just as we found it.

(princ): Our function concludes with this line. It’s a standard AutoLISP closure, ensuring a tidy exit without any lingering values on the command line.


And there we have it! You’ve successfully navigated through the intricacies of our custom circle-drawing function in AutoCAD using AutoLISP. With this newfound knowledge, not only do you possess a practical tool, but you’ve also unlocked a deeper comprehension of how tailored functions can significantly optimize tasks in AutoCAD. Remember, every script you craft further refines your skills. Continue experimenting, learning, and most importantly, enjoying the coding journey!