Monday
AutoLISP, Autocad, ProgrammingAutoLISP sample: Measuring the slope between two points
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
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
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
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
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
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
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: AutoLISP, VisualLISP, AutoLISP programming
Bu yazinin Turkce’sini okumak icin basiniz.
Viewed 7,320 times so far... This week: 43 Today: 3 Latest: 5 July 2009, 0:33Post Tags:
Related Posts
Popular
- Hip tip: Increasing view resolution with VIEWRES system variable
07/03/2009 04:39 am
7 Comments - Sirince – IZMIR
07/02/2009 11:02 am
1 Comment - Visual LISP: Programming user interfaces with OpenDCL
07/01/2009 10:15 pm
10 Comments - 3D Modeling 7: EXTRUDE
06/30/2009 02:14 pm
10 Comments - Ask DailyAutoCAD: Which Notebook to Buy?
06/30/2009 12:17 pm
1 Comment
Featured Articles
- AutoCAD 2009 Update 3 Released
- Speed Up As AutoCAD 2009 Ribbon Menu Helps You!
- MEP Analysis Extension for AutoCAD MEP extended to March 31, 2009
- Recap of AutoCAD-related technologies on Autodesk Labs
- Technology Preview of MEP Analysis Extension extended to 12/31/08
- Autodesk Labs: Forward and Backward utility for AutoCAD
|

Jun 28, 2007
Reply
Hi, how can i start learning how to create my own LISP programs? How can i start to understand the LISP commands? tnx!
Dec 4, 2007
Reply
Erhan,
Hi , i am just a beginner in learning LISP…i am trying to produce a drawing of size of door eg…800×2100mm or something line a automatic size of rectangle in producing door schedule…an you please sent me some LISP idea .
Thanks and Regards
Alan
Aug 17, 2008
Reply
I need a help when insert a block i.e. rectangle can we put sr. no. automatically through lisp ?
Aug 18, 2008
Reply
Hello Sunil,
Yes you can. There are 5 system variables to use with LISP : USERI1 .. USERI5. You can set this variables with (setvar “USERI1″ 1) and retrieve the values with (getvar “USERI1″) functions. And you can use this values as a counter. And generate names like this :
(setq blkName (strcat “ABLOCKNAME” (itoa (getvar “USERI1″))))
Hope this helps
Thanks for the comment