AutoLISP sample: Measuring the slope between two points



Author Erhan Toker
Profession Architect M.Sc.
  Autodesk Authorized Consultant
  Software Specialist
e-mail  

AutoLISP programming

By Drawing a 1/3 sloped roof in 3D article, I have already explained about a useful 3 dimensional technique. And in this article, I will explain how to measure the slope between two points. Before starting this article, I would like to mention that the name of the LISP file that we used in this article is tal_slope.lsp and it includes some of the functions that we have already explained in the previous articles. First, let me explain the (ut-get-object) function ( Fig. 1 ).
 
Fig.1
Fig. 1

First parameter of this function is p:str:otype which shows the type of the object that you would like to select and you can use any of DXF names like “LINE”, “CIRCLE”. Second parameter p:str:prompt is the message prompted from the command line to the user for making a selection. For example, you can use “\nSelect a LINE:”. By this way, you remind the user that you would like him/her to select a line. If the user selects the selection set accordingly, then the function returns the DXF list of that entity. For now, let’s put this function at aside to use it in future and return back to our original function (Fig. 2).
 
Fig.2
Fig. 2

As you can see from the definition, the name of our command will be SLOPE. (get_sys_vars) stores some of the variables and (set_sys_vars) adjusts system variables like CMDECHO, OSNAP according to the execution of command. In the third line, we are continuing by setting our debugging routine.

In order to find the slope between two points; we, as the program designer, will suggest two different methods. First one is selecting two points, and the second one is selecting a line and using the to points of this line. For this reason, by getting use of the structure of command line, we will use point input function as optional and the user will be able to edit his/her selection as LINE also if he/she would likes (Fig. 3).
 
Fig.3
Fig. 3

After setting (initget) function so that “line” can also be given instead of point, now we can proceed with passing the “\nFirst point or [Line]: “ to the (getpoint) function. By this way, if user makes “L” selection of pressed ENTER button, then p1 variable will the value of “Line” or nil. If the user would likes to continue by selecting a line ( true ), then we will make the user to select a line by using (ut-get-object) and load the starting and end points of this line to p1 and p2 points from DXF list (10 and 11). If the user answers the first question by point, then p1 will already be the first point selected, and the user will be prompted to select a second point in( false ) section. And this point will be stored as p2. At this stage, we have two different 3 dimensional points. Now, here are the possibilities: these two points can be on the same elevation plane ( p1.z = p2.z ) or they may have different Z coordinates.  If they are in the same elevation plane, then we will make our calculation by using Y coordinates and in the other case, we will make calculation by using Z coordinates (Fig. 4).
 
Fig.4
Fig. 4

As you can see, first, we are setting all the coordinates as x, y, z and define our calculations accordingly. Next step is to make the slope written on the screen (Fig. 5).
 
Fig.5
Fig. 5

Please note that s1 variable is edited as “3D” or “XY plane” according to its position in Fig. 4. Finally, we are setting the variables and putting the debugging function in its starting position (Fig. 6).
 
Fig.6
Fig. 6

When you load the tal_slope.lsp file, then the SLOPE command will be ready and when you execute it, you will get the following:

Command : SLOPE
First point or [Line]: L
Select a line:
The slope is %57.63 in XY plane

Related articles: Loading AutoLISP applications automatically, AutoLISP page, Drawing a 1/3 sloped roof in 3D

Download locations: tal_slope.lsp

Technorati Tags: , ,

Bu yazinin Turkce’sini okumak icin basiniz.

Similar Posts

Rate this article:

1 Star2 Stars3 Stars4 Stars5 Stars (No Ratings Yet)
Loading ... Loading ...

3 Responses to “AutoLISP sample: Measuring the slope between two points

Leave a Reply