uzumaki narudin Posted December 22, 2021 Posted December 22, 2021 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. Quote
BIGAL Posted December 22, 2021 Posted December 22, 2021 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. Quote
BIGAL Posted December 23, 2021 Posted December 23, 2021 (edited) 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 December 23, 2021 by BIGAL 1 Quote
uzumaki narudin Posted December 23, 2021 Author Posted December 23, 2021 (edited) 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 December 23, 2021 by uzumaki narudin Quote
BIGAL Posted December 23, 2021 Posted December 23, 2021 (edited) Do apologise dropped a bracket somehow code updated. If still not working post a dwg to test. Edited December 23, 2021 by BIGAL Quote
Recommended Posts
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.