An AutoLISP program that draws a bubble at the end of axes.
Print This Post
![]() |
Author | Orhan Toker |
| Profession | Architect M.Sc. | |
| Autodesk Authorized Consultant | ||
| Database Specialist | ||
All AutoLISP versions
Hello,
In this exercise, we will do the process of placing a bubble at the end of a LINE entity so that the bubble is aligned according to angle of the line and there is a text inside the bubble. First of all, see the complete code. To download code click DOWNLOAD CODE Note that there are small changes in code. The link i gave you containing the newest version but i couldn’t change the gifs in article. Please accetp my apologizes for this.

Fig.1 Full view of Bubble.lsp code.
Do not directly load the code and run it. You can click on the above link and download the code, however I am giving the code so that you can compare it with the one you are about to write. If you would like to learn this application, just print the code, sit down and write it yourself by looking at it. I will also explain it one by one while you are writing it.

Fig.2
In these two lines, we are storing the current values of CMDECHO and CLAYER variables, values of which we will change later.

Fig.3
And in this line, we are creating and updating the layer in which the bubble will be created first and then the text that we will write inside the bubble. After this, we are closing command echos so that the command macro that we have written does not give double output lines (echos) together with the AutoCAD messages.

Fig.4
Command definition function is prepared for calling the other functions automatically only when you write bubble in the command line. In this function, it is provided that user inputs the value for diameter of the bubble. I can explain the reason why the value of diameter of bubble is not asked while drawing like this: We could have done the part where the c:bubble command calls draw_buble drawing function which does the real work by creating an infinite cycle until the user presses ESC button. Due to the fact that, it is meaningless for the user to input diameter in each cycle in such a choice, we did this work before the infinite cycle.

Fig.5
I placed a / character after the parenthesis where the argument definition of draw_buble function in its definition line, and then I defined all of the local variables. Reason is to prevent the confusion that will be caused by defining the variables that I will use inside the function in other functions and to fasten the execution of program. In my following lessons, I will explain these in detail in the function definitions and arguments lesson.

Fig.6
Here, by using only one (setq) setting function we are setting the value of four different variables that belong to the axis at a time. How?
•
(entsel)function is used to make selection of an entity with one click. A list of 2 elements which are and values, returns at the end of this function.( (769.977 792.846 0.0)). First element of the list is the entity name and the second element is the coordinates of the point from which you have selected the entity. I assigned this two-membered list to aks variable.
• By using(setq pp (cadr aks)), I assigned the selection point, which is the second element of the list, to pp variable. This means that,(cadr)function is used to select the second single element of the list.
• In(setq aks_hand (entget (car aks)))line, I am assigning the DXF code list of the entity that I have selected to aks_hand variable.. When(entget)command is called by entity name, which is the only argument of it, it gives the DXF code list of the entity that has the label of entity name as its return value. I used(car)function to extract only the first element of the list, which is entity name value. Thus, (car) function is used to extract only the second element of the list value. Don’t worry, we will explain functions like (entget), (car) and (cdr) in the following lessons.
• We can learn what the selected entity is from the 0 component of DXF double code list (dotted pair). That component will be(0 . "LINE"). Then, we use (assoc) function to learn what is the value of this dotted pair which corresponds to 0. In practice, (assoc) is not used separately by itself. It is used to get data from the list as(cdr (assoc value_searched list_name)). We have written this line like this so that we can find which value corresponds to 0. For dotted pairs and management of lists, check out the following lessons.

Fig.7.
In this part, if the entity you have selected is not a LINE then the program will exit. The reason is that, we formed all of the code according to LINE. I will show the use of if function and use of its operators in the following lessons. Here, you can see only how it works.

Fig.8
In this line, we are getting the start and end points of the axis that we have selected from the values of 10 and 11 from the DXF code list. Up to now, we have learned that 0=entity name, 10=starting point, 11=end point. In the following lines, by using (angle p1 p2) AutoLISP function, we calculated the angle formed by two points and we also learned that (dist p1 p2) function is used to calculate the distance between two points.

Fig.9
In this part, we are calculating the center point of the circle according to the end of axis which is closer to the selection point. Here, we can make a small calculation. Assume that first point that we picked while drawing the line is p1 and the second point is p2. We have calculated these values as aks_p1 and aks_p2 above. We also know the angle formed by p1 – p2 points. If user has clicked on a point closer to p1, then we should draw a circle at the extend of p2 – p1 vector (p1 point); or if user has clicked on a point closer to p2, then we should draw a circle at the extend of p1 – p2 vector (p2 point). We can calculate this point by using (polar point angle distance) function. At the position where the point is close to starting point, in order to reverse the normal of vector, we are adding 180 degrees (which is pi in radians) to the axis angle.

Fig.10
After this, we are drawing the circle and place a bubble label in the middle of it. We are re-assigning the default values for system variables settings that we have changed previously.
This was our first AutoLISP application. To write the program, and execute it, you should read our “AutoLISP.2: Programming with Visual LISP editor” lesson. You can form up the code by following the steps there.
Similar Posts
Rate this article:


July 1st, 2007 09:59
Sir
I need a simple autolisp code that reads x,y,z data file and draws the 3D shape using the 3DMesh command
Regards