Skip to main content

AutoCAD Platform Customization: AutoLISP



AutoCAD Platform Customization: AutoLISP

Lee Ambrosius

ISBN: 978-1-118-90696-5 August 2014 432 Pages

Download Product Flyer

Download Product Flyer

Download Product Flyer is to download PDF in new tab. This is a dummy description. Download Product Flyer is to download PDF in new tab. This is a dummy description. Download Product Flyer is to download PDF in new tab. This is a dummy description. Download Product Flyer is to download PDF in new tab. This is a dummy description.


Customize and personalize programs built on the AutoCAD platform

AutoLISP is the key to unlocking the secrets of a more streamlined experience using industry leading software programs like AutoCAD, Civil 3D, Plant 3D, and more.

AutoCAD Platform Customization: AutoLISP provides real-world examples that show you how to do everything from modifying graphical objects and reading and setting system variables to communicating with external programs. It also features a resources appendix and downloadable datasets and customization examples—tools that ensure swift and easy adoption.

  • Find out how to remove unused buttons from the ribbon to gain screen space
  • Discover how to create macros for frequently performed actions, or add your company's logo to the bottom of every drawing
  • Learn to perform more involved customizations, like communicating with a database to validate and update information entered in drawing layers
  • Ideal for CAD administrators, senior drafters, savvy users, and other professionals and students

Through detailed discussions and tutorials that include real-world examples, this book gives you the power to enhance your program's experience and output.

Introduction xix

Chapter 1 • Quick Start for New AutoLISP Programmers 1

Working with AutoLISP Expressions 1

Working with Commands and Input 3

Conditionalizing and Repeating Expressions 5

Grouping Expressions 7

Storing and Loading AutoLISP Expressions 9

Chapter 2 • Understanding AutoLISP 15

Getting Started with AutoLISP 15

Understanding the Syntax of an Expression 16

Executing Expressions 18

Accessing the AutoLISP Documentation 19

Storing and Retrieving Values 19

Setting and Using Variables 21

Working with System Variables 25

Accessing Environment Variables 26

Exploring Data Types 28

Leveraging AutoCAD and Third-Party Commands 30

Using the command Function 31

Using the command-s Function 32

Working with Commands That Display a Dialog Box 33

Defining and Using Custom Functions 33

Defining a Custom Function 34

Using a Custom Function 35

Example: Drawing a Rectangle 36

Chapter 3 • Calculating and Working with Values 39

Calculating Values with Math Functions 39

Performing Basic Math Calculations 39

Performing Advanced Math Calculations 43

Working with Bitwise Operations 44

Manipulating Strings 48

Concatenating Strings 49

Getting the Length of and Searching for Strings 49

Replacing and Trimming Strings 51

Changing the Case of a String 55

Evaluating Values to Strings 56

Converting Data Types 57

Converting Numeric Values to Strings 57

Converting Strings to Numeric Values 58

Converting Numeric Values to Other Number Types 60

Returning a Value from a Custom Function 61

Exercise: Drawing a Rectangle (Revisited) 63

Creating the drawplatelsp File 64

Revising the drawplate Function 65

Adding the Revised drawplate Function to drawplatelsp 66

Creating the utilitylsp File 67

Loading the LSP Files into AutoCAD 68

Chapter 4 • Working with Lists 71

What Are Lists? 71

Creating a List 73

Getting an Element from a List 74

Retrieving a Specifi c Element 75

Stepping Through a List 78

Appending, Substituting, and Removing Elements 79

Appending Elements 79

Substituting Elements 81

Removing Elements 81

Determining Whether an Item Exists in a List 82

Sorting the Elements of a List 84

Using Point Lists to Calculate Geometric Values 84

Measuring Angular and Distance Values 85

Calculating Points 86

Finding and Snapping to Points 86

Translating Points 88

Converting Measurement Units 88

Accessing the AutoCAD Calculator 89

Converting Lists to Strings and Strings to Lists 90

Exercise: Adding Holes to the Plate 90

Defining the New Get-Sysvars and Set-Sysvars Utility Functions 91

Defining the New createcircle Utility Function 93

Revising the drawplate Function 94

Using the Revised drawplate Function 95

Chapter 5 • Requesting Input and Using Conditional and Looping Expressions 97

Interacting with the User 97

Requesting Input at the Command Prompt 98

Providing Feedback to the User 113

Working with the Graphics Windows 118

Conditionalizing and Branching Expressions 120

Comparing Values 120

Grouping Comparisons 126

Validating Values 126

Evaluating if a Condition Is Met 127

Testing Multiple Conditions 129

Repeating and Looping Expressions 131

Repeating Expressions a Set Number of Times 132

Performing a Task While a Condition Is Met 133

Exercise: Getting Input from the User to Draw the Plate 137

Revising the drawplate Function 137

Using the Revised drawplate Function 140

Chapter 6 • Creating and Modifying Graphical Objects 143

Working with Entity Names and Dotted Pairs 143

Creating a Dotted Pair 145

Accessing the Elements of an Entity Data List and Dotted Pair 146

Adding Objects to a Drawing 147

Selecting Objects 152

Selecting an Individual Object 152

Working with Selection Sets 154

Filtering Selected Objects 160

Modifying Objects 161

Listing and Changing the Properties of an Object Directly 162

Updating an Object’s Properties with an Entity Data List 168

Deleting an Object 171

Highlighting Objects 172

Working with Complex Objects 173

Creating and Modifying Polylines 173

Creating and Modifying with Block References 176

Extending an Object’s Information 180

Working with XData 180

Defining and Registering an Application Name 181

Attaching XData to an Object 181

Querying and Modifying the XData Attached to an Object 184

Removing XData from an Object 186

Selecting Objects Based on XData 186

Exercise: Creating, Querying, and Modifying Objects 187

Revising the Functions in utilitylsp 187

Testing the Changes to the drawplate Function 188

Defining the New Get-DXF-Value and Set-DXF-Value Utility Functions 189

Moving Objects to Correct Layers 190

Creating a Basic Block Attribute Extraction Program 192

Using the Functions in the furntoolslsp File 196

Chapter 7 • Creating and Modifying Nongraphical Objects 199

Working with Symbol Tables 199

Accessing and Stepping through Symbol Tables 200

Adding and Modifying Entries in a Symbol Table 202

Creating and Modifying Block Definitions 208

Working with Dictionaries 210

Accessing and Stepping through Dictionaries 210

Creating a Custom Dictionary 213

Storing Information in a Custom Dictionary 215

Managing Custom Dictionaries and Entries 215

Exercise: Creating and Incrementing Room Labels 216

Revising the createlayer Function in utilitylsp 217

Creating the Room Label Block Defi nition 217

Inserting a Block Reference Based on the Room Label Block Definition 219

Prompting the User for an Insertion Point and Room Number 222

Adding Room Labels to a Drawing 224

Chapter 8 • Working with the Operating System and External Files 227

Storing Information in the Windows Registry or a Plist File 227

Creating and Querying Entries 228

Editing and Removing Entries 230

Accessing Data from External Files 231

Opening and Creating an External File 231

Reading Characters and Lines from a File 234

Writing Characters and Lines from a File 235

Closing an Open File 236

Working with Directories and Files in the Operating System 237

Locating and Listing Files and Directories 237

Managing Files and Directories 243

Getting Information about a File 244

Exercise: Reading and Writing Data 244

Creating Layers Based on Data Stored in an External File 245

Adding Layers to a Drawing with the loadlayers Function 247

Writing the Bill of Materials to an External File 248

Using the furnbomexport Function 249

Chapter 9 • Catching and Handling Errors 251

Identifying and Tracking Down Errors 251

Putting Your Code Under the Microscope 252

Displaying Messages During Execution 254

Tracing Functions 259

Catching Errors in a Program 260

Defining and Using a Custom Error Handler 262

Grouping Functions into a Single Undo Action 263

Exercise: Handling Errors in the drawplate Function 266

Using the drawplate Function 267

Implementing a Custom *error* Handler and Undo Grouping 268

Testing the Changes to the drawplate Function 269

Chapter 10 • Authoring, Managing, and Loading AutoLISP Programs 271

Storing AutoLISP Expressions 271

Selecting an Editing Environment 272

Creating an AutoLISP File 272

Editing an AutoLISP File 274

Writing Modular Code 275

Adding Comments 276

Undefining and Redefining Standard AutoCAD Commands 279

Defining a Startup Function 280

Loading AutoLISP Files 281

Manually Loading an AutoLISP File 281

Automatically Loading an AutoLISP File 282

Using the Load/Unload Applications Dialog Box to Load a LSP File 284

Managing the Locations of AutoLISP Files 287

Specifying Support File Search Paths 287

Identifying Trusted Locations 289

Deploying AutoLISP Files 291

Deployment Methods (Local vs External) 292

Defining a Plug-in Bundle 294

Implementing Help for Custom Functions 296

Exercise: Deploying the drawplate Function 298

Loading the utilitylsp File by Reference 298

Loading the drawplatelsp File on Demand 299

Enabling Help Support for the drawplate Function 299

Configuring the AutoCAD Support and Trusted Paths 300

Testing the Deployment of the drawplate Function 301

Creating DrawPlatebundle 302

Deploying and Testing the DrawPlatebundle 303

Chapter 11 • Using the Visual LISP Editor (Windows only) 305

Accessing the Visual LISP Editor 305

Managing AutoLISP Files with the Visual LISP Editor 306

Formatting an AutoLISP File 307

Coloring Syntax 308

Formatting Code 309

Commenting Code 310

Validating and Debugging Code 310

Executing Code from the Visual LISP Editor 310

Checking and Loading Code in the Current Editor Window 311

Debugging Code 313

Creating a Visual LISP Project 315

Compiling LSP and PRJ Files into a VLX File 317

Exercise: Working with the Visual LISP Editor 318

Formatting, Checking, and Debugging the badcode Function 318

Stepping Through and Inspecting the badcode Function 320

Creating and Compiling a Project 323

Chapter 12 • Working with ActiveX/COM Libraries (Windows only) 325

Understanding the Basics of ActiveX 325

Accessing Classes, Objects, and Collections 326

Specifying Properties and Invoking Methods 329

Working with Variants and Arrays 332

Importing COM Libraries 336

Using the AutoCAD COM Library 337

Accessing the AutoCAD Application and Current Drawing Objects 338

Working with Graphical and Nongraphical Objects in the Current Drawing 339

Monitoring Events with Reactors 342

Leveraging the Windows and Microsoft Office COM Libraries 344

Accessing the Windows Shell Object 345

Working with Microsoft Office 347

Chapter 13 • Implementing Dialog Boxes (Windows only) 349

What Is Dialog Control Language? 349

Defining and Laying Out a Dialog Box 351

Defining a Dialog 351

Adding Tiles 352

Grouping, Aligning, and Laying Out Tiles 356

Creating and Previewing a Dialog in a DCL File 360

Loading and Displaying a Dialog Box 362

Loading and Unloading a DCL File 362

Displaying a Dialog 363

Initializing Tiles 365

Interacting with and Responding to a User 369

Specifying the Action of a Tile 369

Getting Information about a Tile 370

Terminating or Closing a Dialog Box 371

Hiding a Dialog Box Temporarily 372

Exercise: Implementing a Dialog Box for the drawplate Function 373

Creating the drawplate Dialog Box 374

Renaming the Existing drawplate Function 376

Defining a New drawplate Function 376

Testing the drawplatelsp Changes 379

Index 381