AutoLISP Programming: A LISP to edit your text objects with number entries



Author M. Derya Bahceci
Profession Civil Engineer
   
Location Ankara, TURKEY
e-mail  

All AutoLISP versions

Hi to all,

Since this is my fist article on this site, I want to share a LISP, which I have created in the very beginning of my AutoCAD history. The aim of the program is to search a defined area and perform mathematical operations in the found text objects with number entries. I have written this program because I have had to change lots of elevation entries since the datum is set wrong. Since chancing them one by one means a serious time, it helped me a lot. I hope it will help you too.

Let us first define the program. ‘cx’ ,as a shortcut, is selected to run the command. I generally choose close keys that is nothing assigned to them.

Fig.1
Code-1

I wanted to run the command in a closed area that I designated instead of the whole drawing. So the next thing is defining a polygon and having the search processed inside.

Do not forget, you have to define the last point in a way that the polygon should include the first point otherwise, process plots an error.

To allow this, I have written the lines below:

Fig.2
Code-2

The point here is listing the text objects in ‘E’ layer found in the designated area in ‘sspoint’ variable and saving them into database. ‘E’ letter in the line (cons 8 “E”) stands for the layer. You can change it with the one you want. You will understand the process better when you examine the lines.

To assign the number of the found text objects to a variable that is going to be used in upcoming loop operation; we have to know the length of sspoint list. So I just write the related command.

Fig.3
Code-3

If some text objects exist in the area defined, the ‘ssl’ variable will be an integer. Let us use it and create a loop.

Fig.4
Code-4

The operation in this example is subtracting ‘0.30’ from the value. You can change it as you like. Do not forget; if the content of text object selected is letters, not numbers, the program just replaces it with ‘-0.30’. So, the objects with number entries should be formed in a different layer.

To end the program we have to make the parenthesis equal.

Fig.5
Code-5

You can understand the program better if you run it in AutoCAD step by step. For instance, just write down the polygon part of the program, run it and check the results. And then make the list and so on. Studying LISP files step by step always gives better results.

Regards.

Related file:

Technorati Tags:

Similar Posts

Rate this article:

1 Star2 Stars3 Stars4 Stars5 Stars (1 votes, average: 5 out of 5)
Loading ... Loading ...

5 Responses to “AutoLISP Programming: A LISP to edit your text objects with number entries

  • 1
    Richard Djeniko
    June 14th, 2008 21:30

    I have been an AutoCAD engineer without having enough knowledge of programming in Autolisp, you first lesson is drawing me closer in using autoCAD lisp programming now.

    thanks a million

    i wholeheartedly appreciate you.

    Yours sincerely,

    Richard Djeniko

  • 2
    Balaji
    June 17th, 2008 11:04

    I want to export text in autocad file to MS-excel. Can anyone help me out?..
    Thanks

  • 3
    jacob
    July 12th, 2008 14:19

    amzaing article….the problem was worrying me for years ….hey dude you simply rock….and keep exploring things like this always……the show must go on

  • 4
    Balaji
    September 13th, 2008 11:46

    How we can draw in autocad by giving commands in excel? Please tell me

  • 5
    M.Derya BAHÇECİ
    September 15th, 2008 17:23

    Dear Balaji,
    What do you exactly want to input Excel to Autocad?
    Please be more specific, so I try to help you.
    Regards.

Leave a Reply