1 / 32

Chapter 8 - AutoLISP by Example: Getting Started

AutoCAD: Secrets Every User Should Know. Chapter 8 - AutoLISP by Example: Getting Started. Key Topics. Entity Selection and Manipulation Constructing New Points String Conversion and Manipulation Debugging and Troubleshooting Techniques Annotating and Error-Trapping. Programming Tools.

Download Presentation

Chapter 8 - AutoLISP by Example: Getting Started

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. AutoCAD: Secrets Every User Should Know Chapter 8 - AutoLISP by Example: Getting Started

  2. Key Topics • Entity Selection and Manipulation • Constructing New Points • String Conversion and Manipulation • Debugging and Troubleshooting Techniques • Annotating and Error-Trapping

  3. Programming Tools • AutoLISP • Based on LISP from 1950s • Good User Language • Can use AutoCAD commands • Can use AutoCAD variables • VLISP Added AutoCAD 200 • Uses AutoCAD Commands VBA and VB.NET C++

  4. Saving AutoLISP Programs • Writing • Text Editor • Visual LISP Editor • NO Word Processors • Saving • ASCII Text File • .LSP extension • ACADDOC.lsp Loads in Each Drawing • ACAD.lsp Loads Only When AutoCAD Fires Up

  5. Loading Programs • Three ways to load AutoLISP • Type it at the command line • or copy/paste to the command line • Load a text file that contains AutoLISP code • (load “program.lsp”) • APPLOAD Startup Suite • Use the load function of the Visual LISP editor

  6. Visual LISP Editor • Start Visual LISP Editor • VLISP or VLIDE • ToolsAutoLISPVisual LISP Editor • Four Windows • Text editor: type your program (more than one can be open) • Visual LISP console: type variable names or pieces of code • Trace window: use while debugging • Build Output window: warnings and error messages

  7. Visual LISP - Color Coding

  8. VLISP Tools

  9. AutoLISP by Example • Or format like this:

  10. Program Structure • Programs Contain AutoLISP Functions • DEFUN, SETVAR, +, and - • Function Name Is Preceded by an Opening Parenthesis • (defun, or (command, or (+ • Balance Parentheses • Separate Atoms with Spaces or Quotation Marks • Functions Are Followed by Arguments, if They’re Necessary

  11. Breaking Down the Code (defun c:00() Defun is an AutoLISP expression C: means “command” not drive (setvar “osmode” 4143) Setvar is an AutoLISP expression “osmode” is a system variable 4143 is a bit sum setting ) Closes opening parenthesis in line 1

  12. Bit Sum 1, 2, 4, 8, 16, 32, 64, 128, etc. • Why 4143? • End, Mid, Cen, Nod, Int, and Ext as running osnaps • Type OSMODE at the command line • Returns 4143 • 1+2+4+8+32+4098 = 4143.

  13. Building on the Basics

  14. Background - Variables • System Variables • Over 550 in AutoCAD 2007 • Examples: APERTURE; AUPREC; LUPREC • Some saved in drawing, others in Registry • (getvar “aperture”) (setvar “aperture” 3) • Environment Variables – Operating System • Examples: “MaxHatch” "HideSystemPrinters" • Saved in Registry • (getenv “MaxHatch”) (setenv “MaxHatch” “100000000”)

  15. Background - Variables • Program Variables • Defined by the programmer using SETQ • Global (defun C:MID () • Retain their value when program terminates • Useful for debugging • Often Changed to Local • Can be used to create a persistent default value • Local (defun C:MID (/ os ap m) • Return to nil when program terminates • !variable at command line to get value

  16. SETQ

  17. Deciphering the Code

  18. Creating New Coordinates Structural Lumber Symbol Get Point1 and Point 2 from User Create Point3 from X of Point 1 and Y of Point2 Create Point4 from X of Point 2 and Y of Point1

  19. Creating New Coordinate Points - LIST

  20. Creating New Points - POLAR Dimension Between Walls

  21. Creating New Points - POLAR Polar pt Angle Distance

  22. Calculations

  23. Calculations - More

  24. Calculations in Programs

  25. Angles Radians vs. Degrees AutoLISP uses Radians Radian: included angle of arc with length of 1

  26. Angles Radian Problems

  27. Angles Radians vs. Degrees Conversion Functions

  28. Transparent Commands Two Methods ‘I2M will work for many command functions Call non-command functions as Lisp

  29. Combining Programs SSECT and RC

  30. Ten Basic Rules • Save as ASCII. • Use Equal Number of Opening and Closing Parens. • DEFUN Means Define Function; C:ZX Is a Command. • Balance Quotation Marks. • Backslash Is a Control Character: \\ or / for Folders. • Leave Space After Forward Slash for Local Variables. • \n Controls New Line in Prompt and Is Lowercase. • Use Semicolons for Comments. • Get Values at Beginning; Use SETQ to Save Them. • Don't Get Discouraged!

  31. Automatic Loading APPLOAD Startup Suite Any LSP program placed by user ACAD.lsp Loads when AutoCAD starts IF in the path Loads in subsequent drawings IF ACADLSPASDOC=1 ACADDOC.lsp Loads with each drawing IF in the path (There are some others, but you probably don’t want to mess them up)

  32. Automatic Loading Startup Functions

More Related