Lessons

Graphics & Display Functions

Welcome back! In today’s lesson, we will delve into the world of Graphics & Display Functions in AutoLISP. These functions are your key to visually interacting with your AutoCAD drawings, allowing you to display, manipulate, and even create graphical content directly. Let’s explore these tools and understand their significance in the AutoLISP environment.

Learning Outcomes

By the end of this lesson, you will be proficient in:

  • Switching between graphic and text screens in AutoCAD.
  • Drawing lines, text, and vectors using AutoLISP.
  • Clearing the graphics screen and redrawing entities.
  • Reading cursor positions and inputs on the graphic screen.

Dive into Graphics & Display Functions

graphscr

Definition: Switches the AutoCAD window to the graphics screen.

Syntax:

(graphscr)

Examples:

  1. Simply switching to the graphics screen:
(graphscr)
  1. Drawing a line and then switching to the graphics screen:
(grdraw ‘(0 0) ‘(10 10) 1)
(graphscr)
  1. Setting a variable and then navigating to the graphics screen:
(setq a 10)
(graphscr)

grclear

Definition: Clears the graphics screen.

Syntax:

(grclear)

Examples:

  1. Clearing the graphics screen post drawing:
(grdraw ‘(0 0) ‘(10 10) 1)
(grclear)
  1. Drawing multiple lines, displaying text, and then clearing the screen:
(grdraw ‘(0 0) ‘(10 10) 1)
(grtext ‘(5 5) “Center Point” 0)
(grclear)
  1. Clearing screen after user input:
(grread)
(grclear)

grdraw

Definition: Draws a line on the graphics screen.

Syntax:

(grdraw start_point end_point color [highlight_flag])

Examples:

  1. Drawing a simple line:
(grdraw ‘(0 0) ‘(10 10) 1)
  1. Drawing a red line:
(grdraw ‘(0 0) ‘(10 0) 1)
  1. Drawing a line with highlighting:
(grdraw ‘(0 0) ‘(10 10) 1 T)

grread

Definition: Reads the cursor’s position or a point on the graphics screen.

Syntax:

(grread [cursor_mode [prompt [input_mode]]])

Examples:

  1. Reading the cursor’s position:
(setq point (grread))
  1. Reading the cursor’s position with a prompt:
(setq point (grread nil “\nSelect a point: “))
  1. Reading the cursor’s position in a specific input mode:
(setq point (grread nil nil 1))

grtext

Definition: Displays a text string on the graphics screen.

Syntax:

(grtext point string angle)

Examples:

  1. Displaying a simple text string:
(grtext ‘(5 5) “Center” 0)
  1. Displaying text at a specific angle:
(grtext ‘(5 5) “Rotated Text” 45)
  1. Displaying multiple lines of text:
(grtext ‘(5 5) “Line 1” 0)
(grtext ‘(5 4) “Line 2” 0)

grvecs

Definition: Draws a series of vectors on the graphics screen.

Syntax:

(grvecs point_list)

Examples:

  1. Drawing vectors connecting multiple points:
(grvecs ‘((0 0) (5 5) (10 0)))
  1. Drawing a triangular shape using vectors:
(grvecs ‘((0 0) (5 5) (10 0) (0 0)))
  1. Drawing multiple separate vectors:
(grvecs ‘((0 0) (5 5) nil (10 10) (15 15)))

textscr

Definition: Switches the AutoCAD window to the text screen.

Syntax:

(textscr)

Examples:

  1. Switching to the text screen after drawing:
(grdraw ‘(0 0) ‘(10 10) 1)
(textscr)
  1. Displaying a message and then navigating to the text screen:
(princ “\nOperation completed successfully!”)
(textscr)
  1. Navigating between graphics and text screens:
(graphscr)
(textscr)

redraw

Definition: Redraws specified entities or the entire drawing.

Syntax:

(redraw [entity [mode]])

Examples:

  1. Redrawing the entire drawing:
(redraw)
  1. Redrawing a specific entity:
(redraw entity_name)
  1. Redrawing an entity in a specific mode:
(redraw entity_name 1)

Conclusion

Graphics & Display Functions are at the heart of visual interactions within the CAD environment. They enable you to create, modify, and manage graphical content with ease and precision. As you become more familiar with these functions, your ability to craft dynamic and interactive routines in AutoLISP will exponentially grow. Remember, practice is key. So, keep experimenting, keep learning, and keep pushing the boundaries of what’s possible!