Showing posts with label Make AutoCAD Fast. Show all posts
Showing posts with label Make AutoCAD Fast. Show all posts

Friday, September 19, 2014

List Functions


In most programming languages they work with arrays. In AutoLISP there are no arrays. But you have lists in AutoLISP.


In fact. Lists can perform the same function as arrays. To learn more about it, take a look at my blog. I have written about it.


But let's talk about lists. There are lists functions. There are 18 list functions. Here is a list of them.


- List
- Append
- Cons
- Atom
- Listp
- Length
- Car
- Cdr
- Caar, Cadr, Cadar, Etc.
- Last
- Member
- Nth
- Reverse
- Assoc
- Subst
- Foreach
- Apply
- Mapcar


LIST


(list <expression>...)


This function makes a list of a loose element or loose elements.


Examples:


Function
Gives back




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


APPEND


(append <expression>...)


This function creates a new list out of two or more lists.


Function
Gives back




(append '(a b) '(c d))
(A B C D)
(append '((a) (b)) '(c))
((A) (B) C)


CONS


(cons <new> <list>)


A new element is added to the list. The new element can be an atom or a list. It comes at the first place of the list. Examples are:


Function
Gives back




(cons 'a '(b c d))
(A B C D)
(cons '(a) '(b c d))
((A) B C D)


Instead of a new element and a list, this function can also be used with two atoms. Then you will get a dotted pair. Examples:


Function
Gives back




(cons 2 'a)
(2 . A)
(cons 8 “0”)
(8 . “0”)


ATOM


(atom <item>)


This function gives back nil if the item is a list. If not it gives back T or true.


Examples:


(setq a '(x y z))
(setq b 'a)


Function
Give back




(atom 'a)
T
(atom a)
nil
(atom 'b)
T
(atom b)
T
(atom '(a b c))
nil


LISTP


(listp <item>)


This function is the same as the prevision function. Except it gives back T if the item is a list and nil if it is not a list.


Function
Gives back




(listp '(a b c))
T
(listp 'a)
nil
(listp 3.434)
nil


LENGTH


(length <list>)


This function gives the number of element of a list. Or the length of a list.


Function
Gives back




(length '(a b c d))
4
(length '(a b (c d))
3
(length '())
0


CAR


(car <list>)


This function gives back the first element of a list. What is given back can be an atom or a list. If the list is empty, nil is given back.


Examples:


Function
Gives back




(car '(a b c))
3
(car '((a b) c)
2
(car '())
nil


CDR


(cdr <list)


This function gives back the list without the first element. The first element can be an atom or a list.


Examples:


Function
Gives back




(cdr '(a b c))
(B C)
(cdr '((a b) c)
(C)
(cdr '())
nil


CAAR, CADR, CADAR, etc.


These functions are a combination of the previous functions. You can combine the functions until four levels.


LAST


(last <list>)


The function gives back the last element of a list. Examples:


Function
Gives back




(last '(a b c d))
D
(last '(a b (c d))
(C D)


MEMBER


(member <expression> <list>)


This function checks if the expression is in the list. If so the list is given back starting with the expression.


Function
Gives back




(member 'c '(a b c d e))
(C D E)
(member 'z '(a b c d e))
nil


NTH


(nth <list>)


This function gives back the nth number minus 1 of the list. The elements of the list are numbered., The number of the first element is zero.


Function
Gives back




(nth 3 '(a b c d e))
D
(nth 0 '(a b c d e))
A
(nth 9 '(a b c d e))
nil


REVERSE


(reverse <list>)


This function turns the order of a list around. Example:


Function
Give back




(reverse '(a b c))
(C B A)


ASSOC


(assoc <item> <list)


This function gives back a part list of a list depending on whether the item has been found in the list.


Examples:


(setq ls '((name box) (width 100) (height 200))


Function
Gives back




(assoc 'name a)
(NAME BOX)
(assoc 'width a)
(WIDTH 100)
(assoc 'length a)
nil


SUBST


(subst <new item> <old item> <list>)


This function looks in a list for an old item and replaces it with the new item. If the anew item can be found.


If the old item is not found, then the original list is given back.


Examples:


(setq dm '(a b (c d) b))


Function
Gives back




(subst 'qq 'b dm)
(A QQ (C D) QQ)
(subst 'qq 'z dm)
(A B (C D) B)
(subst 'qq (c d) dm)
(A B QQ B)
(subst '(qq rr) 'c d) dm)
(A B (QQ RR) B)


FOREACH


(foreach <name> <list> <expression>)


This function goes through a list. Every item is given a name and the name is evaluated according to the expression.


The result of the last item and expression is what is given back by the fucntion.


Example:


Function
Gives back




(foreach nm '(1 2 3) (* nm 2))
6


In the example the following calculations have been made:


(* 1 2)
(* 2 2)
(* 2 3)


APPLY


(apply <function> <list>)


With this function elements of a list can be evaluated. Examples:


Function
Gives back




(apply '+ '(1 2 3))
6
(apply 'strcat '(“Auto” “LISP”)
AutoLISP


MAPCAR


(mapcar <function> <list1>...<listn>)


This function evaluates the function specified with all the lists as arguments. In the lists must be the number of needed arguments.


Example:


(setq a 10 b 20 c 30)
(mapcar '1+ (list a b c))


gives back:


(11 21 31)


That is:


(1+ a)
(1+ b)
(1+ c)


(mapcar '+ (10 20 30) (4 3 2))


gives back:


(14 23 32)


That is:


(+ 10 4)
(+ 20 3)
(+ 30 2)


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.








Saturday, August 23, 2014

Graphical Screen Functions


These functions can be used to make changes to the graphical screen. The graphical screen is the drawing area of AutoCAD.


(grclear)


This function is used to clean th active view port of the drawing area. The information is not erased, but made invisible.


If the REDRAW command is used, then the information is visible again.


(grdraw <p1> <p2> <color> [<highlight>])


This function is used to draw a line between the points p1 and p2. The points can be 2D points and 3D points.


The color argument sets the color of the line. If the color argument is -1, then the line is drawn in the color in a complimentary color.


If another vector is drawn over the same points with the color, then the complete line is made invisible.


If the highlight argument is present and unequal to zero, then the line is drawn in a highlighted format.


(grtext [<box> <text> [<higlight>])


With this function you can write text to the screen menu of AutoCAD. I'm afraid screen menus are no longer used. So forget it.


(grread [<track>])


With this function you can read input from devices such as keyboard, digitizer, mouse, etc. But most of the time GET functions are used.


If a mouse is used, then this is what could be given back by the GRREAD fucntion:


(3 (-13.9732 13.0249 0.000000))


The first element is the the code of the device. These are the codes that are available:


2 Keyboard and the ASCII code of the character.


3 Mouse. The point is put in a list.


4 Screen menu cell with the number of the cell.


5 A list of the point for the drag mode. Only if the TRACK argument is unequal to nil.


6 Button number of the mouse.


7 Selected item in TABLET 1 menu.


8 Selected item in TABLET 2 menu.


9 Selected item in TABLET 3 menu.


10 Selected item in TABLET 4 menu.


11 Selected item in AUX 1 menu.


12 Point of the mouse.


13 Selected screen menu item.


(menucmd <text>)


This is another function that works with the screen menu. We are not using it. So you can forget about it.


Exercise


Now we are going to create an AutoLISP program, that draws circles and lines. The center points of the circles are picked.


To create the AutoLISP program the WHILE function is used. Here is the drawing that is created. Four circles have been drawn. But more circles could be drawn.




Sunday, August 17, 2014

Graphical Screen Functions




These functions can be used to make changes to the graphical screen. The graphical screen is the drawing area of AutoCAD.


(grclear)


This function is used to clean th active view port of the drawing area. The information is not erased, but made invisible.


If the REDRAW command is used, then the information is visible again.


(grdraw <p1> <p2> <color> [<highlight>])


This function is used to draw a line between the points p1 and p2. The points can be 2D points and 3D points.


The color argument sets the color of the line. If the color argument is -1, then the line is drawn in the color in a complimentary color.


If another vector is drawn over the same points with the color, then the complete line is made invisible.


If the highlight argument is present and unequal to zero, then the line is drawn in a highlighted format.


(grtext [<box> <text> [<higlight>])


With this function you can write text to the screen menu of AutoCAD. I'm afraid screen menus are no longer used. So forget it.


(grread [<track>])


With this function you can read input from devices such as keyboard, digitizer, mouse, etc. But most of the time GET functions are used.


If a mouse is used, then this is what could be given back by the GRREAD fucntion:


(3 (-13.9732 13.0249 0.000000))


The first element is the the code of the device. These are the codes that are available:


2 Keyboard and the ASCII code of the character.


3 Mouse. The point is put in a list.


4 Screen menu cell with the number of the cell.


5 A list of the point for the drag mode. Only if the TRACK argument is unequal to nil.


6 Button number of the mouse.


7 Selected item in TABLET 1 menu.


8 Selected item in TABLET 2 menu.


9 Selected item in TABLET 3 menu.


10 Selected item in TABLET 4 menu.


11 Selected item in AUX 1 menu.


12 Point of the mouse.


13 Selected screen menu item.


(menucmd <text>)


This is another function that works with the screen menu. We are not using it. So you can forget about it.


Exercise


Now we are going to create an AutoLISP program, that draws circles and lines. The center points of the circles are picked.


To create the AutoLISP program the WHILE function is used. Here is the drawing that is created. Four circles have been drawn. But more circles could be drawn.




Friday, August 8, 2014

Text Screen Functions

Text Screen Functions


Hari Raya


Sorry. I could not add a new post to my blog for two weeks. It was not my fault. It has to do
with Hari Raya.


I live in Malaysia. And you find a lot of Muslims here. They celebrate Ramadan every year. Ramadan is a month of fasting.


When Ramadan is over, then we have Hari Raya. It lasts a couple of days, when everybody has a national holiday.


But the majority of the people take a holiday. And if they have a shop, they close it. Even Chinese shops and Indian shops are closed.


I do my Internet in an Internet cafe. And my Internet cafe was closed too. So I could not add a new post to my blog.


Don't worry. I keep on adding new posts to my blog. I didn't give up. I still have a lot that I want to say.


Text Screen Functions


In AutoLISP we have the following functions that can be used for giving an AutoLISP program a presentation. They are:


- Text screen functions
- Graphical screen functions
- Text functions
- Conversion functions


Now we are going to talk about the text screen functions. Later we are going to talk about the other functions.


(graphscr)
(textscr)


You can switch from the text screen to the graphic screen with the (graphscr) functions and go to the text screen with the (textscr) function.


System Variables


AutoCAD works with system variables. You can check the value of a system variable with the following function:


(getvar <variabele name>)


Examples:


(getvar “dwgname”) TEST
(getvar “cmdecho”) 1


Some system variables are read only. You cannot change their value. But if you can, you can change the value with:


(setvar <variable name> <value>)


Examples:


(setvar “filletrad” 200) 200
(setvar “cmdecho” 0) 0


It is advisable to set the system variable to its original value after the value has been changed. This is how it can be done:


(setq ce (getvar “cmdecho”)
(setvar “cmdecho” 0)
(setvar “cmdecho” ce)


Printing Data


(princ <expression> [<file description>])


This function writes the expression to the text screen and gives as a result the expression. The expression can be a text or a number.


The file description argument is optional and is used if the expression is written to an external file. We will talk about it later.


Examples:


(setq a 123)
(setq b '(a))


(princ 'a) A
(princ a) 123
(princ b) (A)
(princ “Hello”) “Hello”


If the expression is a text, then control codes can be added to it. The following control codes are available.


\\ the \ character
\e escape
\n new line
\r return
\t tab
\nnn the character with the octal code nnn


The PRINC function can also be used without an argument. Then an empty string is written to the screen. That is often at the end of a program.


Example:


(defun c:setng ()
(setvar “lunits” 4)
(setvar “blipmode” 0)
(princ)
)


After the AutoLISP program has been loaded into AutoCAD it is started by typing its name at the command prompt.


At the end of the AutoLISP program the command prompt is shown again without any additional information. There is no 0.


(prin1 <expression> [<file description>])


This function is the same as the previous function, but control codes are not evaluated.


Examples:


(setq a 123)
(setq b '(a))


(princ 'a) A
(princ a) 123
(princ b) (A)
(princ “Hello”) “Hello”


(print <expression> <file description>)


This function is the same as the previous function. But the expression is print on a new line and after the expression is a tab.


(prompt <text>)


Now you can only print a text to the text screen. The function prints the text and gives back nil.


Example:


(prompt “New value”) New value


Exercise


For this exercisxe the REPEAT function is used. Write an AutoLISP program, that draws five circles with the number of the circle in it.


This is the drawing that is created by the AutoLISP program.



Saturday, July 12, 2014

Repetition Functions

Repetition Functions


Now we come to the repetition functions. They are very important. Repetition functions are often used in AutoLISP programs.


Here they are:


WHILE Function


(while (<test> <expression> …)


This function performs a test at the beginning. If the test gives nil, then the expressions are evaluated.


Example:


(defun c:numbr (/ nr)
(setq nr 1)
(while (<= nr 5)
(princ "\nNumber: ")
(princ nr)
(setq nr (1+ nr))
)
(princ)
)
(c:numbr)


At the start of the AutoLISP program the variable NR is given the value 1. The value of the variable is tested at the beginning of the WHILE function.


As long as the value is less or equal to five, then the expressions in the WHILE function are evaluated.


This is given back by the AutoLISP program:


Number: 1
Number: 2
Number: 3
Number: 4
Number: 5


Repeat Function


(repeat <number> <expression> …)


Now the number of repetitions can be specified.


Example:


(princ "\n")
(defun c:repfc ()
(repeat 4
(princ "-")
)
(princ)
)
(c:repfc)


This is given back by the AutoLISP program:


----


Foreach Function


(foreach <name> <list> <expression> …)


This function goes through a list and gives every element of the list a name. The expression is performed for every name.


Example:


(foreach n (list 1 2 3) (* n 2))


The AutoLISP line gives back 6. The number 3 is multiplied with 2.


Exercise:


We have been talking about predicates, test functions and repetition functions. Here is an exercise to use what has been taught.


Write the SLINE AutoLISP program. The following prompts will show up:


Command: SLINE
Color/Linetype/<first point>: C
Color: 1
Color/Linetype/<first point>: L
Linetype: Hidden
Color/Linetype/<first point>: 100,100
Close/<next point>: 300,300
Close/<next point>: C
Command:












Saturday, June 14, 2014

Parametric Drawing


We can create AutoCAD drawings using AutoLISP. Here is an AutoLISP program that does the job. The name of the program is NEWDR.LSP.


The AutoLISP Program


(defun c:newdr (/ p1 p2 p3 p4 p5 p6 p7 sd ts ws)
(setvar “cmdecho” 0)
(setq p1 (getpoint “\nPosition door: “)
sd (getdist “\nStructural dimension: “)
ws (getdist “\nWidth style: “)
ts (getdist “\nThickness style: “)
p2 (polar p1 0 ts)
p3 (polar p2 (/ pi 2) ws)
p4 (polar p3 pi ts)
p5 (polar p2 0 sd)
p6 (polar p3 0 sd)
p7 (polar p3 (/ pi 2) sd)
)
(command “pline” p1 “w” 0 0 p2 p3 p4 “c”)
(command “copy” “l” “” p1 p5 “”)
(command “pline” p2 p5 “”)
(command “copy” “l” “” p2 p3 “”)
(command “pline” p3 p7 “”)
(command “arc” p6 “c” p3 p7)
(command “zoom” “a”)
(command “zoom” “0.8x”)
(setvar “cmdecho” 1) (princ)
)
(c:newdr)


Using the program a door will be drawn. See how the door looks. As you can see. The door has different sizes and a position.



Copy The AutoLISP Program


That is so good about the listing of an AutoLISP program. You can save it on your hard disk and use it again. Copy the program to a text file.


That is important. When the listing of an AutoLISP program is saved, it is saved with the extension LSP. It can be loaded into your CAD program.


Loading The AutoLISP Program


Let's talk about how to load an AutoLISP program into the AutoCAD program. That must be done first before you can use the AutoLISP program.


I will talk about loading the AutoLISP program into IntelliCAD. Loading it into AutoCAD is done in the same way. So don't worry.


You are in IntelliCAD. Click on Tools in the menu. In the pop-up menu click on Load Application. The Load Application files dialog box is displayed.


In the dialog box click on the Add File button. You can go to different folders and you can select the AutoLISP file that you want to load.


Click on the file. And click on the Open button. You come back into the Load Application file dialog box. Click in the Load button.


The AutoLISP file is now loaded into IntelliCAD. And you can start it by typing its name at the prompt.


Starting Automatically


Before I talk about the AutoLISP program, I want to say something about what has been added to the program. At the end you see:


(c:newdr)


Through that line the AutoLISP starts as it has been loaded into IntelliCAD. As you can see. The name of the AutoLISP program is in the line.


Functions


In the AutoLISP program we find functions. The first function we find it the DEFUN function. Here is the syntax of the DEFUN function:


(defun <symbol> <argument list> <expression> ...)


This how the DEFUN function is used for defining an AutoLISP function. SYMBOL is the name of the new AutoLISP function.


Arguments


In the argument list you find all the arguments that the new AutoLISP function needs to run properly. If not there, then an error occurs.


Local Variables


In the argument list you can find a slash. After the slash comes a list of variables. Those variables are local variables.


The local variables only have a value in the function. Outside the function they have no value. Or the value of them is nil.


If no argument list is given then the symbol of an empty list must be used. This is how that symbol looks like: ().


Variables that are not defined as local have a value outside the function. They have a value when the function is no longer running.


Here are some examples:


(defun funct (x y) – the function has two arguments


(defun funct (/ a b) – the function has two local variables


(defun funct (z / a) – the function has no argument and one local variable


(defun funct () - the function has no arguments



In the AutoLISP function the GETPOINT and GETDIST functions are used. To get information. In a separate chapter we talk about the functions.


As you can see. AutoCAD commands were used in the AutoLISP program. I will talk about using AutoCAD commands in another report.


Exercise


You now have seen how an AutoLISP program is created. You have seen how distances can be entered and how AutoCAD commands are used.



Go ahead. Write your own program. This time the program is going to draw a house. Enter the sizes of the house.

Friday, April 11, 2014

What Everybody Ought To Know About Arrays And AutoLISP


You know about arrays. You have arrays in Visual Basic, in C++, and many other programming languages. But AutoLISP?


OK. Let me be very clear. There are no arrays in AutoLISP. But. In AutoLISP. Can you store values that are related?


Oh yes. You can. But is is done in a different way. It is not done in an array. It is done in a list. AutoLISP works with lists.


Arrays


Let me be very clear. Let's start with an array. I start with a one dimensional array. Here is the array:


1
2
3
4
10
20
30
40


You find the following values in the array.


10, 20, 30, 40


So in this one dimensional array you find four values.



1
2
3
1
10
11
12
2
20
21
22
3
30
31
32


Above you see a two dimensional array. It consists of three rows and three columns. The rows and the columns have been numbered.


You find the following values in the array.


10, 11, 12, 20, 21, 22, 30, 31, 32


So in this array you find nine values. If you want to specify the first value in the second row, then you take this:


array (2,1)


Lists


In AutoLISP we don't have arrays. In AutoLISP we have lists. And like arrays. You have to store all the values in the list.


Let's take a list with the values from the one dimensional array. This is how the list looks.


(10 20 30 40)


But we need to store all the values in the list. This is how we can do it. The name of the list is LS.


(setq ls (list 10 20 30 40))


The list is stored in the variable LS. And that is done with the SETQ function. The LIST function is used to add all the values.


We want to retrieve the values of the list. Suppose we want to find the first value of the list. This is how it is done.


(setq v1 (nth 0 ls))


The number of the first value is zero. The number of the next value is one. Etc. So the number of the last value is three.


OK. Let's make things a little complicated. You saw a two dimensional array. Can we store it in a list in a two dimensional way?


Yes. You can. Of course. You could all the values of the array in a list. But you can also do it in a two dimensional way.


Take the values of each row of the list in a list. This is how it is done:


(setq l1 (list 10 11 12)
l2 (list 20 21 22)
l3 (list 30 31 32)
)


Now we have created three lists. We have created l1, l2, and l3. We turn them into one list. See how it is done.


(setq ls (list l1 l2 l3))


If you enter !ls in AutoCAD, then this is given back by the program:


((11 12 13) (21 22 23) (31 32 33))


Nice. But how can we retrieve the values in the list? Suppose want to know the first value that is in l2. How do we do that?


This is how it is done. We enter at the command prompt:


(setq vl (nth 0 (nth 1 ls)))


First we find the second list in the ls variable. And then we take the first element of the second list. Do you see?


Three Dimensional Lists


Sure. You want to confuse me. You want to make my life very difficult. Now you want to know about three dimensional arrays.


You want to know how you can specify three dimensional arrays in a list. Sorry. I don't need a psychologist now.


After telling you about two dimensional arrays and how their values can be put in a list. I think a three dimensional array is very clear


Arrays And Lists


There more functions that have to do with lists. But I'm not going to explain them. I just wanted to talk about arrays and lists.


Something Completely Different


Here is something completely different from what you normally read in this blog. It is an imagination.


Imagine this. One day you wake up and you are a millionaire! Look at how different your life will be:


- You no longer have to worry about your debts, bills, and slaving for money.


- You can spend your time doing things you love, spend your time with your beloved family and friends.


- You no longer have to worry about money or have to be poor again. Never again living the life you used to have.


Do you want to be a millionaire? Make your dream lifestyle came true. Here's your chance to be a millionaire. Check this out.


Wake Up Millionaire:
http://l1nk.com/rfbzla



To Your Success


Free AutoLISP Course


Sorry. This offer is only for my readers from Malaysia. I want to give an AutoLISP course to them. Free of charge.


I have more than 900 readers. The majority of them is from the USA. More than 500. But I also have readers from Malaysia. About 120.


I don't know what my readers from Malaysia are doing. Are they with an engineering firm or architecture? Or just interested in AutoLISP?


I offer them a free AutoLISP course. It works like this. You let me know if interested and I'll come to your place.


I will give the AutoLISP course at your office. Your people can attend the AutoLISP course. The course consist of 15 lessons.


The first ten lessons are about AutoLISP. All the functions of AutoLISP are explained and there is talked about the system variables.


During the last five lessons we are going to write an AutoLISP program. The people attending the course come with a wish.


That is why this offer is only for my readers from Malaysia. I live in Malaysia. And I do not see how I could travel abroad.


The AutoLISP course is completely free. I will not charge you for the course. But I will ask you to refund my travel expenses.


The people attending the course will get an e-book about AutoLISP. The e-book is a PDF file. What is said in the course, can be found in the book.








Friday, March 28, 2014

Drawing A Polyline with AutoLISP 7


The Main Part Of The AutoLISP Program


Every AutoLISP program has got a main part. You can recognize that part. It has C: in the function name.


Here is the main part:


(defun-c:drwpl-(/-ct-ls-et-sp)
---(start)
---(drlns)
---(setq-ct-T)
---(while-ct
------(setq-ls-(fndet)
------------et-(nth-0-ls)
------------sp-(nth-1-ls)
------)
------(if-(null-et)
---------(setq-ct-nil)
---------(progn
------------(delpl)
------------(drwpl-et-sp)
---------)
------)
---)
---(endpr)
)


In the second post of this AutoLISP program I was talking about the functions of the program. This is what I wrote:


Function Action


START Setting the limits, erasing everything in the screen, setting the snap and grid, zooming out of the screen


DRLNS Drawing four lines


FNDET Finding line or polyline entity


DELPL Delete polyline


DRWPL Draw polyline, no intersection with other line


DPLIP Draw polyline, intersection with other line


ENDPR Ending of the program


You will find all functions mentioned in the main part of the AutoLISP program. A call is made to these functions.


Something else. In the main part of the AutoLISP program is a WHILE loop. There is a repetition in the AutoLISP program.


When the program is running there is asked to select a line. That question is repeated all the time. Until no line is selected.


This is how it is done:


(setq ct T)
(while ct
(setq ls (fndet)
et (nth 0 ls)
sp (nth 1 ls)
)
(if (null et)
(setq ct nil)
; The AutoLISP program draws a polyline
)
)


The CT variable is introduced. The variable gets the value true. As long as the value is true, the loop continues.


A call is made to the FNDET function. In that function there is asked to select a line. But no selection can be made.


The user clicks the right mouse button if he no longer wants to select a line in the screen. Then the values of ET and SP are nil.


The value of the ET variable is checked. If it is nil, then the CT variable gets the value nil too. And the WHILE loop terminates.


OK. Now I have told you everything about the AutoLISP program for drawing a polyline. I trust I have been clear enough.


Something Completely Different


Here is something completely different from what you normally read in this blog. It is an imagination.


Imagine this. One day you wake up and you are a millionaire! Look at how different your life will be:


- You no longer have to worry about your debts, bills, and slaving for money.


- You can spend your time doing things you love, spend your time with your beloved family and friends.


- You no longer have to worry about money or have to be poor again. Never again living the life you used to have.


Do you want to be a millionaire? Make your dream lifestyle came true. Here's your chance to be a millionaire. Check this out.


Wake Up Millionaire:
http://l1nk.com/rfbzla



To Your Success


Free AutoLISP Course


Sorry. This offer is only for my readers from Malaysia. I want to give an AutoLISP course to them. Free of charge.


I have more than 900 readers. The majority of them is from the USA. More than 500. But I also have readers from Malaysia. About 120.


I don't know what my readers from Malaysia are doing. Are they with an engineering firm or architecture? Or just interested in AutoLISP?


I offer them a free AutoLISP course. It works like this. You let me know if interested and I'll come to your place.


I will give the AutoLISP course at your office. Your people can attend the AutoLISP course. The course consist of 15 lessons.


The first ten lessons are about AutoLISP. All the functions of AutoLISP are explained and there is talked about the system variables.


During the last five lessons we are going to write an AutoLISP program. The people attending the course come with a wish.


That is why this offer is only for my readers from Malaysia. I live in Malaysia. And I do not see how I could travel abroad.


The AutoLISP course is completely free. I will not charge you for the course. But I will ask you to refund my travel expenses.



The people attending the course will get an e-book about AutoLISP. The e-book is a PDF file. What is said in the course, can be found in the book.