Showing posts with label hatch. Show all posts
Showing posts with label hatch. Show all posts

Tuesday, January 21, 2014

AutoLISP Program Drawing Donuts And A Hatch 2

AutoLISP Program Drawing Donuts And A Hatch 2


Before talking about all the functions of the AutoLISP program, I want to say something about the working of the AutoLISP program.


Several tasks are performed with the AutoLISP program. For every task there is a function. Here is a list of the task and functions.


Starting and ending the
AutoLISP program START, ENDPR
Drawign lines DRLNS
Finding a line FNDET
Finding a list of points FNDLS
Drawign donuts DRWDN


The Main Function


There is also a hatch drawn between the line sof the AutoLISP prgoram. That is done in the main fucntion of the AutpoLIUSP prgoram.


Here it is:


(defun c:dnsrm (/ pt et ls)
(start)
(drlns)
(setq pt (getpoint "\nPoint in room: "))
(setq et (fndet pt))
(setq ls (fndls et))
(drwdn ls)
(command "-bhatch" "p"
"ANSI31"
50
0
(list 60 60)
""
)
(endpr)
)


See how the BHATCH command is used. The tpyer of the hatch is selected, the scale and the rotation angle, and a point is picked.


The Functions


The START and ENDPR functions


Here they are:


(defun start (/ ss p1 p2)
(setvar "cmdecho" 0)
(command "blipmode" "off")
(command "limits" (list 0.0 0.0)
(list 120.0 120.0)
)
(command "snap" "on")
(command "snap" 10)
(command "grid" 10)
(command "zoom" "all")
(command "zoom" "0.8x")
(setq p1 (getvar "vsmin")
p2 (getvar "vsmax")
)
(setq ss (ssget "c" p1 p2))
(if ss
(command "erase" "all" "")
)
)




(defun endpr ()
(setvar "cmdecho" 1)
(princ)
)
There has been talked enough about these two functions. So no need to repeat what has been said before.


The DRLNS Function


Here is the function:


(defun drlns ()
(command "line" (list 10 10)
(list 30 10)
(list 30 30)
(list 60 30)
(list 60 10)
(list 110 10)
(list 110 110)
(list 10 110)
"c"
)
)


The LINE command is used in the function. Points have been specified. At the end of the LINE conmand the CLOSE option is used.


The FNDET Function


Here is the function:


(defun fndet (pt / ds ss)
(setq ds 10
ss nil
)
(while (null ss)
(setq ss (ssget "c"
pt
(polar pt 0 ds)
)
)
(if ss
(setq et (ssname ss 0))
(setq ds (+ ds 10))
)
)
et
)


A point has been picked between the lines. Now a line has to be found. The SSGET function is used to create a selection set.


The SSGET function works with two points. The first point is the point that has been picked. That point was given to the function.


The second point is on an angel of zero degrees from the first point. It is on a distance. The distance changes until a selection set is found.


If a selection set is found, then the name of the entity in the selections set is found using the SSNAME function. The name is given back.


The FNDLS Function


Here is the fucntion.


(defun fndls (et / fe cn el p1 p2 ls ss et pt)
(setq fe et
cn T
el (entget et)
p1 (cdr (assoc 10 el))
p2 (cdr (assoc 11 el))
ls (list p2)
ls (append (list p1) ls)
)
(while cn
(setq ss (ssget "c" p1 p1)
e1 (ssname ss 0)
)
(if (equal e1 et)
(setq et (ssname ss 1))
(setq et e1)
)
(setq el (entget et)
pt (cdr (assoc 10 el))
)
(if (equal pt p1)
(setq p1 (cdr (assoc 11 el)))
(setq p1 pt)
)
(setq ls (append (list pt) ls))
(if (equal et fe)
(setq cn nil)
)
)
ls
)


The entity, that has been found, is given to the function. The points of the entity are found and with them all other entities are found.


The points of the entities are the points of the lines. They are put in a list. And at the end the list is given back.


How it all is done. I guess that is clear.


The DRWDN Function


Here it is:


(defun drwdn (ls / ct)
(setq ct 0)
(while (setq pt (nth ct ls))
(command "donut" 0 2.5 pt "")
(setq ct (1+ ct))
)
)


A list of points have been found. That list is given to the function. In the function the DONUT command is used to draw the donuts.


That Is It


These are all the functions of the AutoLISP program. The number of functions is not too much. So we talk about a simple AutoLISP program.


Telling Others


Do you like what you have read? Do you know other people, that could be interested? Could you tell them about this blog?




Comment


In the mean time. If you have any questions. Or you want to tell me something. Feel free to add a comment to this blog.


I would love to hear from you. And when you come to me with a comment. I will give a reply to your question or remark.




Warning


Don't spend a lot of money on AutoCAD Light. It is only for creating 2D drawings and it doesn't support AutoLISP.


There is a very similar CAD program. And that is completely free. The name of the program? DraftSight.


How to get it? Do a search on Google for “download DraftSight”. And you will find where you can download the program.






Only Create Drawings


When your CAD operators don't create the borders of your drawings, a lot of time is saved. You get your drawings much faster.


I have created a program that does exactly that. An AutoCAD drawing has been created and the program draws a border around it.


If you want to see how the program works, go to YouTube. You'll find the working of the program here:


http://www.youtu.be/O8Zy6n9zS8Q


Now the AutoLISP program gives you the choice to select the size of your border. You can select A4, A3, A2, or A1.


Maybe you already know the size of the border of your drawing. Maybe all your drawings have the size A1. If so. Let me know.


That is important. The program finds the proper scale of your drawing. Or do you already know what the scale always is?


I can write the AutoLISP program that you want. The price? I will only charge you RM 600.-. That is less than US $ 200.-.






You are welcome to publish my article provided you include the resource box with links intact.




Resource Box


Jos van Doorn is an AutoLISP programmer and blogger. He is originally from Holland and now he lives in Malaysia.



He is the founder of the Make AutoCAD Fast business. Make AutoCAD Fast is writing AutoLISP programs for AutoCAD users.



Make AutoCAD Fast created an AutoLISP program for drawing a border around AutoCAD drawings. The program can be found on YouTube.
http://www.youtu.be/O8Zy6n9zS8Q



Jos is writing a blog. In it are AutoLISP programs with information and it is about Make AutoCAD Fast. You can find his blog here:


http://www.makeautocadfast.blogspot.com


Maybe you have a question. Or want to tell me something. You can contact me on this e-mail address:


makeautocadfast@ymail.com


This article may be freely reprinted or distributed in its entirety in any Ezine, newsletter, blog, or website. As long as the following resource box is added:


-------------------------------------------------
This article is written by Jos van Doorn. He is an AutoLISP programmer who has helped engineering firms and architects to get their AutoCAD drawings fast, without waiting for hours.


You can find more valuable information about his
business and AutoLISP at his blog. It is here:


http://www.makeautocadfast.blogspot.com


If you want to contact him. Go to his blog and leave a comment.
-------------------------------------------------


Sunday, January 19, 2014

AutoLISP Program Drawing Donuts And A Hatch 1

Introduction


I have an AutoLISP program. At the start it draws a room. This is how the room looks. It is pretty straight forward.




After the room has been drawn there is asked to pick point in the room. When that is done, the donuts are drawn and a hatch is added.


This is what you get. See the donuts that have been added and see the hatch that can be found in the room.




The AutoLISP Program


I know. Now you expect me to give you the AutoLISP program. Very good. Here is the complete AutoLISP program.


(defun c:dnsrm (/ pt et ls)
(start)
(drlns)
(setq pt (getpoint "\nPoint in room: "))
(setq et (fndet pt))
(setq ls (fndls et))
(drwdn ls)
(command "-bhatch" "p"
"ANSI31"
50
0
(list 60 60)
""
)
(endpr)
)


(defun start (/ ss p1 p2)
(setvar "cmdecho" 0)
(command "blipmode" "off")
(command "limits" (list 0.0 0.0)
(list 120.0 120.0)
)
(command "snap" "on")
(command "snap" 10)
(command "grid" 10)
(command "zoom" "all")
(command "zoom" "0.8x")
(setq p1 (getvar "vsmin")
p2 (getvar "vsmax")
)
(setq ss (ssget "c" p1 p2))
(if ss
(command "erase" "all" "")
)
)


(defun drlns ()
(command "line" (list 10 10)
(list 30 10)
(list 30 30)
(list 60 30)
(list 60 10)
(list 110 10)
(list 110 110)
(list 10 110)
"c"
)
)


(defun fndet (pt / ds ss)
(setq ds 10
ss nil
)
(while (null ss)
(setq ss (ssget "c"
pt
(polar pt 0 ds)
)
)
(if ss
(setq et (ssname ss 0))
(setq ds (+ ds 10))
)
)
et
)


(defun fndls (et / fe cn el p1 p2 ls ss et pt)
(setq fe et
cn T
el (entget et)
p1 (cdr (assoc 10 el))
p2 (cdr (assoc 11 el))
ls (list p2)
ls (append (list p1) ls)
)
(while cn
(setq ss (ssget "c" p1 p1)
e1 (ssname ss 0)
)
(if (equal e1 et)
(setq et (ssname ss 1))
(setq et e1)
)
(setq el (entget et)
pt (cdr (assoc 10 el))
)
(if (equal pt p1)
(setq p1 (cdr (assoc 11 el)))
(setq p1 pt)
)
(setq ls (append (list pt) ls))
(if (equal et fe)
(setq cn nil)
)
)
ls
)


(defun drwdn (ls / ct)
(setq ct 0)
(while (setq pt (nth ct ls))
(command "donut" 0 2.5 pt "")
(setq ct (1+ ct))
)
)


(defun endpr ()
(setvar "cmdecho" 1)
(princ)
)


(c:dnsrm)


Next Post


In the next post I'm going to talk about all the functions that can be found in the AutoLISP program. I will explain how they work.


Telling Others


Do you like what you have read? Do you know other people, that also could be interested in what I'm saying? Could you tell them about this blog?


Comment


In the mean time. If you have any questions. Or you want to tell me something. Feel free to add a comment to this blog.


I would love to hear from you. And when you come to me with a comment. I will give a reply to your question or remark.


YouTube


I have added videos to YouTube. The videos give examples of my AutoLISP programming work. You could engage me if you want.


If you are thinking of engaging me. Listen. I work for free. I write an AutoLISP program for you. You only pay when you are satisfied.


That is important. When you come to me with an AutoLISP programming job, you are not spending any money.


On YouTube you can find my videos here:


http://youtu.be/zgTWKo7DpeM
http://youtu.be/sd-sbyM3-d8
http://youtu.be/2yhk7G5KlAs
http://youtu.be/mEA6lymElqI
http://youtu.be/eyOdOTHPH-o
http://youtu.be/O8Zy6n9zS8Q
http://youtu.be/5sMBtfnnizk
http://youtu.be/QrmbXvmFa2o
http://youtu.be/4Ol-YpDC2MY
http://youtu.be/DWFke-Nie0E


Saturday, December 7, 2013

AutoLISP Program, Donuts, and Hatch 2

Introduction


In my previous post I was talking about this AutoLISP program. I showed you what screens are created by the AutoLISP program.


I told you about the complication there was and I gave you the complete AutoLISP program. Have you copied it to a text file?


The Actions Of The AutoLISP Program


This is what needs to be done by the AutoLISP program:


1. Switch off command echos
2. Set the limits
3. Set the snap
4. Set the grid
5. Display the whole screen
6. Make the whole screen empty
7. Lines are drawn
8. Pick point in the room
9. Find line of the room
10. Create list of points of the lines
11. Draw the donuts
12. Hatch the room


I have created functions in the AutoLISP program. The functions do what needs to be done.


The Functions


The START Function


I start with the START function. By that function the first six actions are performed. You already know how that function works.


Here is the START function:


(defun start (/ ss p1 p2)
(setvar "cmdecho" 0)
(command "blipmode" "off")
(command "limits" (list 0.0 0.0)
(list 120.0 120.0)
)
(command "snap" "on")
(command "snap" 10)
(command "grid" 10)
(command "zoom" "all")
(command "zoom" "0.8x")
(setq p1 (getvar "vsmin")
p2 (getvar "vsmax")
)
(setq ss (ssget "c" p1 p2))
(if ss
(command "erase" "all" "")
)
)


There is no function for picking a point in the room. It is done in the main program. Using the GETPOINT function.


The DRLNS Function


The DRLNS function is used to draw the lines of the room. The LINE command is used and the points are specified as a list.


Here is the DRLNS fucntion.


(defun drlns ()
(command "line" (list 10 10)
(list 30 10)
(list 30 30)
(list 60 30)
(list 60 10)
(list 110 10)
(list 110 110)
(list 10 110)
"c"
)
)


The FNDET Function


A line of the room has to be found after picking a point in the room. That is done with the FNDET function.


Here is the FNDET function.


(defun fndet (pt / ds ss)
(setq ds 10
ss nil
)
(while (null ss)
(setq ss (ssget "c"
pt
(polar pt 0 ds)
)
)
(if ss
(setq et (ssname ss 0))
(setq ds (+ ds 10))
)
)
et
)


The point that has been picked in the room is given to the function. And then a selection set is found with the SSGET function.


For that function the crossing option is used. The SSGET function works with two points. The first point is the point that has been picked.


The second point is found by using the POLAR contention. There is started with a distance of ten. And that distance is increased all the time.


Finding the selection set is done in a WHILE loop. The WHILE loop continues as long as no selection set is found.


If a selection set is found, then a line has been found. The entity of the line is found with the SSNAME function.


The name of the entity is given back by the function to the main program. It is used for the next function.


The FNDLS Function


Here is the FNDLS function. The function is used to find a list of points. The points are found at the end of each line of the room.


(defun fndls (et / fe cn el p1 p2 ls ss et pt)
(setq fe et
cn T
el (entget et)
p1 (cdr (assoc 10 el))
p2 (cdr (assoc 11 el))
ls (list p2)
ls (append (list p1) ls)
)
(while cn
(setq ss (ssget "c" p1 p1)
e1 (ssname ss 0)
)
(if (equal e1 et)
(setq et (ssname ss 1))
(setq et e1)
)
(setq el (entget et)
pt (cdr (assoc 10 el))
)
(if (equal pt p1)
(setq p1 (cdr (assoc 11 el)))
(setq p1 pt)
)
(setq ls (append (list pt) ls))
(if (equal et fe)
(setq cn nil)
)
)
ls
)


The function starts with giving the CN variable the value of true. The entity list of the line is found and the two points of the line.


The lines are written to a list. And then we get a WHILE loop. The WHILE loop continues as long as the variable CN has the value of true.


The selection set of the first point of the line is found. In the selection set are two lines. The previous line and a new line.


The new line is taken. There is checked what point hasn’t been found before. And that point is written to the list.


Writing a point to the list is done with the APPEND function. But it is important that the point is turned into a list.


This goes on until the point, that is found, is equal to the first point that has been found. That point is in the FE variable.


The DRWDN Function


With the previous function a list of points has been cremated. The list of points is given back to the main program.


The list of points if given to the DRWDN function. And it used to draw all the donuts at the ends of all lines.


(defun drwdn (ls / ct)
(setq ct 0)
(while (setq pt (nth ct ls))
(command "donut" 0 2.5 pt "")
(setq ct (1+ ct))
)
)


How is it done? Easy. The CT variable gets the value of zero. It is used to find the first point of the list.


The function opens with a WHILE loop. A donut is drawn in that point. And the value of the CT variable is increased with one.


The next point of the list of points is taken and a new donut is drawn. The WHILE loop continues as long as points are found.


The DRHTC Function


All the donuts are drawn, Now I want to draw a hatch in the room. That is done with the DRHTC function.


In the fucntion the BHATCH command is used. But before the name of the command there is placed a dash. I don't want a dialog box.


After starting the command I enter P. I want to specify the specifications of the hatch that is to be drawn.


The pattern of the hatch is ANSI31 and the scale of pattern is 50. The angle of the pattern is zero. Very good.


Now an internal point is specified. I could have taken the point that has been picked in the room. But I already know the internal point.


The internal point is 60,60. I enter (LIST 60 60) for the internal point. And an ENTER is entered too. Now the hatch is drawn.


(defun drhtc ()
(command "-bhatch" "p"
"ANSI31"
50
0
(list 60 60)
""
)
)


The ENDPR Function


Everything that needed to be done, has been done. The ENDPR function is started. Here is the function. You already know about it.


(defun endpr ()
(setvar "cmdecho" 1)
(princ)
)


The Complete AutoLISP Program


You have got the complete AutoLISP program with an explanation of all the functions. Copy it to a text file and run it.


I hope everything was clear. If not. Let me know. You know how you can do that. Maybe I should have been more clearer.


Telling Others


Do you like what you have read? Do you know other people, that could be interested? Could you tell them about this blog?




Comment


In the mean time. If you have any questions. Or you want to tell me something. Feel free to add a comment to this blog.


I would love to hear from you. And when you come to me with a comment. I will give a reply to your question or remark.




Warning


Don't spend a lot of money on AutoCAD Light. It is only for creating 2D drawings and it doesn't support AutoLISP.


There is a very similar CAD program. And that is completely free. The name of the program? DraftSight.


How to get it? Do a search on Google for “download DraftSight”. And you will find where you can download the program.






Only Create Drawings


When your CAD operators don't create the borders of your drawings, a lot of time is saved. You get your drawings much faster.


I have created a program that does exactly that. An AutoCAD drawing has been created and the program draws a border around it.


If you want to see how the program works, go to YouTube. You'll find the working of the program here:


http://www.youtu.be/O8Zy6n9zS8Q


Now the AutoLISP program gives you the choice to select the size of your border. You can select A4, A3, A2, or A1.


Maybe you already know the size of the border of your drawing. Maybe all your drawings have the size A1. If so. Let me know.


That is important. The program finds the proper scale of your drawing. Or do you already know what the scale always is?


I can write the AutoLISP program that you want. The price? I will only charge you RM 600.-. That is less than US $ 200.-.






You are welcome to publish my article provided you include the resource box with links intact.




Resource Box


Jos van Doorn is an AutoLISP programmer and blogger. He is originally from Holland and now he lives in Malaysia.



He is the founder of the Make AutoCAD Fast business. Make AutoCAD Fast is writing AutoLISP programs for AutoCAD users.



Make AutoCAD Fast created an AutoLISP program for drawing a border around AutoCAD drawings. The program can be found on YouTube.
http://www.youtu.be/O8Zy6n9zS8Q



Jos is writing a blog. In it are AutoLISP programs with information and it is about Make AutoCAD Fast. You can find his blog here:


http://www.makeautocadfast.blogspot.com


Maybe you have a question. Or want to tell me something. You can contact me on this e-mail address:


makeautocadfast@ymail.com


This article may be freely reprinted or distributed in its entirety in any Ezine, newsletter, blog, or website. As long as the following resource box is added:


-------------------------------------------------
This article is written by Jos van Doorn. He is an AutoLISP programmer who has helped engineering firms and architects to get their AutoCAD drawings fast, without waiting for hours.


You can find more valuable information about his
business and AutoLISP at his blog. It is here:


http://www.makeautocadfast.blogspot.com


If you want to contact him. Go to his blog and leave a comment.
-------------------------------------------------