Friday, September 5, 2014

Conversion Functions


For instance. We are working with an integer. And now we want to convert that integer into a string. We need a conversion function.


AutoLISP has got eleven conversion functions. Here they are:


(angtos <angle> [<mode> [<precision>]])


This function converts an angle into a string. The angle is a real number in radians. The result depends on the mode and the precision.


Mode Description


0 Degrees
1 Degrees/minutes/seconds
2 Degrees (400)
3 Radians
4 Land units


The precision argument give the number of decimals. The mode and precision argument are in the system variables AUUNITS and AUPREC.


Examples:


(setq p1 (list 500 133))
(setq p2 (list 240 133))
(setq an (angle p1 p2))


(angtos an 0 0) "180"
(angtos an 0 4) "180.0000"
(angtos an 1 4) "180d0'0"
(angtos an 3 4) "3.1416r"
(angtos an 4 2) "W"


(rtos <number> [<mode> [<precision>]])


Now a real number is converted into a text. The units and precision depend on the arguments for mode and precision.


Mode Description


1 Mathematical
2 Decimal
3 Feet and decimal inches
4 Feet and fractional inches
5 Divisions


The mode and the precision arguments can be found in the system variables LUNITS and LUPREC.


Examples:


(rtos 17.5 1 4) "1.7500E+01"
(rtos 17.5 2 2) "17.50"
(rtos 17.5 3 2) "1'-5.50"
(rtos 17.5 4 2) "1'-5 1/2"
(rtos 17.5 5 2) "17 1/2"


(itoa <integer>)


Now an integer is converted into a text.


Examples:


(itoa 33) "33"
(itoa -17) "-17"


(atoi <text>)


A text is converted into an integer.


Examples:


(atoi "97") 97
(atoi "-3") -3
(atoi "3.9") 3


(atof <text>)


A text is converted into a real number.


Examples:


(atof "97.1") 97.1
(atof "-3") -3.0


(fix <number>)


This function translates a number into an integer.


Examples:


(fix 3) 3
(fix 3.7) 3


(float <number>)


Here a number is translated into a real number.


Examples:


(float 3) 3.0
(float 3.75) 3.75


(list <expression>)


A list is created with a number of loose expressions. It is often used to create a 2D point or 3D point.


(list 'a 'b 'c) (A B C)
(list 'a '(b c) "text") (A (B C) "text")
(list 3.9 6.7) (3.9 6.7)


(ascii "text")


The ASCII value of the first character of the text is given.


(ascii "a") 97
(ascii "A") 66
(ascii "all") 97


(chr <number>)


The number is an ASCII value. The corresponding character is givne back.


Examples:


(chr 65) "A"
(chr 66) "B"
(chr 97) "a"


(read <text>)


This function gives back what has been read. The text cannot contain spaces. What is after the space is ignored.


(read "LISP") LISP
(read "A") A


Exercise:


Create an AutoLISP program, that creates the following parking spot. Do you see? The sizes for the length, width, and angle are given.








This is how the AutoLISP program works:


Command: PRKSP
Width/Length/Angle/<starting point>:W
Width <default>: width is entered
Width/Length/Angle/<starting point>:L
Length <default>: length is entered
Width/Length/Angle/<starting point>:A
Angle <default>: angle is entered
Number of parking spots <default>: number is entered


Take care. The AutoLISP program is going to be very big. So make separate functions for entering the width, length, and angle.


Exercise


Let's write an AutoLISP program. This is the drawing that is created by the AutoLISP program.




Two points are picked. The circle is drawn in one point. And as line goes to the other point, starting in the first point.


The user enters what text is to be drawn in the circle. And a box is drawn around the text. The TEXTBOX function is used.