asos2000 Posted May 20, 2012 Posted May 20, 2012 I have a text in drawing and want to delete a part of a it This is the text xxxx #xxxx I want to detect # then delete and all letters after To be like this xxxx How is this? Thanks Quote
Tharwat Posted May 20, 2012 Posted May 20, 2012 Use functions substr and entmod before subst 'ing the string ( if that is not annotative text ) Quote
Tharwat Posted May 20, 2012 Posted May 20, 2012 You may need a complete code (defun c:Test (/ ss) ;;; Tharwat 20. May . 2012 ;;; (if (setq ss (ssget "_:L" '((0 . "TEXT,MTEXT")))) ((lambda (inc / sn p ent) (while (setq sn (ssname ss (setq inc (1+ inc)))) (if (setq p (vl-position (ascii "#") (vl-string->list (cdr (assoc 1 (setq ent (entget sn)))) ) ) ) (entmod (subst (cons 1 (substr (cdr (assoc 1 (entget sn))) 1 p)) (assoc 1 ent) ent ) ) ) ) ) -1 ) ) (princ) ) Quote
pBe Posted May 20, 2012 Posted May 20, 2012 another (defun RemChar (ch / ss p str e) (cond ((and (setq ss (ssget "_:L" '((0 . "TEXT,MTEXT")))) (repeat (sslength ss) (if (setq p (vl-string-position (ascii ch) (setq str (cdr (assoc 1 (entget (setq e (ssname ss 0)))))))) (vla-put-textstring (vlax-ename->vla-object e) (substr str 1 p) )) (ssdel e ss)) ) ) ) (princ)) Tharwat, why convert the string to list? Quote
Tharwat Posted May 20, 2012 Posted May 20, 2012 Tharwat, why convert the string to list? Because the function vl-position needs a list while the ascii "#" would return a numerical value , so both are numbers now . Quote
pBe Posted May 20, 2012 Posted May 20, 2012 Because the function vl-position needs a list while the ascii "#" would return a numerical value , so both are numbers now . [b]vl-string-position [/b]Looks for a character with the specified [b]ASCII [/b]code in a [b]string[/b] No need to convert the string to a list my friend. Quote
Tharwat Posted May 20, 2012 Posted May 20, 2012 [b]vl-string-position [/b]Looks for a character with the specified [b]ASCII [/b]code in a [b]string[/b] No need to convert the string to a list my friend. That's correct if I am using vl-string-position but I am using vl-position Quote
pBe Posted May 20, 2012 Posted May 20, 2012 Instead of vl-position use vl-string-position, same result without the overhead of converting the string just saying..... Quote
Tharwat Posted May 20, 2012 Posted May 20, 2012 Instead of vl-position use vl-string-position, same result without the overhead of converting the string just saying..... Ok , certainly I will do Quote
asos2000 Posted May 20, 2012 Author Posted May 20, 2012 another... Gives this error ; error: bad argument type: stringp nil Quote
pBe Posted May 20, 2012 Posted May 20, 2012 on your example string (remchar "#") The code requires a TEXT/MTEXT selection. now if you want to use the fucntion for a string (setq Remstr (lambda (str ch / p str) (if (setq p (vl-string-position (ascii ch) str)) (substr str 1 p) ) ) ) ( Remstr "xxx#xxxx" "#") HTH Quote
asos2000 Posted May 20, 2012 Author Posted May 20, 2012 on your example string (remchar "#") That was the trick (remchar #) This is the mistake what I did Thanks 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.