Jump to content

CHANGE FORMAT NUMBER TEXT/MTEXT


uzumaki narudin

Recommended Posts

Dear Senior, 

 

Is there any lisp of function to bulk change by select manny text that contain only number and reformat it using the spesific format in picture below ?

 

thanks for any help would be apreciated.

FORMATING NUMBER AUTOCAD.png

Link to comment
Share on other sites

The part two X,Y can best be done using a csv to list approach so change the values seperately than join back same with say X,Y,Z

 

The part 1 may exist already, its a case of just reading the string say backwards in lots of 3, I dont have anything, have a couple of others to do 1st.

Link to comment
Share on other sites

Try this

 

; break strings into sets of 3 characters seperated by comma
;By AlanH DEC 2021


; thanks to Lee-mac for this defun 
; www.lee-mac.com
; 44 is comma 32 is space
(defun _csv->lst ( str / pos )
	(if (setq pos (vl-string-position 44 str))
		(cons (substr str 1 pos) (_csv->lst (substr str (+ pos 2))))
		(list str)
    )
)

(defun c:commastr ( / ss x obj txt lst val str str2 len)
(setq ss (ssget (list (cons 0 "TEXT,MTEXT"))))

(if (= ss nil)
  (progn (alert "NO text found\n\n\n Will now exit")(EXIT))

(repeat (setq x (sslength ss))
  (setq lst '())
  (setq obj (vlax-ename->vla-object (ssname ss (setq x (- x 1)))))
  (setq txt (vla-get-textstring obj))
  (setq lst (cons (_csv->lst txt) lst))
  (setq str "")
    (foreach val lst
    (setq val2 (car val))
    (setq len (strlen val2))
    (setq str (substr val2 (- len 2) 3))
    (setq len (- len 3))
      (while (> len 3)
      (setq str2 (substr val2 (- len 2) 3))
      (setq str (strcat str2 "," str))
      (setq len (- len 3))
      )
    )
      (if (> len 0)
        (progn
          (setq str2 (substr val2 1 len))
          (setq str (strcat str2 "," str))
      )
      )
  (vla-put-textstring obj str)
)
)

(princ)
)

(C:commastr)

 

Edited by BIGAL
  • Like 1
Link to comment
Share on other sites

8 hours ago, BIGAL said:

Try this

 



; break strings into sets of 3 characters seperated by comma
;By AlanH DEC 2021


; thanks to Lee-mac for this defun 
; www.lee-mac.com
; 44 is comma 32 is space
(defun _csv->lst ( str / pos )
	(if (setq pos (vl-string-position 44 str))
		(cons (substr str 1 pos) (_csv->lst (substr str (+ pos 2))))
		(list str)
    )
)

(defun c:commastr ( / ss x obj txt lst val str str2 len)
(setq ss (ssget (list (cons 0 "TEXT,MTEXT"))))

(if (= ss nil)
  (progn (alert "NO text found\n\n\n Will now exit")(EXIT))

(repeat (setq x (sslength ss))
  (setq lst '())
  (setq obj (vlax-ename->vla-object (ssname ss (setq x (- x 1)))))
  (setq txt (vla-get-textstring obj))
  (setq lst (cons (_csv->lst txt) lst))
  (setq str "")
    (foreach val lst
    (setq val2 (car val))
    (setq len (strlen val2))
    (setq str (substr val2 (- len 2) 3))
    (setq len (- len 3))
      (while (> len 3)
      (setq str2 (substr val2 (- len 2) 3))
      (setq str (strcat str2 "," str))
      (setq len (- len 3))
      )
    )
      (if (> len 0)
        (progn
          (setq str2 (substr val2 1 len))
          (setq str (strcat str2 "," str))
      )
  )

  (vla-put-textstring obj str)
)

(princ)
)

(C:commastr)

 

Thank for reply BIGAL, but this give me error code while appload lisp

malformed list on input :error#2 

 

what did i missing ?
 

Edited by uzumaki narudin
Link to comment
Share on other sites

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...