Sweety Posted November 11, 2010 Share Posted November 11, 2010 Hello. Hope that someone would tell me how to remove the space from the selected text or mtext . (setq e (car (entsel "\n Select Text :"))) (setq ent (entget e)) (entmod (subst (cons 1 ....... Not specifically the contents are known . Thanks GUYS. Quote Link to comment Share on other sites More sharing options...
BlackBox Posted November 11, 2010 Share Posted November 11, 2010 Remove the space, or replace it with something else? Edit: I guess removing is the same as replacing with an empty string "", huh. Quote Link to comment Share on other sites More sharing options...
Sweety Posted November 11, 2010 Author Share Posted November 11, 2010 No. just remove the space from the selected word from the selected text . Thanks Quote Link to comment Share on other sites More sharing options...
BlackBox Posted November 11, 2010 Share Posted November 11, 2010 (edited) (defun c:FOO (/ ss) (vl-load-com) (vla-startundomark (cond (*activeDoc*) ((setq *activeDoc* (vla-get-activedocument (vlax-get-acad-object)))))) (if (setq ss (ssget '((0 . "TEXT,MTEXT")))) ((lambda (i / e v s) (while (setq e (ssname ss (setq i (1+ i)))) (setq s (vla-get-textstring (setq v (vlax-ename->vla-object e)))) (while (vl-string-search " " s) (setq s (vl-string-subst "" " " s))) (vla-put-textstring v s))) -1)) (vla-endundomark *activeDoc*) (princ)) Edited November 11, 2010 by BlackBox Code re-posted Quote Link to comment Share on other sites More sharing options...
alanjt Posted November 11, 2010 Share Posted November 11, 2010 (defun noSpaces (str) (if (eq (type str) 'STR) (vl-list->string (vl-remove 32 (vl-string->list str))) ) ) Quote Link to comment Share on other sites More sharing options...
alanjt Posted November 11, 2010 Share Posted November 11, 2010 FYI Mat, if you are going to edit entities as vla-objects, it's faster to use vla-get-activeselectionset than to step through the selectionset and convert to vla-objects. Quote Link to comment Share on other sites More sharing options...
BlackBox Posted November 11, 2010 Share Posted November 11, 2010 FYI Mat, if you are going to edit entities as vla-objects, it's faster to use vla-get-activeselectionset than to step through the selectionset and convert to vla-objects. Dually noted. Quote Link to comment Share on other sites More sharing options...
Sweety Posted November 11, 2010 Author Share Posted November 11, 2010 Thank a lot gentlemen . Renderman your routine works great . Alanjt Please take a look (defun noSpaces (str) (if (eq (type str) 'STR) (vl-list->string (vl-remove 32 (vl-string->list str))) ) ) (setq e (car (entsel "\n Select Text :"))) (setq ent (entget e)) (setq tt (cdr (assoc 1 ent))) (noSpaces tt) in the Visual Visp console I see the changes but that does not affect at the selected text. What's wrong in the previous codes. many thanks Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted November 11, 2010 Share Posted November 11, 2010 (edited) You will need to update the entity with the textstring returned by Alan's function. I wanted to challenge myself to avoid the use of VL: [ Scroll down after you have got something working on your own ] (defun c:nospace ( / nospace ss ) (defun nospace ( s ) ( (lambda ( o ) (repeat (strlen s) (if (/= 32 (ascii s)) (setq o (strcat o (substr s 1 1))) ) (setq s (substr s 2)) ) o ) "" ) ) (if (setq ss (ssget "_:L" '((0 . "TEXT,MTEXT")))) ( (lambda ( i / e ) (while (setq e (ssname ss (setq i (1+ i)))) (entupd (cdr (assoc -1 (entmod (subst (cons 1 (nospace (cdr (assoc 1 (entget e)) ) ) ) (assoc 1 (entget e)) (entget e) ) ) ) ) ) ) ) -1 ) ) (princ) ) Edited November 11, 2010 by Lee Mac Quote Link to comment Share on other sites More sharing options...
alanjt Posted November 11, 2010 Share Posted November 11, 2010 If you didn't realize that it would only edit the string and not the object, then you need to learn the basics of editing objects before you go any farther. Quote Link to comment Share on other sites More sharing options...
Sweety Posted November 11, 2010 Author Share Posted November 11, 2010 Wow Lee Thank you . I really wanted to see it in Vanilla . your way of looping the codes make me crazy . Although with entupd function it's not replacing the text (defun noSpaces (str) (if (eq (type str) 'STR) (vl-list->string (vl-remove 32 (vl-string->list str))) ) ) (setq e (car (entsel "\n Select Text :"))) (setq ent (entget e)) (setq tt (cdr (assoc 1 ent))) (noSpaces tt) (entupd ent) Quote Link to comment Share on other sites More sharing options...
alanjt Posted November 11, 2010 Share Posted November 11, 2010 Vanilla and recursive. (defun noSpaces (str / v) (if (eq str "") "" (if (eq (setq v (substr str 1 1)) " ") (noSpaces (substr str 2)) (strcat v (noSpaces (substr str 2))) ) ) ) Quote Link to comment Share on other sites More sharing options...
Sweety Posted November 11, 2010 Author Share Posted November 11, 2010 YES , I am sorry now it works OKI. (defun noSpaces (str) (if (eq (type str) 'STR) (vl-list->string (vl-remove 32 (vl-string->list str))) ) ) (setq e (car (entsel "\n Select Text :"))) (setq ent (entget e)) (setq tt (cdr (assoc 1 ent))) (entupd (cdr (assoc -1 (entmod (subst (cons 1 (noSpaces tt))(assoc 1 ent) ent))))) Many thanks Alanjt I am sorry again for misunderstanding. Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted November 11, 2010 Share Posted November 11, 2010 Wow Lee Thank you . I really wanted to see it in Vanilla . your way of looping the codes make me crazy . You're welcome, glad you got there in the end Quote Link to comment Share on other sites More sharing options...
Sweety Posted November 11, 2010 Author Share Posted November 11, 2010 You're welcome, glad you got there in the end Yeah ... I am so embarrassing with my mistake with (entupd and entmod) they shown me as a stupid . Thanks a lot Lee Quote Link to comment Share on other sites More sharing options...
alanjt Posted November 11, 2010 Share Posted November 11, 2010 Yeah ... I am so embarrassing with my mistake with (entupd and entmod) they shown me as a stupid . Thanks a lot Lee A person is only as stupid as they allow themselves to be. Quote Link to comment Share on other sites More sharing options...
Sweety Posted November 11, 2010 Author Share Posted November 11, 2010 A person is only as stupid as they allow themselves to be. Not completely , because the lack of informations is not a kind of allowing others to call me that way . Maybe in some situations but not all. Quote Link to comment Share on other sites More sharing options...
alanjt Posted November 11, 2010 Share Posted November 11, 2010 Not completely , because the lack of informations is not a kind of allowing others to call me that way . Maybe in some situations but not all. Well, you were the only one that called yourself stupid.Also, you just grabbed and used a bit of code provided without studying it first - you would have realized that it only altered the string and did nothing to an object. Any limitations you incurred were of your own accord. I gave you the means to remove the spaces, if you are attempting you edit strings, you should already have a working knowledge of editing objects and not rely on me or anyone else for that. Quote Link to comment Share on other sites More sharing options...
alanjt Posted November 11, 2010 Share Posted November 11, 2010 BTW, I really like the repeat from the string length idea, Lee. However, why'd you worry with converting the string to an ascii character when (eq s " ") would have sufficed? Quote Link to comment Share on other sites More sharing options...
Lt Dan's legs Posted November 11, 2010 Share Posted November 11, 2010 A person is only as stupid as they allow themselves to be. Are you saying stupid is as stupid does? Quote Link to comment Share on other sites More sharing options...
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.