Monday
Autocad, Programming, Visual LISPVisualLISP: Calculating slope between two points
Visual LISP
Hello Daily AutoCAD readers,
Today, I would like to explain the program “measuring the slope between two points” that was in article that was published by Erhan before, but this time in Visual LISP. The name of the main program is SlopeX, all of its sub-functions are named by using ax: prefix. This is a method that is used to distinguish them from the other LISP functions. Of course, you can define them by using any other definition you want.

Code.1 – Main function “C:SlopeX“
Ax:Entsel function (Code.2) provides easiness to select entities and selects only one entity at a time. If the selection is completed successfully, then the program returns a list of two members. First members of the list is entity itself (VLA-OBJECT), and the second member is the point at which the entity is selected (safearray). If the entity is not selected, then the result is a nil value (not in list = you have not selected anything).
For example:
(#<VLA-OBJECT IAcadLine 014fe064> #<safearray...>)
safearay is a Visual Lisp data type. Its purpose is to store data as a directory tree. If you would like to convert this directory tree, thus the point that you have selected, into a list then you must use (vlax-safearray->list) function.
I suggest that you should read the article “Object properties and methods” about VLA-OBJECT data type that I have written previously.
First parameter of most of the sub-functions are given as a:util. It defines AcadUtility class that is present in VisualLISP. This class is some kind of toolbox where you can find a lot of useful utility functions (VBA class name: AcadUtility).

Code.2 – ax:EntSel function helps you to select one single entity.
If you want the user to enter one single point, then you can use the (ax:GetPoint) function (Code.3)

Code.3 – ax:GetPoint function helps you to enter one single point.
ax:Get:Object function (Code.4)
ax:Get:Object function (Code.4) helps you to get an entity that you defined. If we give as an example as the second parameter of the main program as a:oName, then we can say “AcDbLine”, “AcDbCircle” or “AcDbArc”.
While loop is used to make loop until the user makes a correct input.
The third parameter a:msg is used to give a message to the user to make a selection. You can use “\nSelect a CIRCLE:” as an example. We are simply prompting the user to select a circle.

Code.4 – ax:Get:Object helps you during selection of entities.
ax:CalcSlope function (Code. 5) calculates the slope between the two points by using the input data.

Code.5 – ax:CalcSlope calculates the slope
ax:ShowResult function shows the result value on the screen.
• Starting and end point of the points of the line that you selected on the screen,
• Distance between the two points
• Angle with the X axis on XY plane and the slope of the line…

Code.6 – ax:ShowResult function gives the resultant data about the slope of the line.
Good bye.
Technorati Tags: Visual LISP
Viewed 7,667 times so far... This week: 69 Today: 4 Latest: 5 July 2009, 5:19Post 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
|

Aug 1, 2008
Reply
Sir,
I read your views and I liked the way you made working with AutoCAD easier.
I would like you to guide me with certain Drawing etiquttes of AutoCAD.To make my working in ACAD easier and simple.Would like to learn make my work more easy and more efficient.
Hope to hear from you soon.
nasir.wangde@gmail.com
Oct 4, 2008
Reply
Sir,
I am an autocad operator and need some help in making my work be easier and faster and as i saw you are an expert man in LISP i would like you to give me some help if possible.
hope you will accept to help me…
thx in advance
ramy_nakad@hotmail.com