Tunnelrat Posted June 30, 2011 Share Posted June 30, 2011 Hi, I have seen lisp to add letter(s) to a text but I could not find a lisp that remove the last letter(s) by windows or crossing them . Would you please help me find one if it already posted or perhaps write one for me. Thank you much. Quote Link to comment Share on other sites More sharing options...
BlackBox Posted June 30, 2011 Share Posted June 30, 2011 Here's a simple example to get you started: (defun c:FOO ( / ss) (if (setq ss (ssget "_:L" '((0 . "TEXT")))) ((lambda (i / e ed s) (while (setq e (ssname ss (setq i (1+ i)))) (setq ed (entget e)) (setq s (assoc 1 ed)) (setq ed (subst (cons 1 (substr (cdr s) 1 (1- (strlen (cdr s))))) s ed)) (entmod ed))) -1) (prompt "\n** Nothing selected ** ")) (princ)) This code can be made more efficient, but I've left the multiple setq's so you can understand what the code is doing at each step. Quote Link to comment Share on other sites More sharing options...
Tunnelrat Posted June 30, 2011 Author Share Posted June 30, 2011 That is beautiful. Thank you RenderMan Quote Link to comment Share on other sites More sharing options...
Tharwat Posted June 30, 2011 Share Posted June 30, 2011 the function *vl-string-right-trim* could also help you with it . e.g. (vl-string-right-trim "456" "123456") Tharwat Quote Link to comment Share on other sites More sharing options...
BlackBox Posted June 30, 2011 Share Posted June 30, 2011 That is beautiful.Thank you RenderMan You're very welcome. Quote Link to comment Share on other sites More sharing options...
BlackBox Posted June 30, 2011 Share Posted June 30, 2011 (edited) the function *vl-string-right-trim* could also help you with it . e.g. (vl-string-right-trim "456" "123456") So could "vl-string-subst" :wink: ( (defun c:FOO ( / *error* oldNomutt ss oDoc s) (vl-load-com) (princ "\rFOO ") (defun *error* (msg) (and oldNomutt (setvar 'nomutt oldNomutt)) (if oDoc (vla-endundomark oDoc)) (cond ((not msg)) ; Normal exit ((member msg '("Function cancelled" "quit / exit abort"))) ; <esc> or (quit) ((princ (strcat "\n** Error: " msg " ** ")))) ; Fatal error, display it (princ)) (prompt "\nSelect text objects to remove last character: ") (and (setq oldNomutt (getvar 'nomutt)) (setvar 'nomutt 1)) (if (setq ss (ssget "_:L" '((0 . "TEXT")))) (progn (vla-startundomark (setq oDoc (vla-get-activedocument (vlax-get-acad-object)))) (vlax-for x (setq ss (vla-get-activeselectionset oDoc)) (setq s (vla-get-textstring x)) [color=green];|[/color] [color=green] (vla-put-textstring[/color] [color=green] x[/color] [color=green] (vl-string-subst[/color] [color=green] ""[/color] [color=green] (substr s (strlen s) 1)[/color] [color=green] s)))[/color] [color=green] |;[/color] [color=blue](vla-put-textstring x (substr s 1 (1- (strlen s)))))[/color] (vla-endundomark oDoc) (vla-delete ss) (setvar 'nomutt oldNomutt)) (progn (setvar 'nomutt oldNomutt) (prompt "\n** Nothing selected ** "))) (princ)) Edited June 30, 2011 by BlackBox Code revised Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted June 30, 2011 Share Posted June 30, 2011 Renderman, I think you mean: (vl-string-subst "" (substr s (strlen s)) s) But beware using this method... (setq s "Renderman") (vl-string-subst "" (substr s (strlen s)) s) vl-string-right-trim would also be unpredictable if you only wanted to remove a specific number of characters. I would use substr, as you have in the first post. Quote Link to comment Share on other sites More sharing options...
BlackBox Posted June 30, 2011 Share Posted June 30, 2011 Renderman, I think you mean: (vl-string-subst "" (substr s (strlen s)) s) But beware using this method... (setq s "Renderman") (vl-string-subst "" (substr s (strlen s)) s) vl-string-right-trim would also be unpredictable if you only wanted to remove a specific number of characters. I would use substr, as you have in the first post. Good catch, Lee. Code revised. Quote Link to comment Share on other sites More sharing options...
Tharwat Posted June 30, 2011 Share Posted June 30, 2011 Subst and entmod with Annotative text would cause Cad to screw up . Nice routine Renderman , and why do not you include the Mtext also to the routine .! Regards, Tharwat Quote Link to comment Share on other sites More sharing options...
BlackBox Posted June 30, 2011 Share Posted June 30, 2011 Subst and entmod with Annotative text would cause Cad to screw up . I do not know anyone professionally (i.e., a firm I work with, etc.), that uses annotative objects. Nice routine Renderman , and why do not you include the Mtext also to the routine .! Thanks. As for MText, technically, you could add it to the selection set filter given that the point is to trim the last single character. However, and this may just be how I work, but I put different types of data in Text as oposed to MText. I would never have a practical purpose (or at least cannot think of any) where I need to remove the last character of an MText's TextString: ; TextString = "{\\C1;This\\P\\C2;is\\P\\C4;a\\P\\C6;test}" To each their own. Quote Link to comment Share on other sites More sharing options...
Tharwat Posted June 30, 2011 Share Posted June 30, 2011 I do not know anyone professionally (i.e., a firm I work with, etc.), that uses annotative objects. Agree completely . As for MText, technically, you could add it to the selection set filter given that the point is to trim the last single character. However, and this may just be how I work, but I put different types of data in Text as oposed to MText. I would never have a practical purpose (or at least cannot think of any) where I need to remove the last character of an MText's TextString: ; TextString = "{\\C1;This\\P\\C2;is\\P\\C4;a\\P\\C6;test}" To each their own. I did add the MTEXT to the Selection Set and tried it with formatting Mtext , at the first time it does not remove the last character unless you repeat it two times . Regards. Tharwat Quote Link to comment Share on other sites More sharing options...
BlackBox Posted June 30, 2011 Share Posted June 30, 2011 I did add the MTEXT to the Selection Set and tried it with formatting Mtext , at the first time it does not remove the last character unless you repeat it two times . Incorrect; (and this is why I provided an example) the routine *did* remove the last character on the first pass, then removed the resultant's last characte on the second pass. :wink: [color=silver]; TextString = "{\\C1;This\\P\\C2;is\\P\\C4;a\\P\\C6;tes[/color][color=blue]t[/color][color=red]}[/color]" Quote Link to comment Share on other sites More sharing options...
Tharwat Posted June 30, 2011 Share Posted June 30, 2011 Incorrect; (and this is why I provided an example) the routine *did* remove the last character on the first pass, then removed the resultant's last characte on the second pass. :wink: [color=silver]; TextString = "{\\C1;This\\P\\C2;is\\P\\C4;a\\P\\C6;tes[/color][color=blue]t[/color][color=red]}[/color]" Cooooooooool Man Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted June 30, 2011 Share Posted June 30, 2011 Incorrect; (and this is why I provided an example) the routine *did* remove the last character on the first pass, then removed the resultant's last characte on the second pass. :wink: [color=silver]; TextString = "{\\C1;This\\P\\C2;is\\P\\C4;a\\P\\C6;tes[/color][color=blue]t[/color][color=red]}[/color]" i.e. the routine screwed up the formatting codes... For this to work with MText with formatting you would have to temporarily substitute/remove the formatting codes, operate on the string, then replace the formatting codes in the right places. I had similar issues to deal with when writing my BFind program - 2000 lines of code later and it still has bugs. Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted June 30, 2011 Share Posted June 30, 2011 Cooooooooool Man Huh? Quote Link to comment Share on other sites More sharing options...
BlackBox Posted June 30, 2011 Share Posted June 30, 2011 i.e. the routine screwed up the formatting codes... For this to work with MText with formatting you would have to temporarily substitute/remove the formatting codes, operate on the string, then replace the formatting codes in the right places. I had similar issues to deal with when writing my BFind program - 2000 lines of code later and it still has bugs. Which is why I left MText out of the original filter; I'm just saying. LoL Quote Link to comment Share on other sites More sharing options...
BlackBox Posted June 30, 2011 Share Posted June 30, 2011 Huh? 1+........ Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted June 30, 2011 Share Posted June 30, 2011 Which is why I left MText out of the original filter; I'm just saying. LoL Oh exactly, I don't blame you, I would too Quote Link to comment Share on other sites More sharing options...
BlackBox Posted June 30, 2011 Share Posted June 30, 2011 (edited) Oh exactly, I don't blame you, I would too No worries - I didn't think you were suggesting otherwise. I was responding openly to the thread in response to your post, more so than directly responding to it (if that makes sense?). In any event, we're good, bro. Edited June 30, 2011 by BlackBox I always catch the typos AFTER I hit the button! Quote Link to comment Share on other sites More sharing options...
Tharwat Posted June 30, 2011 Share Posted June 30, 2011 1+........ I did mean that it is new to me to know that the mtext would behave that way when it is being formatted . Thanks for the clarification . 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.