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:
Examples:
- Simply switching to the graphics screen:
- Drawing a line and then switching to the graphics screen:
(grdraw ‘(0 0) ‘(10 10) 1)
(graphscr) |
- Setting a variable and then navigating to the graphics screen:
grclear
Definition: Clears the graphics screen.
Syntax:
Examples:
- Clearing the graphics screen post drawing:
(grdraw ‘(0 0) ‘(10 10) 1)
(grclear) |
- Drawing multiple lines, displaying text, and then clearing the screen:
(grdraw ‘(0 0) ‘(10 10) 1)
(grtext ‘(5 5) “Center Point” 0)
(grclear) |
- Clearing screen after user input:
grdraw
Definition: Draws a line on the graphics screen.
Syntax:
(grdraw start_point end_point color [highlight_flag]) |
Examples:
- Drawing a simple line:
(grdraw ‘(0 0) ‘(10 10) 1) |
- Drawing a red line:
(grdraw ‘(0 0) ‘(10 0) 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:
- Reading the cursor’s position:
- Reading the cursor’s position with a prompt:
(setq point (grread nil “\nSelect a point: “)) |
- 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:
- Displaying a simple text string:
(grtext ‘(5 5) “Center” 0) |
- Displaying text at a specific angle:
(grtext ‘(5 5) “Rotated Text” 45) |
- 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:
Examples:
- Drawing vectors connecting multiple points:
(grvecs ‘((0 0) (5 5) (10 0))) |
- Drawing a triangular shape using vectors:
(grvecs ‘((0 0) (5 5) (10 0) (0 0))) |
- 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:
Examples:
- Switching to the text screen after drawing:
(grdraw ‘(0 0) ‘(10 10) 1)
(textscr) |
- Displaying a message and then navigating to the text screen:
(princ “\nOperation completed successfully!”)
(textscr) |
- Navigating between graphics and text screens:
redraw
Definition: Redraws specified entities or the entire drawing.
Syntax:
Examples:
- Redrawing the entire drawing:
- Redrawing a specific entity:
- Redrawing an entity in a specific mode:
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!