AutoLISP Module 6 Competency Test No.1

Similar documents
CMSC 313 Lecture 03 Multiple-byte data big-endian vs little-endian sign extension Multiplication and division Floating point formats Character Codes

ASCII Code - The extended ASCII table

CMSC 313 COMPUTER ORGANIZATION & ASSEMBLY LANGUAGE PROGRAMMING LECTURE 02, FALL 2012

OOstaExcel.ir. J. Abbasi Syooki. HTML Number. Device Control 1 (oft. XON) Device Control 3 (oft. Negative Acknowledgement

CMSC 313 COMPUTER ORGANIZATION & ASSEMBLY LANGUAGE PROGRAMMING LECTURE 02, SPRING 2013

APPLESHARE PC UPDATE INTERNATIONAL SUPPORT IN APPLESHARE PC

CMSC 313 COMPUTER ORGANIZATION & ASSEMBLY LANGUAGE PROGRAMMING LECTURE 02, FALL 2012

Chemistry Hour Exam 2

1.1. INTRODUCTION 1.2. NUMBER SYSTEMS

Number Systems II MA1S1. Tristan McLoughlin. November 30, 2013

Chapter 2 Number System

DATA REPRESENTATION. Data Types. Complements. Fixed Point Representations. Floating Point Representations. Other Binary Codes. Error Detection Codes

Fundamentals of Programming (C)

Acquirer JCB EMV Test Card Set

First Data EMV Test Card Set. Version 1.30

First Data EMV Test Card Set. Version 2.00

First Data Dual Interface EMV Test Card Set. Version 1.20

Fundamentals of Programming

4. Specifications and Additional Information

Data Representation and Binary Arithmetic. Lecture 2

CIS-331 Exam 2 Fall 2015 Total of 105 Points Version 1

Unit 3, Lesson 2 Data Types, Arithmetic,Variables, Input, Constants, & Library Functions. Mr. Dave Clausen La Cañada High School

Experiment 3. TITLE Optional: Write here the Title of your program.model SMALL This directive defines the memory model used in the program.

CIS-331 Fall 2013 Exam 1 Name: Total of 120 Points Version 1

CIS-331 Spring 2016 Exam 1 Name: Total of 109 Points Version 1

First Data DCC Test Card Set. Version 1.30

USB-ASC232. ASCII RS-232 Controlled USB Keyboard and Mouse Cable. User Manual

2a. Codes and number systems (continued) How to get the binary representation of an integer: special case of application of the inverse Horner scheme

Number System (Different Ways To Say How Many) Fall 2016

Acquirer JCB Dual Interface EMV Test Card Set

CIS-331 Fall 2014 Exam 1 Name: Total of 109 Points Version 1

Representing Things With Bits

Interac USA Interoperability EMV Test Card Set

CIS-331 Exam 2 Fall 2014 Total of 105 Points. Version 1

Chapter 2 Bits, Data Types, and Operations

plc numbers Encoded values; BCD and ASCII Error detection; parity, gray code and checksums

CS/ECE 252: INTRODUCTION TO COMPUTER ENGINEERING UNIVERSITY OF WISCONSIN MADISON

1. Character/String Data, Expressions & Intrinsic Functions. Numeric Representation of Non-numeric Values. (CHARACTER Data Type), Part 1

CIS-331 Exam 2 Spring 2016 Total of 110 Points Version 1

CS/ECE 252: INTRODUCTION TO COMPUTER ENGINEERING UNIVERSITY OF WISCONSIN MADISON

Chapter 2 Bits, Data Types, and Operations

EXPERIMENT 8: Introduction to Universal Serial Asynchronous Receive Transmit (USART)

Number Systems Base r

Chapter 2 Bits, Data Types, and Operations

Bits and Bytes. Data Representation. A binary digit or bit has a value of either 0 or 1; these are the values we can store in hardware devices.

EXPERIMENT 7: Introduction to Universal Serial Asynchronous Receive Transmit (USART)

Number Systems for Computers. Outline of Introduction. Binary, Octal and Hexadecimal numbers. Issues for Binary Representation of Numbers

Coding Theory. Networks and Embedded Software. Digital Circuits. by Wolfgang Neff

Binary Numbers. The Basics. Base 10 Number. What is a Number? = Binary Number Example. Binary Number Example

Chapter 3. Information Representation

*.lsp Commands: + - * / setq setvar getvar getpoint defun command getstring appload vlide

EE 109 Unit 3. Analog vs. Digital. Analog vs. Digital. Binary Representation Systems ANALOG VS. DIGITAL

Exercises Software Development I. 03 Data Representation. Data types, range of values, internal format, literals. October 22nd, 2014

Chapter 2 Bits, Data Types, and Operations

Fundamental Data Types

Midterm Exam, Fall 2015 Date: October 29th, 2015

EE 109 Unit 2. Analog vs. Digital. Analog vs. Digital. Binary Representation Systems ANALOG VS. DIGITAL

Positional Number System

Numbers and Computers. Debdeep Mukhopadhyay Assistant Professor Dept of Computer Sc and Engg IIT Madras

ECHO Process Instrumentation, Inc. Modbus RS485 Module. Operating Instructions. Version 1.0 June 2010

FD-011WU. 2D Barcode Reader User Guide V1.6CC

The Binary Number System

Characters Lesson Outline

CIS-331 Final Exam Spring 2018 Total of 120 Points. Version 1

CS341 *** TURN OFF ALL CELLPHONES *** Practice NAME

Number Representations

CPS 104 Computer Organization and Programming Lecture-2 : Data representations,

6.1 Font Types. Font Types

Chapter 2 Bits, Data Types, and Operations

Gateway Ascii Command Protocol

Oberon Data Types. Matteo Corti. December 5, 2001

VT420 Video Terminal Programmer Reference Manual Update

S-Series Sensor ASCII Protocol v8.1.0

6.1 Combinational Circuits. George Boole ( ) Claude Shannon ( )

3.1. Unit 3. Binary Representation

PJ-600 Series Printer ESC/P Command Reference

J2 LCM Customer Display. Manual

Communications guide. Line Distance Protection System * F1* GE Digital Energy. Title page

CIS-331 Final Exam Spring 2015 Total of 115 Points. Version 1

EE 109 Unit 2. Binary Representation Systems

MK D Imager Barcode Scanner Configuration Guide

UNIT 2 NUMBER SYSTEM AND PROGRAMMING LANGUAGES

Do not start the test until instructed to do so!

Unit 3. Analog vs. Digital. Analog vs. Digital ANALOG VS. DIGITAL. Binary Representation

Beijer Electronics AB 2000, MA00453,

CCD - 75 USB. Programming Manual. GOMARO s.a. - Z.I. La Rosaire 5 - CH Aclens

ZN-DN312XE-M Quick User Guide

Chapter 8. Characters and Strings

Do not start the test until instructed to do so!

Data Representa5on. CSC 2400: Computer Systems. What kinds of data do we need to represent?

C1098 JPEG Module User Manual

CSE-1520R Test #1. The exam is closed book, closed notes, and no aids such as calculators, cellphones, etc.

RS 232 PINOUTS. 1. We use RJ12 for all of our RS232 interfaces (Link-2-Modbus & Link-2-PC- Serial/RS232). The diagram below shows our pin out.

Data Representa5on. CSC 2400: Computer Systems. What kinds of data do we need to represent?

CSE-1520R Test #1. The exam is closed book, closed notes, and no aids such as calculators, cellphones, etc.

Introduction to Decision Structures. Boolean & If Statements. Different Types of Decisions. Boolean Logic. Relational Operators

Mounting Dimensions / Viewing 2 Mounting Options 3. Wiring Configuration 4. Quick Set up Procedure 5. Changing Intensity 6.

Lecture (09) x86 programming 8

July Registration of a Cyrillic Character Set. Status of this Memo

One station Impact Printer. Model: WP-300 Version : 1.03

Transcription:

AutoCAD Self-paced ecourse AutoLISP Module 6 Competency Test No.1 Learning Outcomes When you have completed this module, you will be able to: 1 Complete a written exam and write an AutoLISP program on the principles taught in Module 1 to Module 5. Competency Tests The AutoCAD Self-paced ecourses were written with competency based modules. What that means to you as a student is that you have not completed each module until you have mastered it. To master a module, you must prove that you understand the material contained in it and have completed the lab exercises with 100% accuracy. A competency test module contains multiple choice questions and a comprehensive lab exercise to test the users mastery of the last set of modules completed. There are no answers supplied with a competency test module since it is meant to be checked by your instructor. If there are any parts of this module that you have trouble completing, go back and reread the module or modules containing the information that you are having trouble with. If necessary, redo as many workalongs and lab exercises in those modules until you fully understand the material. Students Using this ebook in a Classroom Setting Students using this ebook in a classroom setting will be given instructions on what to do after they have completed this module. Students Using this ebook by Correspondence or Distance Education Complete the following steps: Step 1 Answer the 20 multiple choice questions on pages 6-2 to 6-5. Record the answers. Step 2 Complete Lab Exercise 6-1 on page 6-6. Step 3 Login into the website www.cadinstructors.com with your name and ID number. In the website, write the online written test for Module 6 - Competency Test No. 1. It has the same 20 questions that you answered in Step 1. Step 4 Submit the file AutoLISP Lab 06-1.lsp when you write the test. Follow the prompts on the website. Step 5 If you have any problems completing Steps 1 to 4, ask your instructor for help. Step 6 Go on to Module 7. Competency Test No. 1 The CAD Guys Ltd. Copyright 1993-2013 Module 6

6-2 AutoCAD Self-paced ecourse - AutoLISP - Revised 2013-04-09 Select the BEST answer. AutoLISP Competency Test No. 1 Open Book Multiple Choice Questions 1 What is the name of the AutoLISP processor to which AutoLISP sends all of the expressions to be evaluated? A) Lisp B) Evaluator C) Parentheses D) Calculator E) Heap 2 In what version of AutoCAD was AutoLISP added? A) 1.0 B) 2.10 C) 2.18 D) 9.0 E) 10.0 3 AutoLISP is an implementation of the LISP programming language. What was the name LISP derived from? A) List Parentheses B) Long Programming C) Listing Processor D) Lisp is Programing E) List Processing 4 What is the answer to the following mathematical formula? ((17 + ((2 X 3) + 4)) + (((5 + (3 X 4)) - 11) + 15)) A) 12 B) 32 C) 48 D) 17 E) 90 5 What is the meaning of an initial space in an AutoLISP program to the AutoLISP evaluator? A) Nothing. B) To go to the next line. C) To ignore the line. D) To stop processing. E) That the last item is complete. Competency Test No. 1 The CAD Guys Ltd. Copyright 1993-2013 Module 6

AutoCAD Self-paced ecourse - AutoLISP - Revised 2013-04-09 6-3 6 Which one of the following is the definition of a local variable? A) A variable that cannot be changed by the user. B) A variable that is saved when the program ends. C) A variable that stays in RAM memory only while the AutoLISP program, where the variable is assigned its value or a program called by that program, is running. D) A variable that stays in RAM memory until the expression that created it ends. E) A variable that is constant. 7 Given the following program, which one of the following items is the program's argument? (defun dtor (angd) (* pi (/ angd 180.0)) ) A) angd B) dtor C) defun D) pi E) * 8 What would the following expression return? (setq num1 (- (* (+ 4 5) 3) 6)) A) 21 B) 20 C) 15 D) 58 E) 12 9 Given the following, which one is a real number to the AutoLISP evaluator? A) 2 B) -2000 C).5 D) "2.5" E) 1.1 10 How many radians would an angle of 283 degrees equal? A) 4.83992 B) 4.26172 C) 4.99393 D) 4.93928 E) 4.92922 Competency Test No. 1 The CAD Guys Ltd. Copyright 1993-2013 Module 6

6-4 AutoCAD Self-paced ecourse - AutoLISP - Revised 2013-04-09 11 Why is it important to have a line indicating the end of the program in each AutoLISP program? A) To identify the end of the program to the users reading or editing the program. B) To tell AutoLISP where to end the program. C) It has no useful purpose. D) It makes the program look better. E) It tells AutoLISP how long the program is before it is run. 12 What does the AutoLISP evaluator do when it finds multiple spaces in an AutoLISP program? A) It ignores the line they are on. B) Skips to the next line of the program. C) Ignores them and treats them as an single space D) It stops the program. E) It skips the next two lines in the program. 13 What does a semicolon in an AutoLISP program instruct the AutoLISP evaluator to do? A) To ignore the remainder the line. B) To start the program at the next line. C) To ignore them and treat them as spaces. D) To stop the program. E) To skip the next two lines in the program. 14 Given the following, which one is an acceptable variable name in an AutoLISP program? A) 1 ang B) ang 1 C) (ang1) D) angle E) ang1 15 What would the following expression return? (setq num2 (* pi (+ 5 3.3))) A) 12.3435 B) 14.9273 C) 26.0752 D) 34.7273 E) nil Competency Test No. 1 The CAD Guys Ltd. Copyright 1993-2013 Module 6

AutoCAD Self-paced ecourse - AutoLISP - Revised 2013-04-09 6-5 16 Why is it important to indent lines in an AutoLISP program? A) The program will not run without it. B) It helps the programmer read, edit, and understand the program. C) It instructs the AutoLISP interpreter to ignore the line. D) It instructs the AutoLISP evaluator to return a result on the line. E) It instructs the AutoLISP interpreter to stop processing the program. 17 What is the largest integer that can be passed to AutoCAD from AutoLISP? A) 2,000 B) 32,767 C) 16 D) 1024 E) 256 18 What would the following expression return? (princ "\nhello my name is \"John\"")(princ) A) Hello my name is \"John\" B) Hello my name is John C) Hello my name is "John" D) Hello my name is "John" E) nil 19 What would the following expression return? (setq ans1 3 ans2 4.5 ans3 "y") A) nil B) 3 4.5 "y" C) "y" D) nothing E) T 20 What does an expression that has been entered in upper-case characters mean to AutoLISP? A) It's the most important function. B) To ignore the function. C) To process the function first. D) Nothing. E) It's an AutoCAD command. Competency Test No. 1 The CAD Guys Ltd. Copyright 1993-2013 Module 6

6-6 AutoCAD Self-paced ecourse - AutoLISP - Revised 2013-04-09 Lab Exercise 6-1 Program Name AutoLISP Lab 06-1.lsp Template AutoLISP English Purpose: To write a program, using arguments, that calculates the number of square inches remaining when the largest circle is placed inside a square and prints the answers. The size of the square is entered by the user. Step 1 Step 2 Step 3 Step 4 Create a program naming it AutoLISP Lab 06-1.lsp Write a function, named AREAREM, that runs as an AutoCAD command. Declare all variables as local variables. Prompt the user to enter the length of one side of the square. Save it as a real number. Step 5 Calculate the area of the circle and the square. (Figure Step 5) Figure Step 5 Step 6 Calculate the area remaining when the area of the circle is subtracted from the area of the square. Step 7 The program must include the two additional functions, cofs and cofc, that runs with arguments sent to them. Step 8 The function cofs calculates the circumference of a square. Step 9 The function cofc calculates the circumference of a circle. Competency Test No. 1 The CAD Guys Ltd. Copyright 1993-2013 Module 6

AutoCAD Self-paced ecourse - AutoLISP - Revised 2013-04-09 6-7 Step 10 Open the Text window. Step 11 Print the answers as shown in the figure. Step 12 Prevent the program from printing a return when it ends. Step 13 Load and run the program in AutoCAD. (Figure Step 13) Figure Step 13 Author's Comments: This program does not draw anything in AutoCAD. It simply asks the user to enter the length of one side of a square, calculates the necessary answers and prints them as show in Figure Step 13. Competency Test No. 1 The CAD Guys Ltd. Copyright 1993-2013 Module 6

AutoCAD Self-paced ecourse AutoLISP Module 12 Looping - Part 1 Learning Outcomes When you have completed this module, you will be able to: 1 Describe the ASCII code and the binary, decimal, hexadecimal and octal numbering systems. 2 Describe and apply the =, /=, >, <, <= and >= functions. 3 Describe and apply the while and cond functions. ASCII Code The American Standard Code of Information Interchange (ASCII code) was design to standardize characters on the keyboard. See Table 12-1 on pages 12-2 to 12-9. Study it, and pay special attention to the ASCII column. Binary Numbers All computers work in binary numbers. The binary number system is made up exclusively of 0's and 1's. Each binary digit is called a bit and 8 bits make a byte. There are 256 different combinations of 0's and 1's in one byte. When a key is pressed on the keyboard, it sends a one byte binary number to the CPU. Counting in binary numbers is as follows: 0000 0000 0000 0001 0000 0010 0000 0011 0000 0100... Decimal Numbers The decimal numbering system is based on multiples of 10. It is the numbering system used in everyone's day to day life. Counting in decimal numbers is as follows: 0 1 2 3 4 5 6 7 8 9 10 11... Hexadecimal Numbers The hexadecimal numbering system is based on multiplies of 16. To count to 16, it uses the letters A to F as a part of the numbering system. Counting in hexadecimal numbers is as follows: 0 1 2 3 4 5 6 7 8 9 A B C D E F 10 11 12 13 14 15 16 17 18 19 1A 1B... It takes one hexadecimal number for all the combinations in 4 bits, called a nibble. It takes 2 hexadecimal numbers for all the combinations in one byte or 256 different combinations. Octal Numbers The octal numbering system is based on multiples of 8. The number 8 is important because it is 2 cubed. Counting in octal numbers is as follows: 0 1 2 3 4 5 6 7 10 11 12 13 14 15 16 17 20 21...

12-2 AutoCAD Self-paced ecourse - AutoLISP - Revised 2013-04-10 Table 12-1 ASCII Code 1 of 8 Binary Decimal Hexadecimal Octal ASCII Control Teletype 0000 0000 0 0 0 ^@ NUL null 0000 0001 1 1 1 ( ^A SOH Start of Header 0000 0010 2 2 2 ) ^B STX Start of Transmission 0000 0011 3 3 3 Ì ^C EXT End of Transmission 0000 0100 4 4 4 Ë ^D EOT End of Text 0000 0101 5 5 5 Ê ^E ENQ Enquiry 0000 0110 6 6 6 Í ^F ACK Acknowledge 0000 0111 7 7 7! ^G BEL bell 0000 1000 8 8 10 3 ^H BS backspace 0000 1001 9 9 11 " ^I HT horizontal tab 0000 1010 10 A 12 4 ^J LF line feed 0000 1011 11 B 13 % ^K VT vertical tab 0000 1100 12 C 14 & ^L FF form feed 0000 1101 13 D 15 * ^M CR carriage return 0000 1110 14 E 16 + ^N SO shift out 0000 1111 15 F 17 ' ^O SI shift in 0001 0000 16 10 20 < ^P DLE 0001 0001 17 11 21 = ^Q DC1 device control #1 0001 0010 18 12 22 ù ^R DC2 device control #2 0001 0011 19 13 23. ^S DC3 device control #3 0001 0100 20 14 24 ^T DC4 device control #4 0001 0101 21 15 25 ^U NAK negative acknowledge 0001 0110 22 16 26 ( ^V SYN 0001 0111 23 17 27 0 ^W ETB 0001 1000 24 18 30 8 ^X CAN cancel 0001 1001 25 19 31 9 ^Y EM 0001 1010 26 1A 32 6 ^Z EOF end of file 0001 1011 27 1B 33 7 ^[ ESC escape 0001 1100 28 1C 34 2 ^\ FS field separator 0001 1101 29 1D 35 : ^] GS 0001 1110 30 1 36 > ^^ RS record separator 0001 1111 31 1F 37? ^- US underscore

AutoCAD Self-paced ecourse - AutoLISP - Revised 2013-04-10 12-3 Table 12-1 ASCII Code 2 of 8 Binary Decimal Hexadecimal Octal ASCII Notes 0010 0000 32 20 40 Space character 0010 0001 33 21 41! 0010 0010 34 22 42 " 0010 0011 35 23 43 # 0010 0100 36 24 44 $ 0010 0101 37 25 45 % 0010 0110 38 26 46 & 0010 0111 39 27 47 ' 0010 1000 40 28 50 ( 0010 1001 41 29 51 ) 0010 1010 42 2A 52 * 0010 1011 43 2B 53 + 0010 1100 44 2C 54, 0010 1101 45 2D 55-0010 1110 46 2 56. 0010 1111 47 2F 57 / 0011 0000 48 30 60 0 0011 0001 49 31 61 1 0011 0010 50 32 62 2 0011 0011 51 33 63 3 0011 0100 52 34 64 4 0011 0101 53 35 65 5 0011 0110 54 36 66 6 0011 0111 55 37 67 7 0011 1000 56 38 70 8 0011 1001 57 39 71 9 0011 1010 58 3A 72 : 0011 1011 59 3B 73 ; 0011 1100 60 3C 74 < 0011 1101 61 3D 75 = 0011 1110 62 3 76 > 0011 1111 63 3F 77?

12-4 AutoCAD Self-paced ecourse - AutoLISP - Revised 2013-04-10 Table 12-1 ASCII Code 3 of 8 Binary Decimal Hexadecimal Octal ASCII Notes 0100 0000 64 40 100 @ 0100 0001 65 41 101 A 0100 0010 66 42 102 B 0100 0011 67 43 103 C 0100 0100 68 44 104 D 0100 0101 69 45 105 E 0100 0110 70 46 106 F 0100 0111 71 47 107 G 0100 1000 72 48 110 H 0100 1001 73 49 111 I 0100 1010 74 4A 112 J 0100 1011 75 4B 113 K 0100 1100 76 4C 114 L 0100 1101 77 4D 115 M 0100 1110 78 4 116 N 0100 1111 79 4F 117 O 0101 0000 80 50 120 P 0101 0001 81 51 121 Q 0101 0010 82 52 122 R 0101 0011 83 53 123 S 0101 0100 84 54 124 T 0101 0101 85 55 125 U 0101 0110 86 56 126 V 0101 0111 87 57 127 W 0101 1000 88 58 130 X 0101 1001 89 59 131 Y 0101 1010 90 5A 132 Z 0101 1011 91 5B 133 [ 0101 1100 92 5C 134 \ 0101 1101 93 5D 135 ] 0101 1110 94 5 136 ^ 0101 1111 95 5F 137 _

AutoCAD Self-paced ecourse - AutoLISP - Revised 2013-04-10 12-5 Table 12-1 ASCII Code 4 of 8 Binary Decimal Hexadecimal Octal ASCII Notes 0110 0000 96 60 140 ` 0110 0001 97 61 141 a 0110 0010 98 62 142 b 0110 0011 99 63 143 c 0110 0100 100 64 144 d 0110 0101 101 65 145 e 0110 0110 102 66 146 f 0110 0111 103 67 147 g 0110 1000 104 68 150 h 0110 1001 105 69 151 i 0110 1010 106 6A 152 j 0110 1011 107 6B 153 k 0110 1100 108 6C 154 l 0110 1101 109 6D 155 m 0110 1110 110 6 156 n 0110 1111 111 6F 157 o 0111 0000 112 70 160 p 0111 0001 113 71 161 q 0111 0010 114 72 162 r 0111 0011 115 73 163 s 0111 0100 116 74 164 t 0111 0101 117 75 165 u 0111 0110 118 76 166 v 0111 0111 119 77 167 w 0111 1000 120 78 170 x 0111 1001 121 79 171 y 0111 1010 122 7A 172 z 0111 1011 123 7B 173 { 0111 1100 124 7C 174 0111 1101 125 7D 175 } 0111 1110 126 7 176 ~ 0111 1111 127 7F 177 -

12-6 AutoCAD Self-paced ecourse - AutoLISP - Revised 2013-04-10 Table 12-1 ASCII Code 5 of 8 Binary Decimal Hexadecimal Octal ASCII Notes 1000 0000 128 80 200 Ç 1000 0001 129 81 201 ü 1000 0010 130 82 202 é 1000 0011 131 83 203 â 1000 0100 132 84 204 ä 1000 0101 133 85 205 à 1000 0110 134 86 206 å 1000 0111 135 87 207 ç 1000 1000 136 88 210 ê 1000 1001 137 89 211 ë 1000 1010 138 8A 212 è 1000 1011 139 8B 213 ï 1000 1100 140 8C 214 î 1000 1101 141 8D 215 ì 1000 1110 142 8 216 Ä 1000 1111 143 8F 217 Å 1001 0000 144 90 220 É 1001 0001 145 91 221 æ 1001 0010 146 92 222 Æ 1001 0011 147 93 223 ô 1001 0100 148 94 224 ö 1001 0101 149 95 225 ò 1001 0110 150 96 226 û 1001 0111 151 97 227 ù 1001 1000 152 98 230 ÿ 1001 1001 153 99 231 Ö 1001 1010 154 9A 232 Ü 1001 1011 155 9B 233 1001 1100 156 9C 234 1001 1101 157 9D 235 1001 1110 158 9 236. 1001 1111 159 9F 237 ƒ

AutoCAD Self-paced ecourse - AutoLISP - Revised 2013-04-10 12-7 Table 12-1 ASCII Code 6 of 8 Binary Decimal Hexadecimal Octal ASCII Notes 1010 0000 160 A0 240 á 1010 0001 161 A1 241 í 1010 0010 162 A2 242 ó 1010 0011 163 A3 243 ú 1010 0100 164 A4 244 ñ 1010 0101 165 A5 245 Ñ 1010 0110 166 A6 246 ª 1010 0111 167 A7 247 º 1010 1000 168 A8 250 1010 1001 169 A9 251 1 1010 1010 170 AA 252 1010 1011 171 AB 253 ½ 1010 1100 172 AC 254 ¼ 1010 1101 173 AD 255 1010 1110 174 AE 256 «1010 1111 175 AF 257» 1011 0000 176 B0 260! 1011 0001 177 B1 261 " 1011 0010 178 B2 262 # 1011 0011 179 B3 263 * 1011 0100 180 B4 264 1 1011 0101 181 B5 265 I 1011 0110 182 B6 266 M 1011 0111 183 B7 267 D 1011 1000 184 B8 270 @ 1011 1001 185 B9 271 < 1011 1010 186 BA 272 5 1011 1011 187 BB 273 7 1011 1100 188 BC 274 8 1011 1101 189 BD 275 E 1011 1110 190 BE 276 A 1011 1111 191 BF 277,

12-8 AutoCAD Self-paced ecourse - AutoLISP - Revised 2013-04-10 Table 12-1 ASCII Code 7 of 8 Binary Decimal Hexadecimal Octal ASCII Notes 1100 0000 192 C0 300. 1100 0001 193 C1 301 2 1100 0010 194 C2 302 0 1100 0011 195 C3 303 / 1100 0100 196 C4 304 ) 1100 0101 197 C5 305 3 1100 0110 198 C6 306 G 1100 0111 199 C7 307 K 1100 1000 200 C8 310 9 1100 1001 201 C9 311 6 1100 1010 202 CA 312 = 1100 1011 203 CB 313 ; 1100 1100 204 CC 314 : 1100 1101 205 CD 315 4 1100 1110 206 CE 316 > 1100 1111 207 CF 317 N 1101 0000 208 D0 320 J 1101 0001 209 D1 321 L 1101 0010 210 D2 322 H 1101 0011 211 D3 323 F 1101 0100 212 D4 324 B 1101 0101 213 D5 325? 1101 0110 214 D6 326 C 1101 0111 215 D7 327 O 1101 1000 216 D8 330 P 1101 1001 217 D9 331-1101 1010 218 DA 332 + 1101 1011 219 DB 333 $ 1101 1100 220 DC 334 ( 1101 1101 221 DD 335 % 1101 1110 222 DE 336 ' 1101 1111 223 DF 337 &

AutoCAD Self-paced ecourse - AutoLISP - Revised 2013-04-10 12-9 Table 12-1 ASCII Code 8 of 8 Binary Decimal Hexadecimal Octal ASCII Notes 1110 0000 224 E0 340 α 1110 0001 225 E1 341 ß 1110 0010 226 E2 342 Γ 1110 0011 227 E3 343 π 1110 0100 228 E4 344 Σ 1110 0101 229 E5 345 σ 1110 0110 230 E6 346 µ 1110 0111 231 E7 347 τ 1110 1000 232 E8 350 Φ 1110 1001 233 E9 351 Θ 1110 1010 234 EA 352 Ω 1110 1011 235 EB 353 δ 1110 1100 236 EC 354 4 1110 1101 237 ED 355 φ 1110 1110 238 EE 356 ε 1110 1111 239 EF 357 1 1111 0000 240 F0 360 / 1111 0001 241 F1 361 ± 1111 0010 242 F2 362 $ 1111 0011 243 F3 363 # 1111 0100 244 F4 364! 1111 0101 245 F5 365 " 1111 0110 246 F6 366 1111 0111 247 F7 367. 1111 1000 248 F8 370 E 1111 1001 249 F9 371 @ 1111 1010 250 FA 372 A 1111 1011 251 FB 373 % 1111 1100 252 FC 374 6 1111 1101 253 FD 375 ² 1111 1110 254 FE 376 # 1111 1111 255 FF 377

12-10 AutoCAD Self-paced ecourse - AutoLISP - Revised 2013-04-10 AutoLISP Function: = The ' = ' {equals} function is used to compare two or more numbers or strings testing to find if they are numerically equal to one another. When testing numbers, this function does not check for the same data type. It simply checks the numerical value of the numbers. When testing strings, this function compares the numerical ASCII code value of the strings. For example, an upper-case A and a lowercase a are not equal. Returns: T if the atoms are numerically equal, nil if they are not. Format: (= atom atom... ) Examples: 1 (= 12 12.0) T Author's Comments: The atoms 12 and 12.0 are numerically equal, even though they are not the same data type, therefore it returns T. 2 (= 55 75) nil Author's Comments: The two integers are not equal, therefore it returns nil. 3 (= 7.5 7.5 7.5) T Author's Comments: This example show more than two numbers being entered. Since all the numbers are equal, it returns T. 4 (= "PIPE" "PIPE") T Author's Comments: If two strings are being compared, both strings must be identical for it to return T. 5 (= "Pipe" "PIPE") nil Author's Comments: If the ASCII code of the two strings being compared are not numerically equal, it returns nil. 6 (setq num1 5.0 num2 5) 5 (= num1 num2) T Author's Comments: The variables num1 and num2 are both set to the numerical value 5.

AutoCAD Self-paced ecourse - AutoLISP - Revised 2013-04-10 12-11 AutoLISP Function: /= The ' /= ' {not equal} function is used to compare two numbers or strings testing to find if they are numerically not equal to one another. When testing numbers, this function does not check for the same data type. It simply checks the numerical value of the numbers. When testing strings, this function checks the numerical ASCII code value of the strings. An upper-case A and a lowercase a are not equal. Returns: T if the atoms are numerically not equal, nil if they are. Format: (/= atom atom ) Examples: 1 (/= 12 12.0) nil Author's Comments: The atoms 12 and 12.0 are numerically equal even though they are not the same data type, therefore it returns nil. 2 (/= 55 75) T Author's Comments: The two integers are not equal, therefore, it returns T. 3 (/= "Pipe" "PIPE") T Author's Comments: The two strings do not have the same numerically ASCII code value, therefore, it returns T. 4 (setq num1 5.0 num2 5) 5 (/= num1 num2) nil Author's Comments: The variables num1 and num2 are both set to the numerical value of 5, therefore, it returns nil. When testing numbers, testing functions do not check for the same data type. They simply check the numerical value of the numbers. When testing strings, testing functions check the numerical ASCII code value of the strings. An upper-case A and a lowercase a are not equal.

12-12 AutoCAD Self-paced ecourse - AutoLISP - Revised 2013-04-10 AutoLISP Function: > The ' > ' {greater than} function is used to compare two or more numbers or strings, testing to find if the atom on the left is numerically greater than the atom to its right. If two atoms are given, this function tests to see if the first atom is greater than the second atom. If more than two atoms are given, it tests to see if each atom is greater than the atom to its right. When testing numbers, this function does not check for the same data type. It simply checks the numerical value of the numbers. When testing strings, this function checks the numerical ASCII code value of the strings. An upper-case A and a lowercase a are not equal. Returns: T if the first atom is numerically greater than the second atom, nil if it is not. If more than two atoms are given, it returns T if each atom is greater than the atom to its right, nil if it is not. Format: (> atom atom... ) Examples: 1 (> 12 12.0) nil Author's Comments: The atoms 12 and 12.0 are numerically equal, even though they are not the same data type. It returns nil since the number on the left is not greater than the number to its right. 2 (> 75 55) T Author's Comments: The first integer 75 is greater than the second integer 55, therefore, it returns T. 3 (> 7.5 7.5 7.5) nil Author's Comments: This example show more than two numbers being entered. Since all the numbers are numerically equal, it returns nil. 4 (> 2000 1000 500) T Author's Comments: This example shows three integers being entered. It returns T since each number is greater then the number to its right. 5 (> "PIPE" "pipe") nil Author's Comments: When comparing two string, the numerical ASCII code value is used.

AutoCAD Self-paced ecourse - AutoLISP - Revised 2013-04-10 12-13 AutoLISP Function: < The ' < ' {less than} function is used to compare numbers or strings, testing to find if the atom on the left is numerically less than the atom to its right. If two atoms are given, this function tests to see if the first atom is less than the second atom. If more than two atoms are given, it tests to see if each atom is less than the atom to its right. When testing numbers, this function does not check for the same data type. It simply checks the numerical value of the numbers. When testing strings, this function checks the numerical ASCII code value of the strings. An upper-case A and a lowercase a are not equal. Returns: T if the first atom is numerically less than the second atom, nil if it is not. If more than two atoms are given, it returns T if each atom is less than the atom to its right, nil if it is not. Format: (< atom atom... ) Examples: 1 (< 12 12.0) nil Author's Comments: The atoms 12 and 12.0 are numerically equal, even though they are not the same data type, therefore it returns nil. 2 (< 75 55) nil Author's Comments: The first integer is greater than the second integer, therefore, it returns nil. 3 (< 3.5 3.7 7.5) T Author's Comments: This example show more than two numbers being entered. Since all the numbers are less than the number to its right, it returns T. 4 (< 500 1000 3000 500) nil Author's Comments: Since each number is not less then number to its right, it returns nil 5 (< "PIPE" "pipe") T Author's Comments: Since the numerical ASCII code value of the upper-case PIPE is less than the numerical ASCII code value for the lowercase pipe, it returns T.

12-14 AutoCAD Self-paced ecourse - AutoLISP - Revised 2013-04-10 AutoLISP Function: >= The ' >= ' {greater than or equal to} function is used to compare two or more numbers or strings, testing to find if the atom on the left is numerically greater than or equal to the atom on the right. If two atoms are given, this function will test to see if the first atom is numerically greater than or equal to the atom to its left. If more than two atoms are given, it tests to see if each atom is greater than or equal to the atom to its right. When testing numbers, this function does not check for the same data type. It simply checks the numerical value of the numbers. When testing strings, this function checks the ASCII code value of the strings. An upper-case A and a lowercase a are not equal. Returns: T if the first atom is numerically greater than or equal to the second atom and nil if it is not. If more than two atoms are given, it returns T if each atom is greater than or equal to the atom to its right and nil if it is not. Format: (>= atom atom... ) Examples: 1 (>= 12 12.0) T Author's Comments: The atoms 12 and 12.0 are numerically equal, even though they are not the same data type, therefore it returns T. 2 (>= 75 55) T Author's Comments: The 75 is greater than 55, therefore, it returns T. 3 (>= 3.5 3.5 7.5) nil Author's Comments: This example has more than two real numbers being entered. Since the second 3.5 number is not equal or greater than the 7.5 number on the left, it returns nil. 4 (>= 2000 1000 3000 500) nil Author's Comments: The expression returns nil since not all of the numbers are greater than or equal to the number to their right. 5 (>= "PIPE" "pipe") T Author's Comments: This example show two strings being compared. Since the ASCII value of the upper-case PIPE is less than the ASCII value for the lowercase pipe,, it returns nil.

AutoCAD Self-paced ecourse - AutoLISP - Revised 2013-04-10 12-15 AutoLISP Function: <= The ' <= ' {less than or equal to} function is used to compare two or more numbers or strings, testing to find if the atom on the left is numerically less than or equal to the atom on the right. If two atoms are given, this function will test to see if the first atom is numerically less than or equal to the atom to its right. If more than two atoms are given, it tests to see if each atom is less than or equal to the atom to its right. When testing numbers, this function does not check for the same data type. It simply checks the numerical value of the numbers. When testing strings, this function checks the numerical ASCII code value of the strings. An upper-case A and a lowercase a are not equal. Returns: T if the first atom is numerically less than or equal to the second atom, nil if it is not. If more than two atoms are given, it returns T if each atom is less than or equal to the atom to its right, nil if it is not. Format: (<= atom atom... ) Examples: 1 (<= 12 12.0) T Author's Comments: The atoms 12 and 12.0 are numerically equal, even though they are not the same data type, therefore it returns T. 2 (<= 75 55) nil Author's Comments: The first integer is greater than the integer on its right, therefore, it returns nil. 3 (<= 3.5 3.5 7.5) T Author's Comments: This example show more than two numbers being entered. Since all the numbers are less than or equal to the number to their right, it returns T. 4 (<= 2000 1000 3000 500) nil Author's Comments: With four integers entered in the expression, it returns nil since not all of the numbers are less than or equal to the number to their right. 5 (<= "PIPE" "pipe") T Author's Comments: Since the numerical ASCII code value of the upper-case PIPE is less than the numerical ASCII code value for the lowercase pipe, it returns T.

12-16 AutoCAD Self-paced ecourse - AutoLISP - Revised 2013-04-10 Author's Comments: All example AutoLISP programs in the AutoLISP ecourse are located in your Examples folder. I suggest that you load and run these programs after you study the code. Ensure that you can read back each line of the code and understand what it means, in plain English. After you do that, load the program and run it, if necessary, to help you understand how the programs works. AutoLISP Function: while The while {as long as} function is used to loop through and evaluate an expression or a series of expressions in a continuous loop until a specified condition is met. Each while function must contain one test-expression, which is evaluated at the start of each loop. If the test-expression evaluates nil, the while loop terminates. If the test-expression evaluates to anything but nil, the while function evaluates the expression(s) it contains. It then evaluates the test-expression again in a continuous loop. The loop is terminated when the testexpression evaluates nil. A method for the while loop to terminate must be written into the code. If there is none, the program will go into a continuous loop and the user would have to stop it by pressing the Esc key. Returns: The value of the last expression evaluated. Format: (while (test-expression) (expression) (...) ) Examples: 1 Figure Example 1A

AutoCAD Self-paced ecourse - AutoLISP - Revised 2013-04-10 12-17 Figure Example 1B Author's Comments: This small program prints the numbers 7 to 16, each on a new line. The while statement says " as long as " num1 is less than or equal to 16, print the number. Take note how the num1 variable increases by one number on each loop of the function. The function terminates when num1 equals 16. 2 Figure Example 2A

12-18 AutoCAD Self-paced ecourse - AutoLISP - Revised 2013-04-10 Figure Example 2B Author's Comments: This program tests the numerically value of the strings entered by the user. In a while loop, it will ask the user to reenter the string until the strings are identical. Using the While Function Purpose: This program works similar to the MEASURE command. It inserts points on a line that is drawn by the user. The distance between the points is specified by the user. A point is inserted on the start coordinate of the line and continues entering points, at the specified distance, until the distance between the last point inserted and the endpoint of the line is less than the distance between points. Step 1 Step 2 Step 3 Step 4 Start a new drawing using the template AutoLISP English. Create a program naming it AutoLISP Work 12-1.lsp Name the function MEASURELINE1. Have it run like an AutoCAD command. Declare all variables as local variables. Step 5 Save the current value of the system variables cmdecho, clayer, osmode and orthomode. Step 6 Set the value of the system variables cmdecho, osmode and orthomode to 0. Set the pdmode to 34. Step 7 Step 8 Step 9 Step 10 Ask the user to enter the layer name and the layer color. Save both values as strings. Using the input from Step 7, create a new layer and set it as the current layer. Ask the user to enter the distance between points. Ask the user to specify the start and end points of the line. Step 11 Draw a line between the start and end points specified in Step 10. Step 12 Insert a point at the start point of the line.

AutoCAD Self-paced ecourse - AutoLISP - Revised 2013-04-10 12-19 Step 13 In a while loop, insert points on the line using the distance between points. Continue to enter points until the distance left to the end point of the line is smaller than the distance between points. Hint: Use polar functions to find the XY location of the points. Step 14 Reset the original value of the system variables cmdecho, clayer, osmode and orthomode. Hint: Do not reset the original pdmode system variable as this will change the point type on the drawing. Step 15 Load and run the program in AutoCAD. (Figure Step 15A and 15B) Figure Step 15A Figure Step 15B Author's Comments: Do your best to complete the AutoLISP program on your own. If you get stuck and cannot complete it on your own, check my answer in page 12-28. If you complete the program on your own and it returns the correct results, it is correct even if it does not match my program exactly. There are many ways to write the same program.

12-20 AutoCAD Self-paced ecourse - AutoLISP - Revised 2013-04-10 AutoLISP Function: cond The cond {if true - do this} function is used to evaluate more than one test-expressions within one expression. The cond function evaluates the first test-expression and if it returns a value other than nil, it evaluates the result-expressions(s) that follows it. If the first test-expression evaluates nil, it then evaluates the next test-expression and continues to do this until it finds one test-expression that evaluates something other than nil. It will only terminate when it finds one test-expression that returns a value other than nil and evaluates the expression(s) contained in that result area. After finding one expression that returns a value, the cond function will terminate. Each cond loop should include a true statement as the last test-expression in the function. See the examples below. Returns: The evaluation of the applicable result-expression. If the test-expression does not have a result, cond returns the value of the test-expression. Format: Examples: 1 (cond ((test-expression1)(result1)(...)) ((...)(...)) ) Figure Example 1A Figure Example 1B

AutoCAD Self-paced ecourse - AutoLISP - Revised 2013-04-10 12-21 Author's Comments: This example could replace the AutoCAD QUIT command. If the user enters a lowercase y or an upper-case Y, the drawing is quit but if any other answer is given, the AutoLISP program terminates and AutoCAD stays active. Notice the last function in the cond function (t nil). This statement always returns a true and allows the cond function to terminate if it cannot find a true test-expression. You should include one true test-expression in every cond expression. It should always be the last test-expression in the cond expression. 2 Figure Example 2A Figure Example 1B Author's Comments: The cond function is used to test 12 different expressions. If the user enters a number higher then 12, it prints an error message and ends. If a while loop was added to the program, it could go into an continuous loop until the user entered a number between 1 and 12.

12-22 AutoCAD Self-paced ecourse - AutoLISP - Revised 2013-04-10 Each cond loop should include a true statement as the last test-expression in the function. Step 1 Step 2 Step 3 Using the Cond Function Purpose: This program edits the code of the AutoLISP Work 12-1.lsp program that you wrote in the first workalong. It adds a method for the user to select the point style to be inserted plus counting and printing the number of points inserted. Open the program AutoLISP Work 12-1.lsp that you wrote in the first workalong. Using SAVEAS, save the program with the name AutoLISP Work 12-2.lsp. Rename the function MEASURELINE2. Step 4 Using the cond function, add the necessary code that allows the user to select the point style for the points that are inserted. Only allow the four point styles; 2, 34, 66 and 98. Step 5 If the user enters a number other then 2, 34, 66 and 98, the program should print the message "The Point Style 3 will be used" and then set the current point style to 3. Step 6 Add the necessary code to count the number of points inserted and print how many points were inserted. Step 7 Load and run the program in AutoCAD. (Figure Step 7A, 7B, 7C, and 7D) Figure Step 7A Figure Step 7B

AutoCAD Self-paced ecourse - AutoLISP - Revised 2013-04-10 12-23 Figure Step 7C Figure Step 7D Author's Comments: Do your best to complete the AutoLISP program on your own. If you get stuck and cannot complete it on your own, check my answer in page 12-29. If you complete the program on your own and it returns the correct results, it is correct even if it does not match my program exactly. There are many ways to write the same program. A method for the while loop to terminate must be written into the code. If there is none, the program will go into a continuous loop and it would have to be stopped by pressing the Esc key. The Key Principles in Module 12 1 The American Standard Code of Information Interchange (ASCII code) was design to standardize characters on the keyboard. 2 Testing functions do not check for the same data type. They simply checks the numerical value of the numbers or the numerical value of the ASCII code if strings are tested. 3 The while function is used to loop through a expression, or a series of expressions, and evaluates those expressions in a continuous loop until a specified condition is met. 4 A method for the while loop to terminate must be written into the while expression. 5 The cond function is used to evaluate several test-expressions within one expression. 6 The cond function should always include a true statement as the last test-expression in the function.

12-24 AutoCAD Self-paced ecourse - AutoLISP - Revised 2013-04-10 Lab Exercise 12-1 Program Name AutoLISP Lab 12-1.lsp Template AutoLISP English Purpose: This program will ask the user for information and draw a primary circle and spacing between circles. Using the spacing between circles, the program loops and draws as many circles, inside the primary circle, as it can until the space between circles is less than the distance remaining to the center of the circle. Step 1 Step 2 Step 3 Step 4 Step 5 Step 6 Write a program naming the function CONCIR. Have it run like an AutoCAD command. Declare all variables as local variables. Save the current value of the required system variables. Set the values of the required system variables. Ask the user to enter the layer name and the layer color. Save both values as strings. Using the input from Step 5, create a new layer and set it as the current layer. Step 7 Ask the user to enter the following: A Specify the location for center of the circle: B Enter diameter of circle: C Enter spacing between circles: (Figure Step 7) Figure Step 7

AutoCAD Self-paced ecourse - AutoLISP - Revised 2013-04-10 12-25 Step 8 Draw a circle using the entered diameter at the location entered in Step 7. This is the primary circle. Step 9 Using a while loop, draw as many circles as possible, inside the primary circle, using the spacing between circles until the space left to the center of the circle is smaller than the space between circles. Step 10 Step 11 Add the code to count the number of circles inserted and print the results. Reset the original system variables values as necessary. Step 12 Load and run the program in AutoCAD. (Figure Step 12A and 12B) Figure Step 12A Figure Step 12B Author's Comments: Do your best to complete the AutoLISP program on your own. If you get stuck and cannot complete it on your own, check my answer in Module 28. If you complete the program on your own and it returns the correct results, it is correct even if it does not match my program exactly. There are many ways to write the same program.

12-26 AutoCAD Self-paced ecourse - AutoLISP - Revised 2013-04-10 Lab Exercise 12-2 Program Name AutoLISP Lab 12-2.lsp Template AutoLISP English Purpose: This program asks the user to select two points, select the block, enter the distance between blocks and the scale of the blocks. It inserts blocks between the two points, including the start point. It inserts blocks until there is no space left between the last block inserted and the end point. Step 1 Step 2 Step 3 Step 4 Step 5 Step 6 Write a program naming the function IBLOCK. Have it run like an AutoCAD command. Declare all variables as local variables. Save the current value of the required system variables. Set the values of the required system variables. Ask the user to enter the layer name and the layer color. Save both values as strings. Using the input from Step 5, create a new layer and set it as the current layer. Step 7 Ask the user to enter the following: A Enter distance between blocks: B Enter the scale of the block: C Specify start point: D Specify end point: Step 8 Display the Text window and display the following menu: Block List 1. Circle - O 2. Letter - X 3. Centerline - CL Enter Block number 1 to 3: Step 9 Using the cond function, insert the block selected by the user on the start point. If the user does not enter a number from 1 to 3, print an error message and do not insert the block. Step 10 Change to the Graphic window. Step 11 Using the while function, insert blocks, until the distance between blocks is smaller than the distance remaining to the end point. Step 12 Step 13 Count the number of blocks inserted and print the number on the screen. Set the necessary system variables back to their original values.

AutoCAD Self-paced ecourse - AutoLISP - Revised 2013-04-10 12-27 Step 14 Load and run the program in AutoCAD. (Figure Step 14A, 14B and 14C) Figure Step 14A Figure Step 14B Author's Comments: Do your best to complete the AutoLISP program on your own. If you get stuck and cannot complete it on your own, check my answer in Module 28. If you complete the program on your own and it returns the correct results, it is correct even if it does not match my program exactly. There are many ways to write the same program. Figure Step 14C

12-28 AutoCAD Self-paced ecourse - AutoLISP - Revised 2013-04-10 Answers to Workalongs AutoLISP Work 12-1.lsp

AutoCAD Self-paced ecourse - AutoLISP - Revised 2013-04-10 12-29 AutoLISP Work 12-2.lsp

AutoCAD Self-paced ecourse AutoLISP Module 20 Lists - Part 2 Learning Outcomes When you have completed this module, you will be able to: 1 Describe and apply the quote, length, last, append and member functions. AutoLISP Function: quote The quote {use - do not evaluate} function is used to obtain the expression unevaluated. This function can also be written as the character ' (single quote). Quote is a very handy function and can save the programmer many keystrokes. Returns: The expression unevaluated. Format: (quote expression) or 'expression Examples: 1 (quote s) S Author's Comments: The character ' s ' is returned unevaluated. Notice how quote returns the upper-case ' S '. 2 (' s) error: bad function ((QUOTE S)) *Cancel* Author's Comments: As you can see the ' (single quote character) cannot be used by itself at the command prompt. It must be used inside an AutoLISP functions as shown in Example No. 3. 3 (setq lst1 (quote (2.5 5.5))) (2.5 5.5) (setq lst2 '(2.5 5.5)) (2.5 5.5) (setq lst3 (list 2.5 5.5)) (2.5 5.5) Author's Comments: Notice that the same list is returned, using either the quote function, the ' (single quote) or the list function. Lists - Part 2 The CAD Guys Ltd. Copyright 1993-2013 Module 20

20-2 AutoCAD Self-paced ecourse - AutoLISP - Revised 2013-04-10 AutoLISP Function: length The length {length of list} function is used to obtain the number of elements in a list. Returns: An integer. Format: (length list) Examples: 1 (length (list 2 6 9 10)) 4 Author's Comments: The length function returns the integer 4 which is the number of elements in the list. 2 (setq num3 (length (list 2.3 5.6 2.1 '(5 9 6 3)))) 4 Command Author's Comments: The length function counts a nested list as only one element. AutoLISP Function: last The last {last element in list} function is used to obtain the last element in a list. The specified list must not be nil. Returns: An element. Format: (last list) Examples: 1 (setq lst1 (list 2 6 9 10)) (2 6 9 10) (setq e1 (last lst1)) 10 Author's Comments: The last function returns the element 10. It is the last element in the list. 2 (setq e2 ( last '("pipe" "motor" "valve"))) "valve" Author's Comments: The last function returns the string "valve" since it is the last element in the list. 3 (setq num3 (last (list 2.3 5.6 2.1 '(5 9 6 3)))) (5 9 6 3) Author's Comments: Since the list is nested, the last function returns the last item, a list. Lists - Part 2 The CAD Guys Ltd. Copyright 1993-2013 Module 20

AutoCAD Self-paced ecourse - AutoLISP - Revised 2013-04-10 20-3 AutoLISP Function: append The append {join lists} function is used to join lists together to form one. All arguments specified in this function must be lists. Returns: A list. Format: (append list...) Examples: 1 (setq lst1 (append '(3 6 9) '(5 2 7))) (3 6 9 5 2 7) Author's Comments: The two lists are joined together to make one. 2 (setq lst2 (append (list "desk" 2 4.5) '("chair" (4.5 6.7) (2.8 5.2)))) ("desk" 2 4.5"chair" (4.5 6.7) (2.8 5.2)) Author's Comments: Different data types can be included in the same list. Note how append will not affect nested lists. AutoLISP Function: member The member {search list} function is used to search a list for an expression. It will search the list for the expression and returns the first occurrence of the expression and the remainder of the list. If it does not find the expression, it will return nil. Returns: A list or nil if expression is not found in the list. Format: (member expression list) Examples: 1 (setq lst1 (member "chair" (list "desk" "table" "chair" "computer" "printer"))) ("chair" "computer" "printer") Author's Comments: Member returns the list starting at the string "chair". 2 (setq lst2 (member 'c '(a b c ))) (C) Author's Comments: Member returns a list with only one element. 3 (setq num1 (car (member '6.5 '(3.2 5.2 6.5 7.8)))) 6.5 Author's Comments: Note how one element is returned from a list. Since the member function always returns a list, the car function returns the first element in the list. Lists - Part 2 The CAD Guys Ltd. Copyright 1993-2013 Module 20

20-4 AutoCAD Self-paced ecourse - AutoLISP - Revised 2013-04-10 Using the length, append and member Functions Purpose: This program demonstrates using the list functions length, last, member and append. Step 1 Start a new drawing using the template AutoLISP English. Create a program and name it AutoLISP Work 20-1.lsp Step 2 Step 3 Step 4 Step 5 Name the function LIST1. Have it run like an AutoCAD command. Declare all variables as local variables. Save the current value of the required system variables. Set the required system variables to the required values. Step 6 Create the following lists: A (setq lst1 (list "desk" "chair" "cabinet")) B (setq lst2 (list "computer" "mouse" "keyboard")) Step 7 Join the two lists to form one list. Step 8 Open the Text window and print the following two statements on the screen. A The last item in the list is: B The number of items in the list is: Step 9 Step 10 In a loop, extract the item from the list and print them on the screen. Ask the user to enter one of the item in the list. Step 11 Search the original list for the item entered by the user in Step 10 and return that item and the remainder of the list, as a list. Print the new list. Step 12 Reset the original system variable's values, as necessary. Step 13 Load and run the program in AutoCAD. (Figure Step 13) Figure Step 13 Lists - Part 2 The CAD Guys Ltd. Copyright 1993-2013 Module 20

AutoCAD Self-paced ecourse - AutoLISP - Revised 2013-04-10 20-5 Notes The Key Principles in Module 20 1 The quote function is used to obtain the expression unevaluated. 2 The length function is used to obtain the number of elements in a list. 3 The last function is used to obtain the last element in a list. 4 The append function is used to join lists together to form one. 5 The member function is used to search a list for an expression. Lists - Part 2 The CAD Guys Ltd. Copyright 1993-2013 Module 20

20-6 AutoCAD Self-paced ecourse - AutoLISP - Revised 2013-04-10 Lab Exercise 20-1 Program Name AutoLISP Lab 20-1.lsp Template AutoLISP English Purpose: This program allows the user to draw a rectangle with a specified number of divisions. In the center of each division it inserts a number that increments by 1. It draws a vertical rectangle box if the Y axis is longer than the X axis and a horizontal rectangle of the X axis is longer than the Y axis. Step 1 Step 2 Step 3 Step 4 Name the function NUMBOX. Have it run like an AutoCAD command. Declare all variables as local variables. Save the current value of the required system variables. Set the required system variables to the required values. Step 5 Ask the user to enter the layer name. Display the current layer name. If the user presses Enter, use the current layer name. Step 6 Ask the user to enter the layer color. Do not allow a null input and display the colors: "RED,R GREEN,G CYAN,C BLUE,B MAGENTA,M") Author's Comments: If the user presses Enter to Step 5, change the color of the current layer in Step 6. Step 7 Ask the user the following and save the coordinates. Rubberband a window and do not accept a null input: A Specify the bottom left corner of rectangle: B Specify the top right corner of rectangle: Step 8 Ask the user to Enter number of divisions: and save the input as an integer. Do not allow a null input, a negative input or a zero input. Step 9 Calculate which axis is longer the X or the Y. Step 10 Calculate the coordinates and draw the either a vertical rectangle or a horizontal rectangle including the lines for the divisions. Step 11 Insert the numbers using the TEXT command. Set the text height to one-half the height of the rectangle and center it in the sector. Step 12 Reset the original system variable's values as necessary. Lists - Part 2 The CAD Guys Ltd. Copyright 1993-2013 Module 20

AutoCAD Self-paced ecourse - AutoLISP - Revised 2013-04-10 20-7 Step 13 Load and run the program in AutoCAD. (Figure Step 13A, 13B, 13C and 13D) Figure Step 13A Figure Step 13B Figure Step 13C Figure Step 13D Author's Comments: Do your best to complete the AutoLISP program on your own. If you get stuck and cannot complete it on your own, check my answer in Module 28. If you complete the program on your own and it returns the correct results, it is correct even if it does not match my program exactly. There are many ways to write the same program. Lists - Part 2 The CAD Guys Ltd. Copyright 1993-2013 Module 20

20-8 AutoCAD Self-paced ecourse - AutoLISP - Revised 2013-04-10 Answers to Workalongs AutoLISP Work 20-1.lsp Lists - Part 2 The CAD Guys Ltd. Copyright 1993-2013 Module 20