+ Reply to Thread
Results 1 to 5 of 5
  1. #1
    Junior Member
    Computer Details
    philk's Computer Details
    Operating System:
    Window 7 Enterprise
    RAM:
    6gb
    Using
    AutoCAD LT 2006
    Join Date
    Feb 2006
    Location
    Leicester, England
    Posts
    12

    Default adding numbers to numbers

    Registered forum members do not see this ad.

    Hi there,

    Can anyone help me. I have roughly a thousand datum levels which all need to be increased by the same number as the bench mark has changed. Does anyone know of a lisp routine that can carry out this.
    All help is very much appreciated.

    Cheers

    Phil k

  2. #2
    Senior Member
    Using
    AutoCAD 2008
    Join Date
    Nov 2005
    Location
    Bulgaria, Sofia
    Posts
    228

    Default

    Do you have a block with attributes for each bench in your drawing?

  3. #3
    Junior Member
    Computer Details
    philk's Computer Details
    Operating System:
    Window 7 Enterprise
    RAM:
    6gb
    Using
    AutoCAD LT 2006
    Join Date
    Feb 2006
    Location
    Leicester, England
    Posts
    12

    Default

    Hi there,

    Unfortunately not, its all single line mtext.

  4. #4
    Senior Member
    Using
    AutoCAD 2005
    Join Date
    Dec 2005
    Location
    Brandon, Manitoba, Canada
    Posts
    166

    Default

    I can get the text entiy and read it value and add some number to it, but I'm not sure how to write a value back to the object.

    Code:
    ;Written by: Kevin Petursson
    ; February 23, 2006
    (defun c:addto (/ what where scale blockname tryagain insertpoint whatlength ll ur)
        (setq what nil)
        (print "Select text...")
        ;set the ammount to add to the base number
        (setq adding 15)
        (setq what (ssget))
        ;get name of the block
        (setq whatlength (sslength what))
        (setq whatlength (1- whatlength))
        &#40;while &#40;<= 0 whatlength&#41;
          &#40;setq textvalue &#40;cdr&#40;assoc 1 &#40;entget&#40;ssname what whatlength&#41;&#41;&#41;&#41;&#41;
          &#40;setq number &#40;atof textvalue&#41;&#41;
          &#40;setq number &#40;+ number adding&#41;&#41;
          ;write the value back to the object
          
          &#40;setq whatlength &#40;1- whatlength&#41;&#41;
        &#41;
      
      &#40;princ "all done"&#41;
      &#40;princ&#41;
    &#41;
    Hopefully someone else is a little more helpful.
    Thalon

  5. #5
    Junior Member
    Computer Details
    philk's Computer Details
    Operating System:
    Window 7 Enterprise
    RAM:
    6gb
    Using
    AutoCAD LT 2006
    Join Date
    Feb 2006
    Location
    Leicester, England
    Posts
    12

    Default Eureka

    Registered forum members do not see this ad.

    This guy deserves a Nobel prize!

    It works a treat.

    Thanks for reading and helping.

    Philk

    ; ************************* DP2.LSP *****************************
    ; Program to select required text (on a layer called LEVELS only)
    ; and change the numerical part of each text item by adding or
    ; subtracting a user-entered value. 20 May 1998
    ; Version 3 Modified to convert negative number values
    ; Written by Colin Browning
    ; ================================================== =============
    (Defun *ERROR* (MSG)
    (Princ "Error: ")
    (Princ MSG)
    (Princ)
    )

    ; *** SUB-ROUTINE TO UPDATE NUMBER VALUE:-
    (Defun Processit ()
    (Setq NUM1 nil)
    (Setq TLa (Strlen T2a)) ;calc string length
    (Setq KNT 1)
    (Setq PRE "") ;initialise prefix store as an empty string
    (Repeat TLa
    (Setq C1 (Substr T2a KNT 1)) ;check each char
    (Setq C2 (Ascii C1)) ;get ascii value
    (If (Or (< C2 45)(> C2 57)(= C2 46)(= C2 47));if not a number
    (Progn ;char or a minus sign then...
    (Setq PRE (Strcat PRE C1)) ;build prefix string
    (Setq KNT (1+ KNT))
    ) ;end of Progn
    (Setq NUM1 (Substr T2a KNT)) ;else get remaining number
    ) ;end of IF
    ) ;end of Repeat
    (If NUM1 ;check if number element exists
    (Progn
    (Setq TLb (Strlen NUM1)) ;calc no. of chars in number string
    (Setq NUM2 (Atof NUM1)) ;convert string number to a real
    (Setq TLc (Strlen (Itoa (Fix NUM2))));calc no. of chars in integer part
    (If (= TLb TLc) ;calc no. dec places
    (Setq TLd 0)
    (Setq TLd (- TLb TLc 1))
    ) ;end of 1st IF
    (Setq NUM3 (+ NUM2 V2)) ;update number value as a real
    (Setq NUM4 (Rtos NUM3 2 TLd)) ;convert back to string
    (Setq T2b (Strcat PRE NUM4)) ;add back prefix code if any
    ) ;end of Progn
    (Setq T2b PRE) ;Else re-use prefix if no no. element
    ) ;end of outer IF
    (Princ)
    )

    ; *** MAIN FUNCTION:-
    (Defun CP2 ()
    (Graphscr)
    (Initget "Global Manual")
    (Setq S1 (Getkword "\nSelect text Globally or Manually (G/M) <Globally>: "))
    (If (Null S1)(Setq S1 "Global"))
    (If (= S1 "Global")
    (Setq S2 (Ssget "X" (List '(0 . "TEXT")'(8 . "LEVELS"))))
    )
    (If (= S1 "Manual")
    (Setq S2 (Ssget (List '(0 . "TEXT")'(8 . "LEVELS"))))
    )
    (If S2 ;if valid selection...
    (Progn ;then do this...
    (Initget 1)
    (Setq V2 (Getreal "\nEnter value to change levels by: "))
    (Setq L2 (Sslength S2)) ;calcs how many items selected
    (Setq CNT 0) ;initialise counter
    (Repeat L2 ;loop thru each
    (Setq N2 (Ssname S2 CNT)) ;gets entity name
    (Setq A2 (Entget N2)) ;gets assoc data listing
    (Setq T2 (Assoc 1 A2)) ;extracts text sub-list
    (Setq T2a (Cdr T2)) ;extracts actual text item
    (Processit) ;sub-routine to change text values
    (Setq A3 (Subst (Cons 1 T2b) T2 A2)) ;subst modified text value
    (Entmod A3) ;update drawing
    (Setq CNT (1+ CNT)) ;increment counter
    ) ;end of Repeat loop
    ) ;end of Progn
    (Prompt "\nNo valid selection. Try again!");Else option if no selection
    ) ;end of IF function
    (Princ) ;exit cleanly
    )
    

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