AutoCAD Platform Customization: AutoLISP

AutoCAD Platform Customization: AutoLISP

by Lee Ambrosius


View All Available Formats & Editions
Eligible for FREE SHIPPING
  • Want it by Thursday, September 27  Order now and choose Expedited Shipping during checkout.


AutoCAD Platform Customization: AutoLISP by Lee Ambrosius

Customize and personalize programs built on the AutoCADplatform

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

AutoCAD Platform Customization: AutoLISP providesreal-world examples that show you how to do everything frommodifying graphical objects and reading and setting systemvariables to communicating with external programs. It also featuresa resources appendix and downloadable datasets and customizationexamples—tools that ensure swift and easy adoption.

  • Find out how to remove unused buttons from the ribbon to gainscreen 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, likecommunicating with a database to validate and update informationentered in drawing layers
  • Ideal for CAD administrators, senior drafters, savvy users, andother professionals and students

Through detailed discussions and tutorials that includereal-world examples, this book gives you the power to enhance yourprogram's experience and output.

Product Details

ISBN-13: 9781118798812
Publisher: Wiley
Publication date: 08/18/2014
Pages: 432
Product dimensions: 7.30(w) x 9.10(h) x 0.90(d)

About the Author

Lee Ambrosius is a Principal Learning Content Developerat Autodesk for AutoCAD and AutoCAD LT products and has worked onend-user and API documentation for nine releases. He has presentedcustomization and programming sessions at Autodesk University for adecade, and has authored and edited several AutoCAD-related books.Follow him on twitter at @leeambrosius.

Table of Contents

Introduction xix

Chapter 1 • Quick Start for New AutoLISP Programmers1

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 withValues 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 UtilityFunctions 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 andLooping 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 thePlate 137

Revising the drawplate Function 137

Using the Revised drawplate Function 140

Chapter 6 • Creating and Modifying Graphical Objects143

Working with Entity Names and Dotted Pairs 143

Creating a Dotted Pair 145

Accessing the Elements of an Entity Data List and DottedPair 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 ObjectDirectly 162

Updating an Object’s Properties with an Entity DataList 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 anObject 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 UtilityFunctions 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 NongraphicalObjects 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 BlockDefinition 219

Prompting the User for an Insertion Point and RoomNumber 222

Adding Room Labels to a Drawing 224

Chapter 8 • Working with the Operating System andExternal Files 227

Storing Information in the Windows Registry or a Plist File227

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 OperatingSystem 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 ExternalFile 245

Adding Layers to a Drawing with the loadlayersFunction 247

Writing the Bill of Materials to an External File 248

Using the furnbomexport Function 249

Chapter 9 • Catching and HandlingErrors 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 UndoGrouping 268

Testing the Changes to the drawplate Function 269

Chapter 10 • Authoring, Managing, and Loading AutoLISPPrograms 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 File284

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 (Windowsonly) 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 Objects338

Working with Graphical and Nongraphical Objects in the CurrentDrawing 339

Monitoring Events with Reactors 342

Leveraging the Windows and Microsoft Office COM Libraries344

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 Function373

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

Customer Reviews

Most Helpful Customer Reviews

See All Customer Reviews