Showing posts with label CAD. Show all posts
Showing posts with label CAD. Show all posts

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, May 23, 2014

Basic Concepts




Let's start with AutoLISP. It is used for writing programs for AutoCAD and CAD programs similar to AutoCAD. IntelliCAD is such a program.


With AutoLISP you can write programs that perform tasks and calculations automatically.


AutoLISP is a dialect of the programming language LISP. LISP has been developed by John McCarthy in the nineteen fifties.


LISP is the second higher programming language after FORTRAN. In the nineteen eighties LISP became really popular.


LISP was used for developing scientific systems, the so called Expert Systems, and systems for artificial intelligence.


Now we not only have LISP. There are also many dialects of LISP. Some dialects are InterLISP, MacLISP, ZetaLISP, CommonLISP, and SCHEME.


AutoLISP is also a dialect of LISP and it is based XLISP ODF David Bentz. AutoLISP looks very much like CommonLISP.


The name LISP comes from “LISt Programming” or LISt Processing”. It is also called “Lots of Insane Stupid Parenthesis”.


The Introduction Of AutoLISP



In AutoLISP you can write programs and functions that can be used in the AutoCAD program and CAD programs that are alternatives of AutoCAD.



Similar Programs


Autodesk started with the introduction of AutoLISP. They praised the:


- Flexibility
- Simplicity
- Interpretation


AutoLISP is flexible, because you define functions and programs in many ways. And variables can have many values.


AutoLISP is simple, because it is easy to learn. Of the higher programming languages AutoLISP is the easiest one to learn.


You can type an expression on the command prompt and right away you get to see the result. That is not complicated.


AutoLISP is being interpreted instead of being compiled. The advantage is that errors in the program can be found right away.


AutoLISP As A Tool


AutoLISP can be used as you are drawing in AutoCAD or an alternative CAD program. It can be used for making calculations. Or store data in memory.


Here is an example. Suppose you want to insert a block. And you want to insert it with a scale factor of three divided by seven.


The INSERT command is used. These are the prompts that show up at the command prompt:


- Command:
- Blockname:
- Insertion point:
- X scale factor:
- Y scale factor:
- Rotation angle:


We fill in the name of the block and we pick a point. That point is the insertion point. Now we must enter the scale factor.


We know the scale factor is three divided by seven. We could calculate what the value is and use the number.


The exact value is 0.4285714285714286. Maybe you round the value up to 0.43. But if you round it up, you do not get an exact value.


There is another way. It is the AutoLISP way. If you follow that way, you will use the exact value of the calculation.


At the prompt, where is asked for the X value, enter (/ 3.0 7.0). AutoLISP calculates the value and gives it back to the command.


Concepts


In AutoLISP there are the following concepts:


- Atoms
- Symbols
- Strings
- Real numbers
- Integers
- Subrs (built in functions)
- File descriptors
- AutoCAD entity names
- AutoCAD selection sets
- Lists


A symbol is a variable in which data is stored. Use a name that says something about the data that is stored in the symbol.


Example:


p1 - point
e1 - entity


A string is a text. In AutoLISP a string has got quotes. Here is an example of a string as is used in AutoLISP.


This is a string”


Real numbers have a value behind the point. Here are some real numbers:


- 3.24
- 14.9
- 15.0



An integer is a number without a part behind the point. Here are integers:


- 23
- 10


Subrs or built in functions are used by AutoLISP. They perform an action. Here are two examples:


+ - count
/ - divide


If you work with external files in AutoLISP, then
file descriptors are used. With the file descriptor the external file is specified.



Here is how a file descriptor may look:



<file #E814>



In an AutoCAD drawing you can find a lot of entities. Every line, circle, block, etc. is an entity.



These entities have a name. This is how the name of an entity may look:


<Entity name: 60000014>



In AutoCAD you may find selection sets. Selection sets are created by AutoLISP. They are named like this:
<Selection set:5>



These are the atoms of AutoLISP. But AutoLISP is also having lists. A list is a group of elements between brackets.


This is how a list may look:



- (A B C)
- (1 2 (3 4) 5)


A point is a list too. You can have 2D points and you can have 3D points. This is how they may look:



- 2D point: (10 20)
- 3D point: (10 20 30)


The numbers in the list for the point stand for the X value, the Y value, and the Z value. Only 3D points also have a Z value.


Functions


In AutoLISP there are a lot of functions. We have used a function as we were calculating a value for the INSERT command.


The function was (/ 3.0 7.0). Let's be more specific:


(/ 3.0 7.0) - list
/ - built in function
3.0, 7.0 - real numbers
/, 3.0, 7.0 - atoms


A call to a function is done with a list. You have seen what list has been used here. The first element is the symbol of the function.


The symbol of the function is the built in function. It is a dash. We have got a prefix notation. The symbol comes first.


You will find more functions in this book. They are all explained. I will not give you any more examples of functions.


Storing Data


We have used a function with the INSERT command. But the result of the function was not stored in the CAD program.


We can store data in the CAD program. The data is stored in a symbol. That is done with the SETQ function. Here is how it is done:


(setq vl 5)


The symbol VL gets the value five.


But if we use a function for a calculation, then the function gives back a value too. And we store that value in a symbol.


Here is what we can do with the function that we used with the INSERT command:


(setq dv (/ 3.0 7.0))


Now the value of three divided by seven is stored in the symbol DV.


Getting A Value


You have stored value in symbols. And now you want to know the values of the symbols. That is easy. Put an exclamation mark in front of the symbol.


We have used the SETQ function like this:



(setq vl 5)



To find the value that is stored in the symbol VL we enter “!vl” at the command prompt. And five is given back.



You could also enter at the command prompt:



(eval vl)


That function also gives back five.


Lexical Appointments


We were talking about AutoLISP. You saw the start of programming in AutoLISP. But there are some appointments to follow.


- For programing in AutoLISP lowercase characters and uppercase characters can be used. The use of lowercase characters is preferred.



- Symbol names can contain all characters except:


(
)
.
'

;


- The following characters end a symbol name:


(
)
'

;
(space)
(end of line)


- Symbol names and function names cannot start with a number.


- Texts are enclosed in quotes


- AutoLISP works with control codes. The following control codes are available:


\\ \ character
\e escape
\n new line
\r return
\t tab
\nnn character nnn


- You can place comments in an AutoLISP program by placing a semi colon in front of the colon. The AutoLISP program will ignore the comment.


- For symbols use a name of two characters. For functions use a name of five characters. To save computer memory.


Exercises


1. Is (1 4 “hallo”) a list?
2. Is '(1 2 3)' a list?
3. Is 21 a symbol?
4. How many elements has the list (1 45 (“this” “is”) “a text”)?
5. What is the integer of 3.1536?
6. What is the integer of 3.0?
7. Is point.1 a symbol?
8. Is point_1 as symbol?
9. What is the result of (setq ct 56 pt 23)
10. What character is placed in front of a symbol to get the value of the symbol?


Saturday, May 17, 2014

Introduction


Programming in AutoLISP is very easy. You may disagree. You may find it very complicated. Most people find it very complicated.


Are you working with the full version of AutoCAD? Or are you working with an alternative CAD program such as IntelliCAD or ZWCAD?


Use the 3P method for programming in AutoLISP. If you do, then you'll find programming in AutoLISP very easy.


Remember. Anything that is done by hand with an CAD program, can also be done by an AutoLISP program. Except AutoLISP is much faster.


The 3P method stands for:


- Planning
- Proces
- Programming


Here is a table in which an explanation is given:


Action
Description




Planning
What do you want the AutoLISP program to do?
Proces
What steps are to be undertaken by the AutoLISP program?
Programming
Write the AutoLISP program a function for each step.


Did you already figure out? If you follow the 3P method, then programming in AutoLISP becomes very easy. It isn't complicated at all.


In fact. Everything that is done in AutoCAD. Cvamn also be done with an AutoLISP program. Except AutoLISP is much quicker.


In this e-book there is talked about the basic concepts, the functions, the database, and the system variables.


At the end of the course an AutoLISP program is written. You figure out what AutoLISP program is to be written.


When the course has been completed you are ready to start programming in AutoLISP. Of course. If you need help. You can always contact me.


This is my e-mail address:


makeautocadfast@ymail.com




Friday, April 18, 2014

How To Get Your AutoCAD Drawings Right Away

You are working with AutoCAD. Or any CAD program. You know how it is. It takes a lot of time before your drawing has been created.

And then. After your drawing has been created. You cannot use it right away. The drawing must be checked. And that takes time too.

Big Disadvantage

Waiting for your CAD drawing before it is finished. And then the time that checking takes. That is a big disadvantage.

Is that how it always is? Is there no way that the waiting can be avoided? Is there a quicker way of getting your CAD drawing?

A Quicker Way 

There is a quicker way. There is no need for waiting for hours before your CAD drawing is finished and checked.

Get an AutoLISP program. An AutoLISP program can create parts of your CAD drawing. It can even create complete CAD drawings.

If the AutoLISP program is creating parts of your CAD drawing, you are saving a lot of time. The CAD operator is quicker.

The AutoLISP program creating a complete CAD drawing. That is even better. You get your CAD drawing in less than five seconds.

And working with the CAD program is very easy. Anybody can work with the CAD program. Even non CAD operators.

CAD Operators

I'm not saying that you must do that. I'm not saying to get rid of all your CAD operators. But maybe you can do with less of them.

I think. Even if you are working with a lot of CAD programs. You still need CAD operators. Not everything is done automatically.

The Point

That is the point of this post. There is no need for waiting for hours before your CAD drawing is finished. You can save a lot of time.
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, 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.

Friday, March 21, 2014

Drawing A Polyline with AutoLISP 6

The DPLIP Function


This function is long. And it is also a little bit complicated. But you will understand the function. I hope.


Here is the function:


(defun-dplip-(et-sp-ss-/-e1-el-ip-p1-p2-p3-p4)
---(setq-el-(entget-et)
---------p1-(cdr-(assoc-10-el))
---------p2-(cdr-(assoc-11-el))
---)
---(setq-e1-(ssname-ss-0))
---(if-(equal-et-e1)
------(setq-e1-(ssname-ss-1))
---)
---(setq-el-(entget-e1)
---------p3-(cdr-(assoc-10-el))
---------p4-(cdr-(assoc-11-el))
---)
---(if-(or-(=-(angle-p1-p2)(angle-p1-p3))
-----------(=-(angle-p1-p2)-(angle-p2-p3))
-------)
------(setq-ip-p3)
------(setq-ip-p4)
---)
---(if-(=-(+-(distance-p1-sp)
-------------(distance-sp-ip)
----------)
----------(distance-p1-ip)
-------)
------(command-"pline"-p1
-----------------------"w"
-----------------------2.5
-----------------------2.5
-----------------------ip
-----------------------""
------)
------(command-"pline"-p2
-----------------------"w"
-----------------------2.5
-----------------------2.5
-----------------------ip
-----------------------""
------)
---)---
)


We give an entity to the function together with the selection point and the selection set that was found in the previous function.


Finding Two Points Of The Line


We want to find the two points of the entity. The entity is a line. This is how we find the two points of trhe line.


(setq-el-(entget-et)
p1-(cdr-(assoc-10-el))
p2-(cdr-(assoc-11-el))
)


Finding The Other Line


Another line is coming to the line that we have selected. We want to know what that line is. It is in the selection set.


There are two entities or two lines in the selection set. We take the first entity of the selection set.


We see if it is the same as the entity that was given to the function. If it is, then we take the second entity of the selection set.


Here are the programming lines:


(setq-e1-(ssname-ss-0))
(if-(equal-et-e1)
(setq-e1-(ssname-ss-1))
)


Now we have the line that is drawn against the line that has been selected. We find the points of that line. Here is how.


(setq-el-(entget-e1)
p3-(cdr-(assoc-10-el))
p4-(cdr-(assoc-11-el))
)


The Point On The Selected Line


Now we need to find what point is on the line that has been selected. We check the angles. Here is how it is done.


(if (or (= (angle p1 p2)(angle p1 p3))
(= (angle p1 p2)(angle p2 p3))
)
(setq ip p3)
(setq ip p4)
)


Now we know the two points of the line that has been selected. And we know the point of the other line that is on the line.


How The Polyline Is To Be Drawn


Now we must figure out how a polyline is to be drawn. We must figure out between what points the polyline must be drawn.


We know. The polyline is drawn to the point of the other line that is on the selected line. But from where is it drawn?


Is it drawn from point P1 or is it drawn from point P2. The points P1 and P2 are from the selected line.


It is quite simple to find out between what points the polyline must be drawn. We look at the distances.


There is the distance between P1 and the selection point and the distance between the selection point and the point of the other line.


If the total of those distances are the same as the distance between P1 and the point of the other line, then we know.


Then the polyline is drawn from point P1 to the point of the other line. Otehrwise it comes from point P2.


Here are the lines of the AutoLISP program.


(if (= (+ (distance p1 sp)
(distance sp ip)
)
(distance p1 ip)
)
(command "pline" p1
"w"
2.5
2.5
ip
""
)
(command "pline" p2
"w"
2.5
2.5
ip
""
)
)


Next Post


In the next post I'm going to talk about the main part of the AutoLISP program. And then I'm done talking about this AutoLISP program.


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.

Monday, March 17, 2014

Drawing A Polyline with AutoLISP 5

The DELPL Function


Now I'm going to talk about the next function of the AutoLISP program. I'm going to talk about the DELPL function. Here it is:


(defun-delpl-(/-et-el-tp)
---(setq-et-(entlast)
---------el-(entget-et)
---------tp-(cdr-(assoc-0-el))
---)
---(if-(=-tp-"LWPOLYLINE")
------(command-"erase"-(entlast)-"")
---)
)


The function is used as the AutoLISP program starts. It deletes a polyline. A call to it is in the main AutoLISP program.


Working Of The Function


The function works like this. The last entity in the drawing is found. The ENTLAST function is used.


The type of the last entity is found. If the type is a polyline, the name is LWPOLYLINE, then it is deleted.


The polyline is deleted with this programming line:


(command-"erase"-(entlast)-"")


Important


I told you. As the AutoLISP program works, then the polyline that has been drawn by the program, is deleted.


Next Post


I keep this post short. In my next post I'm going to talk about the next function. I'm going to talk about the DRWPL function.


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.

Sunday, March 16, 2014

Drawing A Polyline with AutoLISP 4

Now I'm going to talk about all the functions of the AutoLISP program. I already gave you a list of all the functions. Here it is again:


The Functions


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


The START And The END Function


Earlier I talked about those two functions. You know how they work. I don't have to tell you once more.


The DRLNS Function


This function is used to draw the lines in the screen. It is a very simple function. The LINE command is used twice.


Here is the function.


(defun-drlns-()
---(command-"line"-(list-120-0)
-------------------(list-10-0)
-------------------(list-10-120)
-------------------(list-120-120)
-------------------""
---)
---(command-"line"-(list-10-60)
-------------------(list-120-60)
-------------------""
---)
)


The FNDET Function


Let's first talk about this function. Let me tell you what it does. Let me tell you what is happening through the function.


There is asked to make a selection. A selection could have bene made or there is no selection made. The right mouse button is clicked.


What ever is done. A selection has been made or no selection has been made. An entity and the selection point is given back.


If a selection has been made, then a polyline has been selected or a line. If a polyline has been selected, then the points of it are found.


After the points have been found, the polyline is deleted and the line under the polyline is found. The points are needed for doing that.


If a line has been selected, then the entity of the line can easily be found. And the selection point is known too.


If no selection has been made, then the entity and the selection point, that are given back to the main program, get the value of nil.


Here is the FNDET function.


(defun-fndet-(/-an-el-et-ls-p1-p2-pt-sl-sp-ss-tp)
---(setq-sl-(entsel-"\nSelect-line: "))
---(if-sl
------(progn
---------(setq-et-(car-sl)
---------------el-(entget-et)
---------------sp-(cadr-sl)
---------------sp-(osnap-sp-"nea")
---------------tp-(cdr-(assoc-0-el))
---------)
---------(setq-ls-nil)
---------(if-(=-tp-"LWPOLYLINE")
------------(progn
---------------(while-(setq-nr-(caar-el))
------------------(if-(=-nr-10)
---------------------(progn
------------------------(setq-pt-(cdar-el))
------------------------(if-ls
---------------------------(setq-ls-(append-
-------------------------------------(list-pt)
-------------------------------------ls
------------------------------------)
---------------------------)
---------------------------(setq-ls-(list-pt))
------------------------)
---------------------)
------------------)
------------------(setq-el-(cddr-el))
---------------)
---------------(setq-p1-(nth-1-ls)
---------------------p2-(nth-0-ls)
---------------------an-(angle-p1-p2)
---------------)
---------------(command-"erase"-et-"")
---------------(setq-ss-(ssget-"c"-(polar-p1-
------------------------------------------an-
------------------------------------------1
-----------------------------------)
-----------------------------------(polar-p2-
------------------------------------------(+-an
---------------------------------------------pi
------------------------------------------)
------------------------------------------1
-----------------------------------)
------------------------)
---------------)
---------------(setq-et-(ssname-ss-0))
------------)
---------)
------)
------(setq-et-nil
------------sp-nil
------)
---)
---(list-et-sp)
)


I have told you what the function does. And I have told you what is happening through the function. Lets now see how it done.


Asking to make a selection. It is done with this line. The ENTSEL function is used. That function gives back a list.


(setq sl (entsel "\nSelect-line: "))


This is an example of the list that is given back by the ENTSEL function.


(<Entity name: 37d85a0> (61.8922 59.7297 0.000000))


If a selection has been made, then we want to know the name of the entity and the selection popint. We use these lines.


(setq-et-(car-sl)
el-(entget-et)
sp-(cadr-sl)
sp-(osnap-sp-"nea")
tp-(cdr-(assoc-0-el))
)


First we find the name of the entity. It is the first element in the list from the ENTSEL function. We use the CAR function.


The second element of the list is the selection point. To find it we use the CADR function. And we use the OSNAP function.


The OSNAP function is used to have the point laying on the polyline or the line that has been selected.


We also want to know the type of the entity. The type can be LINE or LWPOLYLINE. A polyline has been selected if it is LWPOLYLINE.


We find the type of the entity with this line.


(setq-tp-(cdr-(assoc-0-el))


If a line has been selected, then we have the name of the entity and the selection point. But a polyline could have been selected.


If a polyline has been selected, we need to find the points of the polyline. This is how it is done:


(while (setq nr (caar el))
(if (= nr 10)
(progn
(setq pt (cdar el))
(if ls
(setq ls (append (list pt) ls))
(setq ls (list pt))
)
)
)
(setq el (cddr el))
)


I start with a WHILE loop. The WHILE loop continues as long as a number has been found. The number is in the sub list of the entity list.


The CAAR function is used. With that function the first sub list of the entity list is taken and the first element in it.


There is checked if that number is ten. If so, the point is found in the sub list with the CDAR function.


Next the first sub list of the entity list is removed from the entity list with the CDDR function. And we continue with the WHILE loop.


The points of the polyline are found in the sub lists that have the number ten. We create a list. The kist has two points.


After the points have been found, the polyline is deleted and the line under the polyline is found. The points are needed for doing that.


The polyline is deleted with this line:


(command-"erase"-et-"")


These are the lines that are used to find the line under the polyline. We use the points of the polkyline for doing that.


Here are the programming lines:


(setq-ss-(ssget-"c"-(polar-p1-an-1)
(polar-p2-(+-an-pi)-1)
)
)
(setq-et-(ssname-ss-0))


The angle between the point P1 and P2 is measured. And the points of the SSGET function are one from the points.


We do not want to find the lines that cross the line at the points P1 and P2. That is why we go to points 1 from the original points.


We find a selection set. I call it SS. The first entity in the selection set is the line that we are looking for. Here is the programming line.


(setq-et-(ssname-ss-0))


If a line has been selected, then the entity of the line can easily be found. And the selection point is known too.


If no selection has been made, then the entity and the selection point, that are given back to the main program, get the value of nil.


Very good. We have found the line and we have found the selection point. Those two are put in a list and given back to the main program.


We put these two in a list. This is how it is done:


(list-et-sp)


Next Post


I have talked about the FNDET function. You have got a lot of information. I hope I was clear enough. If not, let me know.


In my next post I'm going to talk about the DELPL function. That function is used to delete the polyline that has been drawn.


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.