Learn the basics of AutoCAD and More!

Lesson 5.06 – Working with User Input

🎯 Lesson 5-06 – Working with User Input

Learn how to collect numbers, strings, points, and object selections using AutoLISP’s built-in input functions.


πŸ“š What You’ll Learn

By the end of this lesson, you’ll be able to:

  • Prompt the user for integers, real numbers, strings, and coordinates
  • Use initget to control input behavior
  • Select objects interactively with entsel
  • Validate and handle input effectively in custom commands

🧠 Why It Matters

User input is the gateway to interactive automation in AutoCAD. By mastering these functions, you can build routines that adapt to user decisions, geometry selections, and numeric dataβ€”all essential for custom workflows.


πŸ› οΈ Tools You’ll Use

FunctionPurpose
getintGet an integer from the user
getrealGet a real (decimal) number
getstringGet text input from the user
getpointLet the user click or enter a coordinate
initgetAdd input constraints (e.g., keywords, no NULL)
entselPrompt user to select an object

🧭 Lesson Structure

1️⃣ Getting Numbers and Text

Use these functions to collect basic input from the user:

(setq age (getint "\nEnter your age: "))
(setq price (getreal "\nEnter price: "))
(setq name (getstring "\nEnter your name: "))
FunctionExpected InputExample InputReturns
getintWhole number4545
getrealDecimal number129.99129.99
getstringText stringJohn"John"

πŸ”Ή Tip: Use (getstring T ...) to allow spaces in string input.

2️⃣ Getting Points from User

You can collect coordinate input using getpoint:

(setq pt (getpoint "\nPick a point: "))
Input TypeExample Result
Mouse click(100.0 200.0 0.0)
Typed value50,100 becomes (50.0 100.0 0.0)

Use points in drawing commands like LINE, CIRCLE, or for geometry logic.


3️⃣ Controlling Input with initget

Use initget to filter or extend input:

(initget 1 "Yes No")
(setq response (getkword "\nDo you want to continue? [Yes/No]: "))
odeDescription
(initget 1)Disallows null input (user must respond)
(initget "Yes No")Accepts only the listed keywords
(getkword ...)Collects a keyword from the user

🚨 Always call initget before the input function!

4️⃣ Selecting Objects with entsel

Use entsel to let the user click an entity in the drawing:

(setq sel (entsel "\nSelect an object: "))
User hit escape or didn’t click

You can pass the result to entget to retrieve object data.

βœ… Lesson Checklist

TaskCompleted
Used getint, getreal, getstring, and getpoint☐
Restricted input using initget and getkword☐
Let user pick an object using entsel☐
Applied input in a custom routine☐

πŸ“Œ Quick Tips

TipWhy It Helps
Use initget 1 to make input requiredPrevents unintentional nil values
Always test entsel result for nilAvoids crashes if the user cancels
Add \n before prompt stringsEnsures clean, new-line display in command line
Use getstring T to allow spaces in namesHelps for full names or titles

🧩 Real-World Applications

ScenarioInput Function UsedPurpose
Dimension labelinggetstring, getrealAdd dynamic text or dimensions
Interactive scriptsgetpoint, getint, initgetPrompt-driven workflows
Object analysisentselSelect and inspect drawing entities

πŸ“ Files and Resources

File / ResourceDescription
user_input_demo.lspRoutine demonstrating all input types
input_practice.txtPractice exercises for capturing different inputs
initget_cheatsheet.docxReference guide for using initget effectively

πŸ“– Review Table

FunctionUse CaseExample
getintWhole number input(getint "\\nEnter value: ")
getrealDecimal number input(getreal "\\nEnter height: ")
getstringText input(getstring "\\nEnter name: ")
getpointPick or type coordinates(getpoint "\\nPick location: ")
initgetControl allowed input or make required(initget 1 "Yes No")
entselSelect object(entsel "\\nSelect entity: ")