Sunday, November 17, 2013

Turning An Arc Into A Circle In AutoLISP

Introduction


Here I have a very simple AutoLISP program. We have an AutoCAD drawing. In it you find arcs. They are turned into a circle.


This is how the AutoCAD drawing looks after all the arcs have been turned into circles. The layers stayed the same.






The AutoLISP Program


Here is the AutoLISP program. It is a very simple program. It works right away. The user doesn't have to make a selection first.


(defun c:artcr (/ ss)
(setvar "cmdecho" 0)
(setq ss (selar))
(drcrc ss)
(setvar "cmdecho" 1)
(princ)
)


(defun selar (/ ss)
(setq ss (ssget "x" (list (cons 0 "ARC"))))
ss
)


(defun drcrc (ss / et el la cp rd)
(while (setq et (ssname ss 0))
(setq el (entget et)
la (cdr (assoc 8 el))
cp (cdr (assoc 10 el))
rd (cdr (assoc 40 el))
)
(command "erase" et "")
(command "layer" "s" la "")
(command "circle" cp rd)
(ssdel et ss)
)
)


(c:artcr)


How The AutoLISP Program Works


We have the main AutoLISP program. The main AutoLISP program is ARTCR.LSP. And we have two functions: SELAR and DRCRC.


Let's start with the main program. At the start the CMDECHO system variable is set to zero. At the end of the program it is set back to one again.


AutoCAD commands have been used in the program. We do not want command echos. That is why the CMDECHO system variable is set to zero.


After setting the CMDECHO system variable to zero, calls are made to both functions. A call is made to the SELAR function.


In that function all arcs in the drawing are selected. That is done with the SSGET fucntion. The X option is used.


That all arcs need to be selected has been specified in the SSGET function. See how it is done. (CONS 0 "ARC") has been used.


A selection set has been created. The selection set is stored in the variable SS. And that variable is given back to the main program.


Next a call is made to the second function. A call is made to the DRCRC function. A lot is done in the DRCRC function.


In the function is the WHILE loop. As long as an entity is found in the selection set, the WHILE loop continues to work.


The entity is an arc. The entity list of the arc is found. And then the following three values of the arc can be found:


- The layer of the entity
- The center point of the arc
- The radius of the arc


These values are needed for what is done next in the function. The layer of the arc is set. And a circle is drawn on the layer.


Before the layer is set and the circle is drawn, the arc is erased. We do not want it no more. That is why.


After the layer has bee set and the circle has been drawn, the arc is removed from the selection set. That is important.


In the WHILE loop the first entity of the selection set is selected. Later it is removed, so the first entity is the next entity.


In the WHILE loop the first entity in the selection set is selected. And when there are no more entities, then the loop stops.


Make AutoCAD Fast




This is an example of how I do AutoLISP programming. I figured out what needs to be done and the AutoLISP program does it.


If you are looking for an AutoLISP program, that will help you to save a lot of time and money. Come to me.




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


No comments:

Post a Comment