VisualLISP: Calculating slope between two points



Author Muharrem Koçyiğit
Profession Mechanical Technician
  AutoCAD & Prosteel Specialist
Location Germany
e-mail  

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
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
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)

Fig.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
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
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
Code.6 - ax:ShowResult function gives the resultant data about the slope of the line.

Good bye.

Technorati Tags:

Similar Posts

Rate this article:

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

Leave a Reply