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

Sign In

Subscribe

Subscribe to Daily Autocad.


Apr 30
Wednesday
AutoLISP, Autocad, Programming
AutoLISP Programming: A LISP to edit your text objects with number entries

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:

Viewed 5,783 times so far... This week: 69 Today: 3 Latest: 5 July 2009, 6:11

Post Tags: , ,

10 Responses to “ AutoLISP Programming: A LISP to edit your text objects with number entries ”
  1. Richard Djeniko

    Jun 14, 2008
    Reply

    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. I want to export text in autocad file to MS-excel. Can anyone help me out?..
    Thanks

  3. 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. How we can draw in autocad by giving commands in excel? Please tell me

  5. M.Derya BAHÇECİ

    Sep 15, 2008
    Reply

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

  6. Vincent Tigchelaar

    Oct 27, 2008
    Reply

    Hi, great Lisp!
    Just a small question. Is it possible to multiply or devide the content of the text object with a given number?

  7. Hi guys

    if you are changing elevation data say on sections /levels on general arrangements etc via text objects or attributes try using fields in your text. press <control F>  or right click for context menu for options in multiline text editor or you only can right click in attribute box when in a block.  The fields can be accessed easier via document field in dialogue box.

    rao intialise you custom variables  go to [file]menu[drawing properties]  [custom] tab
    add data in dialogue box.

    put the field inthe text / attributes  in whatever blocks you use for your different elevations / sections and plans. when you save the fields should automatically update. you can alter the  settings for when the fields update. its all pretty straight forward.

    when you do it loads it becomes far easier.

    i haven’t tried your lisp routine but i wasn’t aware of a change command in autolisp,

    and now that i have had a look you need to do a lot more with it if you are going to get it to work.

    if you’ve defined your own command ‘change’ you need to include what that does.

    the best thing to do  is get the user to pick a selection set by using soming like this

    (setq mc 1)(setq Alltextn 0) (setq selectionwindow nil)
    (while (/= mc nil)

    (initget 1 “a A w W x X”)
    (if ( = Alltextn 0)
    (setq answer1(getkword”\n[All text[OFF]/Window/runX]: “)))
    (if ( = Alltextn 1)
    (setq answer1(getkword”\n[All text[ON]/Window/runX]: “)))  

    (if (or (= answer1 “a”)(= answer1 “A” ))
    (progn
    (setq Alltextn 1)
    (setq a (ssget “_X” ‘((0 . “TEXT”))))
    (prompt “\n<All text> option selected”)
    (setq mc (1+ mc))
    )))

    this bit of code is not complete but shows how you would get a selection set of all text objects in a drawing from a menu on the command line. ive only included the all text option.

    once you’ve got your selection set you need to determine length of selection set & then the name of each entity in the selection set .
    remember a is the selection set. b is the selection set length. iterate with while. get the assoc code 1 for text of object.
    something like this
    (setq b (sslength a))

    (setq counter 0)

    (while (< counter b)

    (setq Entname (ssname a counter))
    ;(print Entname)
    (setq Entlist (entget Entname))
    ;(print Entlist)

    ;1 Default value (the string itself)
    (setq x1 (assoc 1 Entlist))
    ;(print x1)
    (setq Stringtext (cdr x1)))

    again not a complete listing but you would need to add routine as above to change text to float number format,  then perform operation on it which does work…

    you then need to use  entmod command to update variable once you have assembled dot list.

    alternatively you could recreate the info in a new text object and delete the selection set at the end of the routine .
    (command “mtext” pt1 “s” Tstyle “h” Theight “j” justifytext “r” Trotate pt1 Stringtext “”) obviously you would need to get more association codes from dxf reference for the above line to work. for various things.

    you could also try using vla-add etc methods.

    good luck.

  8. Sir,

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

  9. Sir,

    How can Possible.  I have L-Section , I want change Different between Two Level in autocad.

    Example – 34 and 36 differen =2 Value -2 Input in My Autocad DWG Have any Lsp of Change the Thirt Value.

  10. vijaya varma namburi

    Apr 27, 2009
    Reply

    Hi All,

    How can I edit any one particular LAYER  (names & colors) using DIESEL in AutoCAD LT for several hundred .dwg files in a single go?

    Regards,
    vijaya


Post a Comment



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