Our Friends: Leaflet Printing , Presented by: Talia Cad Software

Sign In

Subscribe

Subscribe to Daily Autocad.


Nov 05
Monday
Autocad, Programming, Visual LISP
VisualLISP: 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
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:

Viewed 7,667 times so far... This week: 69 Today: 4 Latest: 5 July 2009, 5:19

Post Tags:

2 Responses to “ VisualLISP: Calculating slope between two points ”
  1. Nasir Wangde

    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

  2. Ramy Nakad

    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


Post a Comment



All content and source © 2008 Daily Autocad | News Plus wordpress theme brought to you by Zidalgo.