Jump to content

Manipulating with text numbers


Recommended Posts

Posted

Hi,

I'm wondering if there's a lisp that could increment numbers in selected text.

For example :

 

1/1,1/2,1/3...to 1/2,1/3,1/4...

 

So, program should select text and then increment or decrement prefix or sufix.

Any help is appreciated.

Posted

Just a solution take the text read each character till you find the "/" then read the rest use rtos to make back into a number add 1 the convert to a string and add start start string. As a start search for a lisp "find character" the most common is for CSV.

Posted

Thank's for replies.

@ Lee Mac

Text increment selects one element at a time. That takes time if you have numbers from one to a hundred or so.

Is there a way to select al of the elements at once ?

Posted (edited)
kratki spoj said:
Text increment selects one element at a time. That takes time if you have numbers from one to a hundred or so.

Is there a way to select al of the elements at once ?

 

Try this quick mod:

;; Text Increment  -  Lee Mac
;; Increments numerical data found in a selection of Text or MText
;; objects by a value specified by the user.

(defun c:txtinc ( / e i l s x )
   (if (null *inc*)
       (setq *inc* 1.0)
   )
   (if (setq i (getreal (strcat "\nSpecify Increment <" (rtos *inc* 2) ">: ")))
       (setq *inc* i)
   )
   (if (equal 0.0 (rem *inc* 1) 1e-8)
       (setq *inc* (fix *inc*))
   )
   (if (setq s (ssget "_:L" '((0 . "TEXT,MTEXT") (1 . "*#*"))))
       (repeat (setq i (sslength s))
           (setq e (entget (ssname s (setq i (1- i))))
                 x (assoc 1 e)
           )
           (entmod
               (subst
                   (cons 1
                       (apply 'strcat
                           (mapcar
                               (function
                                   (lambda ( x )
                                       (if (and (= 'int (type x)) (= 'int (type *inc*)))
                                           (itoa (+ x *inc*))
                                           (if (member (type x) '(int real))
                                               (rtos (+ x *inc*) 2)
                                               x
                                           )
                                       )
                                   )
                               )
                               (LM:splitstring (cdr x))
                           )
                       )
                   )
                   x e
               )
           )
       )
   )
   (princ)
)            

;; Split String  -  Lee Mac
;; Splits a string into a list of text and numbers

(defun LM:splitstring ( s )
   (
       (lambda ( l )
           (read
               (strcat "("
                   (vl-list->string
                       (apply 'append
                           (mapcar
                               (function
                                   (lambda ( a b c )
                                       (cond
                                           (   (= 92 b)
                                               (list 32 34 92 b 34 32)
                                           )
                                           (   (or (< 47 b 58)
                                                   (and (= 45 b) (< 47 c 58) (not (< 47 a 58)))
                                                   (and (= 46 b) (< 47 a 58) (< 47 c 58))
                                               )
                                               (list b)
                                           )
                                           (   (list 32 34 b 34 32))
                                       )
                                   )
                               )
                               (cons nil l) l (append (cdr l) (list nil))
                           )
                       )
                   )
                   ")"
               )
           )
       )
       (vl-string->list s)
   )
)

(princ)
 
Edited by Lee Mac
Posted

Thank's Lee. That's what I was looking for.

:thumbsup:

Posted

Not sure if it may contribute to solution or not. Following trick is highly dependant to your case:

 

I usually delete all text entities which I need to increment the numercial part of them. Copy a single pattern to proper location and then leverage the 'Find&Replace' option of AutoNumber (ExpressTools).

 

357fyno.jpg

 

In above scenario, you just need to copy '1/x' to all desired place. In find&replace, type 'x'.

 

As I said, it might not be always feasible to everyone but I use it a lot.

 

Hi,

I'm wondering if there's a lisp that could increment numbers in selected text.

For example :

 

1/1,1/2,1/3...to 1/2,1/3,1/4...

 

So, program should select text and then increment or decrement prefix or sufix.

Any help is appreciated.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...