+ Reply to Thread
Page 1 of 3 1 2 3 LastLast
Results 1 to 10 of 24
  1. #1
    Junior Member
    Using
    AutoCAD 2006
    Join Date
    Mar 2008
    Posts
    14

    Default Lisp for adding number to multiple text entities?

    Hello,

    This might be a little tricky, but does anybody know of a lisp routine that can add a certain number to multiple dtext/mtext entities?

    For example, I have a topographical survey in dwg format, I do not have the original survey data. I need to adjust the levels to a new datum. I therefore need to add 9.123 to all of the text values.

    I would be very grateful for any assistance - I'm always telling all my CAD friends how great this site is

    Thanks!

    (I am currently using vanilla ACAD 2006)

  2. #2
    Senior Member Commandobill's Avatar
    Using
    AutoCAD 2008
    Join Date
    Oct 2008
    Location
    Massachusetts
    Posts
    317

    Default

    add as in 1+2=3 or add as in "something" = "something 9.123" ?
    ***Commandobill***
    Abusing AutoCad Since 1999
    "Caddatude... Do you has it?"
    Sorry for my poor English, I'm American...

  3. #3
    Junior Member
    Using
    AutoCAD 2006
    Join Date
    Mar 2008
    Posts
    14

    Default

    Ah sorry, I mean I have a set of numbers, say 6.000, 5.900 etc. and I want to add say 1.500 to each and every one of them, so in this instance I would be left with 7.500 and 7.400.

    I want a lisp that edits the number by adding x amount to it.

  4. #4
    Senior Member Commandobill's Avatar
    Using
    AutoCAD 2008
    Join Date
    Oct 2008
    Location
    Massachusetts
    Posts
    317

    Default

    like this?
    Code:
    (defun c:addn ( / ss)
      (vl-load-com)
      (if (and (setq ss (ssget "X" (list (cons 0 "*text"))))
           (setq amt (getreal "\nPlease type the amount you would like to add: ")))
        (progn
          (mapcar '(lambda (z) (vla-put-textstring z (rtos (+ (atof (vla-get-textstring z)) amt) 2 3)))
              (mapcar 'vlax-ename->vla-object (vl-remove-if 'listp (mapcar 'cadr (ssnamex ss)))))
          )
        )
      (princ)
      )
    Last edited by Commandobill; 15th Jul 2009 at 12:28 pm. Reason: added option for increment
    ***Commandobill***
    Abusing AutoCad Since 1999
    "Caddatude... Do you has it?"
    Sorry for my poor English, I'm American...

  5. #5
    Junior Member
    Using
    AutoCAD 2006
    Join Date
    Mar 2008
    Posts
    14

    Default

    Wow - that is incredible!

    Thank you very much indeed for that - much appreciated

  6. #6
    Senior Member Commandobill's Avatar
    Using
    AutoCAD 2008
    Join Date
    Oct 2008
    Location
    Massachusetts
    Posts
    317

    Default

    Not a problem!
    ***Commandobill***
    Abusing AutoCad Since 1999
    "Caddatude... Do you has it?"
    Sorry for my poor English, I'm American...

  7. #7
    Quantum Mechanic Lee Mac's Avatar
    Computer Details
    Lee Mac's Computer Details
    Operating System:
    Windows 7 Ultimate (32-bit)
    Discipline
    Multi-disciplinary
    Lee Mac's Discipline Details
    Discipline
    Multi-disciplinary
    Details
    Custom Programming / Software Customisation
    Using
    AutoCAD 2013
    Join Date
    Aug 2008
    Location
    London, England
    Posts
    16,737

    Default

    Bill, just a tip, you don't need the:

    Code:
    (vl-remove-if 'listp ..
    When using

    Code:
    (ssget "_X")
    Lee Mac ProgrammingTwitterExchange App StoreDropbox (500MB free)

    With Mathematics there is the possibility of perfect rigour, so why settle for less?

  8. #8
    Senior Member Commandobill's Avatar
    Using
    AutoCAD 2008
    Join Date
    Oct 2008
    Location
    Massachusetts
    Posts
    317

    Default

    Quote Originally Posted by Lee Mac View Post
    Bill, just a tip, you don't need the:

    Code:
    (vl-remove-if 'listp ..
    When using

    Code:
    (ssget "_X")
    Yeah i know. I didnt know if he was going to select them or have it automated so i threw that in there for good measure. Thanks though
    ***Commandobill***
    Abusing AutoCad Since 1999
    "Caddatude... Do you has it?"
    Sorry for my poor English, I'm American...

  9. #9
    Senior Member
    Using
    AutoCAD 2009
    Join Date
    Jul 2009
    Posts
    264

    Default

    Hey, Lee... I tried to modify another lisp to increment text and mtext with a specific value... but I get the same error in this one and in the one I modified...

    when I select Mtext with text strings (not just numbers) the specified increment replaces the whole mtext, so I does not work as one would wish... to increment the numerical text with the specified value... would that be possible?

    Code:
    ;;http://www.autolisp.com/forum/showthread.php?t=347
    (defun c:sum ()
    (setq meu-ss(ssget '((0 . "TEXT,MTEXT"))))
      (setq value (getdist "\nValue to sum to numbers: "))
    ;
    (setq cntr 0)
    (while (< cntr (sslength meu-ss))
    ;
    (setq en(ssname meu-ss cntr))
    ;
    (setq enlist(entget en))
    (setq s-tex(cdr(assoc 1 enlist)))
    (setq n-tex(atof s-tex))
    (setq nf-tex (+ value n-tex))
    (setq nft-tex(rtos nf-tex 2 2))
    (setq enlist(subst (cons 1 nft-tex)(assoc 1 enlist) enlist))
    (entmod enlist)
    ;
    (setq cntr(+ cntr 1))
    ;
    )
    )
    and by the way... I have been taking small steps with selection sets.. but at this moment I can say I am only taking other existing codes to do a little more things with commands and selections.... I made something else today...

    I converted a routine to Insert points at center of each selected circles.. into a routine to insert a block at every selected circle... and then into a routine to select polylines, lwpolylines and circles and do wipeouts with them... .. no error handlers nor any of that stuff.. but It works.
    Code:
    ;BINCIRCLE.lsp 01/01/97 Jeff Foster
    ;
    ;OBJECTIVE***
    ;The purpose of this routine is to allow the user to enter
    ;a text item and place that same text in the center of a selection
    ;of circles
    ;
    ;TO RUN***
    ;At the command line, type (load "c:/lispdir/txtncirc")
    ;where c:/ is the drive where TXTNCIRC.lsp is contained
    ;where lispdir/ is the directory where TXTNCIRC.lsp is contained
    ;
    ;
    ;If you find this routine to be helpful, please give consideration
    ;to making a cash contribution of $10.00 to:
    ;         Jeff Foster
    (DEFUN C:BINCIRCLE (/ SS EN ED AS)
      (SETQ DM (GETVAR "DIMSCALE"))
      (PRINC "SELECT CIRCLES TO PUT TEXT INTO")
      (SETQ SS (SSGET))
      (WHILE (> (SSLENGTH SS) 0)
        (PROGN
        (SETQ EN (SSNAME SS 0))
        (SETQ ED (ENTGET EN))
        (SETQ AS (CDR (ASSOC '0 ED)))
        (SETQ START (CDR (ASSOC '10 ED)))
        (IF (= AS "CIRCLE")
        (COMMAND "INSERT" "COLUMN ROW BUBBLE" START DM DM "0" "")
        )
        (PRIN1)
        (SSDEL EN SS)
      ))
      (PRIN1)
    )
    Code:
    ;; C2W3.lsp BY Paulo Gil Soto - March 2010
    ;; draws a wipeout made of a polygon of 40 sides over each selected circle.
    ;; and will replace selected closed polylines and lwpolylines with a wipeout
    ;; Selected circles are deleted
    ;; Most of the code taken from  Jeff Foster --01/01/97
    ;;
    ;;
    (DEFUN C:C2W3 (/ SS EN ED AS)
    (COMMAND "undo" "begin")  ;beginning of undo group 
      (AND (SETQ ss (SSGET "_:L" '((0 . "CIRCLE,*POLYLINE"))))
           (FOREACH x (VL-REMOVE-IF 'LISTP (MAPCAR 'CADR (SSNAMEX ss)))
      (COND
        ((EQ "CIRCLE" (CDR (ASSOC 0 (SETQ elist (ENTGET x)))))
      (WHILE (> (SSLENGTH SS) 0) 
        (PROGN 
        (SETQ EN (SSNAME SS 0)) 
        (SETQ ED (ENTGET EN)) 
        (SETQ AS (CDR (ASSOC '0 ED))) 
        (SETQ START (CDR (ASSOC '10 ED))) 
        (SETQ RAD (CDR (ASSOC '40 ED))) 
        (IF (= AS "CIRCLE") 
        (COMMAND "POLYGON" "40" START "I" RAD "WIPEOUT" "P" "L" "Y" "ERASE" EN "") 
        ) 
        (IF (= AS "LWPOLYLINE") 
        (COMMAND "WIPEOUT" "P" EN "Y") 
        ) 
        (IF (= AS "POLYLINE") 
        (COMMAND "WIPEOUT" "P" EN "Y") 
        ) 
        (PRIN1) 
        (SSDEL EN SS) 
      )) 
              (ENTMOD elist)
        )
         
        (T T)
      ) ;_ cond
           ) ;_ foreach
      ) ;_ and
    
      (COMMAND "undo" "end")  ;end of undo group
    
    ) ;_ defun
     
    ;|«Visual LISP© Format Options»
    (80 2 40 2 nil "end of " 60 9 2 0 0 T T T T)
    ;*** DO NOT add text below the comment! ***|;

  10. #10
    Senior Member
    Using
    Map 3D 2008
    Join Date
    Sep 2009
    Posts
    114

    Default add number to an attribute

    Registered forum members do not see this ad.

    Hello everybody,
    If i have a block with an attribute, ... B1, is it possible to add a number to this attribute, to be B2? Thanks!

Similar Threads

  1. Adding number to a text string
    By Storm2002 in forum AutoLISP, Visual LISP & DCL
    Replies: 13
    Last Post: 4th May 2009, 04:20 am
  2. adding multiple text boxes to a form
    By comcu in forum AutoLISP, Visual LISP & DCL
    Replies: 2
    Last Post: 30th Aug 2008, 04:07 pm
  3. Adding entities to a DB Action.
    By GE13579 in forum AutoCAD Drawing Management & Output
    Replies: 1
    Last Post: 2nd Jun 2008, 12:16 pm
  4. Divided a text number for a text number
    By HelloWorld in forum AutoLISP, Visual LISP & DCL
    Replies: 12
    Last Post: 17th Apr 2008, 02:48 am
  5. adding text string to multiple lines at once?
    By Lucid in forum AutoCAD Drawing Management & Output
    Replies: 3
    Last Post: 18th Oct 2007, 07:31 pm

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts