Do you have a block with attributes for each bench in your drawing?
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


Do you have a block with attributes for each bench in your drawing?
Hi there,
Unfortunately not, its all single line mtext.


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.
Hopefully someone else is a little more helpful.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)) (while (<= 0 whatlength) (setq textvalue (cdr(assoc 1 (entget(ssname what whatlength))))) (setq number (atof textvalue)) (setq number (+ number adding)) ;write the value back to the object (setq whatlength (1- whatlength)) ) (princ "all done") (princ) )
Thalon
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