sales@landfx.com
  +1 805-541-1003

Activated

100% - 1 votes

AutoLISP Basics

Jun 29, 2018
Video Length:  1:02:29
Presented By:  Jeremiah Farmer
AutoLISP is a hidden gem within AutoCAD – a robust and capable programming language that’s easy to test and develop right from the CAD Command line. Land F/X CEO Jeremiah Farmer has been working with AutoLISP for more than 20 years and will start you off with the basics. This webinar will include recommendations on development environment, best coding practices, and helpful resources along the way. We’ll even program a simple function in real time to show you how it all comes together.

 

 

Helpful downloads:

 

Webinar Contents:

Note: The following catalog of content covered in this webinar is time stamped to allow you to follow along or skip to sections of the video that are relevant to your questions. You can also search for content on this page using the FIND command in your browser (CTRL + F in Windows, Command + F in Mac OS.)

  • Intro/TOC
  • What is AutoLISP?
  • What Can Be Done with AutoLISP?
  • Data Types, Function Organization, Code Techniques
  • Do’s and Do Not Do’s
  • Development Environment
  • Make a Simple Function!

 

0:00 – 3:32: Intro/TOC

3:33 – 6:02: What is AutoLISP?

  • Command line interpreted programming language (i.e., it’s not compiled somewhere else and then run as a binary executable. It’s fed, line by line, to the AutoCAD Command line.)
  • Intermix commands and complete functions
    • Functions can run AutoCAD commands
    • Any AutoLISP statement or function can be tested at the Command line.
    • Functions can prompt for input, display dialog boxes, modify entries.
    • Complete program can have a ribbon, database access, cloud connectivity, create/download blocks, wrap AutoCAD commands (e.g., Land F/X).
  • A very powerful addition to AutoCAD!

 

LISP basics (5:25)

LISP is a language of mathematics.

6:03 – 8:14: What Can Be Done with AutoLISP?

LISP essentials, operators and operants (6:03)

8:15 – 29:05: Data Types, Function Organization, Code Techniques

Data types (8:15)

  • Boolean – example: t / nil
  • Integer ­– example: 0, 1, 2, 3, -65536, 1073741824
  • Real ­– example: 3.141592653589793
  • String – example: “Hi, Mom!”

 

Lists (10:15)

  • Basic – example: (1 2 3 4)
  • Very common: a point – example: (101.222 319.045 0.0)

In other programming languages, you would need to declare a variable as a 3D point. In AutoLISP, a point is simply a list that includes three real numbers.

  • Lists within lists – example: ( (0 . 10.0) (1 . 4) (2 . “Hi, Mom”) (3 . 75.44139) )
  • Entity access – example: ( (0 . “LINE”) (67 . 0) (8 . “0”) (10 250.831 43.694 0.0) (11 271.714 55.7062 0.0) )

This example shows a line between two particular points in Model Space.

 

Command Line calls (14:32)

 

Function basics (18:45)

 

Vocabulary (21:47)

Autodesk has a Functions Reference page for AutoLISP, where you can learn all the functions. 

 

Examples of LISP vocabulary (23:55)

 

Design philosophy (26:20)

 

Example of Land F/X code (27:30)

 

Comments (28:55)

29:06 – 30:54: Do’s and Do Not Do’s

The importance of including comments in your code (29:06)

30:55 – 34:19: Development Environment

Our recommendations:

  • UltraEdit
    • AutoLISP word file (autolisp.uew)
    • Nice code writing font (Source Code Pro, Lucida Console)
  • AutoCAD Support File Search Path
  • -ommand to reload
  • Error function

 

Getting help (32:35)

34:20 – end: Make a Simple Function!

Examples of creating a simple function with and without a helper function (34:20)

 

Example of writing code for a function: selecting a layer and changing its color (38:25)

 

Checking the list of AutoCAD entities and their codes (43:17)

 

Error checking (51:10)

 

Question: Do you recommend using an integrated development environment (IDE)? (55:40)

Answer: Yes, but  Jeremiah doesn’t recommend using the Autodesk IDE. Autodesk stopped developing AutoLISP in 2002, so their IDE is quite difficult to work with. He recommends using a good code editor such as:

UltraEdit

Notepad++

 

Above all, make sure to:

  • Program slowly and meticulously
  • Put in your own breakpoints
  • Include access panels (and leave them in place)

 

How to adjust the LISP function created in this presentation if all lines inside a block are on Layer 0, how would you adjust the LISP created in this presentation (58:05)

Log in to landfx.com:

Username:

Password: