Visual LISP: Program which divides an ARC with equal spaces and projects on a line



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

All Visual LISP versions

Hello Daily AutoCAD readers,

Today’s subject is a special request a reader, Naim Yılmaz, from Turkish version of our website AutoCAD Gunlugu. Our reader has asked for a program that divides and ARC entity into equal spaces by using MEASURE command (Fig. 1). Points are distributed automatically along the shown entity by AutoCAD. Until this point, Naim has made it perfectly by himself. I will try to explain how to determine the number of points and how the perpendicular lines are drawn onto a beam that is connected to the arc as shown in Fig. 2.4.

In order to draw the beam, there is no need for prompting the user to enter start and end points. We can get them by using vla-get-StartPoint and vla-get-EndPoint commands which are part of the properties of arc entity and store the results in sp, ep variables (Code 2).

NOTE: Check the system variables PDMOE=35 and PDSIZE=0 (zero) settings. Points may not be properly seen on the screen.

Before the _MEASURE command is used, last entity that is transferred into the AutoCAD database is determined (utl:entity:get:last) and all the entities that were added after that one is called by using (utl:entity:next) function (Code 2, blue arrows).

You can get the pp points that are intersecting with the beam by using CAL_OrthoProjectPointToLine function (Code 3). (Functions that are written with red and bold are stored in“KM-Lib.VLX” library, and includes mathematical operations)

Next step is quite simple, perpendicular lines are created by using vla-AddLine command.

Fig.1 Fig.2
Fig. 1 – Select any arc on the screen (ARC entity) Fig. 2 – POINTs that have equal spacing are created by using _MEASURE command and a beam that is connected to the arc. 
Fig.3 Fig.4
Fig. 3 – We are creating lines start point of which is center of arc px and are perpendicular to the beam. Calculating the intersection point pp is the key point!!! 
Fig. 4 – At the end of program, you will get something like this. Points that we don’t need are deleted.

Command: KM_Measure
>> Makro: "KM_Measure" programed by M. Koçyiğit
>> Please select ARC to measure:
(Select the ARC entity that you would like to delete)
>> Specify length of segment <5>: 10
(Enter the equal spacing that you would like to divide with)
>> 13 POINTS are exist ...

The main function C:KM_Measure prompts user to select an ARC (Code.1) and it passes the result to Mea-Execute which is a sub-function (Code.2). Just like it is done for all of the main functions, there is also an *Error* function which informs AutoCAD if there is an error. Mea-Error sub-function informs us of any possible errors. 

Code.1
Code.1 – Main function “C:KM_MEASURE“
Code.2
Code.2 – Sub- function “Mea-Execute“
Code.3
Code.3 - Sub- function “Mea-Draw-Each-Point“

The purpose of Mea-GetCurrentSpace function (Code.4) is to determine which drawing area the user is at. As you all know, there is also as Layout (Paperspace) space beside Model (Modelspace) space. Moreover, considering that AutoCAD also has multi document property, which enables AutoCAD to open and process multiple documents (drawings) at the same time, this is a very necessary operation. Otherwise, VisualLISP will draw the entity that you are willing to draw at another at a completely different place. The return value of our function will be given as VLA-OBJECT.

For example:

#<VLA-OBJECT IAcadModelSpace2 0ea1dabc> (Modelspace)
#<VLA-OBJECT IAcadPaperSpace2 0e708e64> (Paperspace)
 

Code.4
Code.4 - Sub- function “Mea-GetCurrentSpace“

Visual LISP commands that are used in the program:

vl-load-com
vlax-get-ACAD-Object
vla-get-ActiveDocument
vla-get-ActiveSpace
vla-get-ModelSpace
vla-get-PaperSpace
vlax-ename->vla-object, vlax-vla-object->ename
vla-get-ObjectName
vla-AddLine
vla-get-Coordinates, vlax-3d-point
vla-get-StartPoint, vla-get-EndPoint
vl-CmdF

Have a nice day; we are looking forward to hear your questions and comments.

LISP files: Measure.rar

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

4 Responses to “Visual LISP: Program which divides an ARC with equal spaces and projects on a line

  • 1
    abu
    May 8th, 2007 16:14

    sir,
    i want polyline lisp .. i want one start point to end point .. lay automatly ( pl ) what is the procedure in the line ….

    with Regards,

    ( M.siddick )

  • 2
    balraj
    December 15th, 2007 09:43

    Sir,
    I want parabolic curve ,i have start point & end point ,
    no of nodes.Now i have to calculate slope & y co-ordinates & also draw parbola using y cordination

  • 3
    nagaraj
    February 27th, 2008 15:41

    i want some sample program in lisp for my project

  • 4
    Jason Day
    May 30th, 2008 20:54

    I am still learning the basics of Visual Lisp so this has some great information. The Mea-GetCurrentSpace function is very useful.
    Where do I get the (utl:entity:get:last) and (utl:entity:next) code? Those would be really useful functions.
    Thanks for the help!

Leave a Reply