Michaels Posted November 13, 2010 Share Posted November 13, 2010 Wow wow wow . Here what I got when I tested your routine with the Vlide and got the indication number 32 to the free space in the tested Text String . (100 103 102 100 103 102 100 103 32 32 32 32 32 32 32 32 32 103 100 102 103 32 32 32 32 32 32 32 32 32 32 32 32 32 119 101 114 116 121) Wonderful test of vl-string->list function . Thanks for giving me the chance to do it myself. Thanks and greatly appreciated Lee Michaels Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted November 13, 2010 Share Posted November 13, 2010 You're welcome Michaels, but do you understand exactly the numbers that are returned - i.e. how they relate to the characters? Quote Link to comment Share on other sites More sharing options...
Michaels Posted November 13, 2010 Share Posted November 13, 2010 but do you understand exactly the numbers that are returned - i.e. how they relate to the characters? I can say yes , Chech these numbers that are related to my name somehow and how the numbers are different than each other . Look how did I write my name (First char in capital and the second one in small letter) [color="red"]M[/color][color="#4169e1"]m[/color]ichael s Here is the return of the vl-string->list function . ([color="red"]77[/color] [color="#4169e1"]109[/color] 105 99 104 97 101 108 [color="#ff00ff"]32[/color] 115) So what I meant is that the capital and small letters are having different values of that return . Nice try . Thanks Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted November 13, 2010 Share Posted November 13, 2010 The numbers are the ASCII codes for the characters contained in the string: http://en.wikipedia.org/wiki/ASCII#ASCII_printable_characters Quote Link to comment Share on other sites More sharing options...
Michaels Posted November 13, 2010 Share Posted November 13, 2010 Wow thats really nice , I added one more vl-remove function to remove the capital letter in name and it did it well . Mmichael s (vla-put-TextString o (vl-list->string [color="red"](vl-remove 77[/color] (vl-remove 32 (vl-string->list (vla-get-TextString o)))))) And it become ... michaels So general question , could we build a text with these (ASCII printable characters) that are included within that list ?(strange question:unsure:) Thanks Lee Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted November 13, 2010 Share Posted November 13, 2010 So general question , could we build a text with these (ASCII printable characters) that are included within that list ?(strange question:unsure:) We are already... You have used the vl-list->string function in your code. Also, look into the ascii and chr functions. Quote Link to comment Share on other sites More sharing options...
Michaels Posted November 13, 2010 Share Posted November 13, 2010 I think it's a matter of turning the value of each char to become a char first , and after that we would use (vla-put-TextString ..... to replace or to add specific chars. Am I right ? Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted November 13, 2010 Share Posted November 13, 2010 As I said, you are already using vl-list->string which does just that, look it up in the VLIDE Help Docs. Quote Link to comment Share on other sites More sharing options...
Michaels Posted November 13, 2010 Share Posted November 13, 2010 Here it goes . .. . . . .. .. Try it with text entity not (mtext) (defun c:underline (/ e ) (vl-load-com) (while (setq e (car (entsel))) (if (vlax-property-available-p (setq o (vlax-ename->vla-object e)) 'TextString) (vla-put-TextString o (setq a (strcat (chr 37)(chr 37)(chr 117)(setq b (vla-get-TextString o))))) ) (princ) ) But what about your way with vl-list->string ? I feel like dancing on the moon. Michaels Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted November 13, 2010 Share Posted November 13, 2010 But what about your way with vl-list->string ? What about it? Quote Link to comment Share on other sites More sharing options...
Michaels Posted November 13, 2010 Share Posted November 13, 2010 I mean , I could not make it with the function vl-list->string . Is it possible as well as my previous action of the routine ? Thanks Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted November 13, 2010 Share Posted November 13, 2010 Yes, three different ways: (defun c:test1 ( / e ) (vl-load-com) (while (setq e (car (entsel))) (if (vlax-property-available-p (setq o (vlax-ename->vla-object e)) 'TextString) (vla-put-TextString o (strcat "%%u" (vla-get-TextString o))) ) ) (princ) ) (defun c:test2 ( / e ) (vl-load-com) (while (setq e (car (entsel))) (if (vlax-property-available-p (setq o (vlax-ename->vla-object e)) 'TextString) (vla-put-TextString o (vl-list->string (append '(37 37 117) (vl-string->list (vla-get-TextString o))))) ) ) (princ) ) (defun c:test3 ( / e ) (vl-load-com) (while (setq e (car (entsel))) (if (vlax-property-available-p (setq o (vlax-ename->vla-object e)) 'TextString) (vla-put-TextString o (vl-list->string (cons 37 (cons 37 (cons 117 (vl-string->list (vla-get-TextString o))))))) ) ) (princ) ) For this task, the first is the most practical IMO Quote Link to comment Share on other sites More sharing options...
Michaels Posted November 13, 2010 Share Posted November 13, 2010 Frankly , More than great Lee. Have you noticed that you used my way instead of the one that you have used in your routine before ? The way that I did it before . (setq e (car ([color="red"]entsel[/color]))) The way that you did it before but not use it earlier . (setq e (car ([color="red"]nentsel[/color]))) So any difference in the use of nentsel in our examples ? Thank you so much Lee. Greatly appreciated. Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted November 13, 2010 Share Posted November 13, 2010 Have you noticed that you used my way instead of the one that you have used in your routine before ? Yes, I just modified your posted code :wink: So any difference in the use of nentsel in our examples ? Yes, nentsel allows for a selection of attributes, entsel does not. Thank you so much Lee. Greatly appreciated. You're very welcome Michaels Quote Link to comment Share on other sites More sharing options...
alanjt Posted November 15, 2010 Share Posted November 15, 2010 For this task, the first is the most practical IMO Agreed. Unless you had a reason to already have the string converted to a list of ascii code, the others are pointless. Quote Link to comment Share on other sites More sharing options...
ryoerger Posted June 26, 2012 Share Posted June 26, 2012 (edited) Is there a way to do this so that only "extra" spaces are removed? (I'm not a programmer). In other words, I don't want to remove spaces between words but only the spaces before and after each text string/sentence... or I suppose it could also be in a case where there are two spaces side-by-side and one of them needs to go away. Thanks! Compliments to Lee Mac for this code (I assume it's alright to repost this?) (defun c:removespcs ( / e ) (vl-load-com) (while (setq e (car (nentsel))) (if (vlax-property-available-p (setq o (vlax-ename->vla-object e)) 'TextString) (vla-put-TextString o (vl-list->string (vl-remove 32 (vl-string->list (vla-get-TextString o))))) ) ) (princ) ) Edited June 27, 2012 by ryoerger To comply with forum rules. Quote Link to comment Share on other sites More sharing options...
pBe Posted June 27, 2012 Share Posted June 27, 2012 (edited) Welcome to Cad Tutor I'm sure theres a more efficient way of doing this. (defun c:removespcs ( / e str l p) (vl-load-com) (while (setq e (car (nentsel))) (if (and (vlax-property-available-p (setq o (vlax-ename->vla-object e)) 'TextString) (setq str (vla-get-TextString o)) (vl-string-search " " str)) (progn (while (setq p (vl-string-position 32 str nil t)) (setq l (cons (strcat " " (substr str (+ 2 p))) l) str (substr str 1 p))) (setq str (strcat str (apply 'strcat (vl-remove-if '(lambda (j)(eq j " ")) l))) l nil) (vla-put-textstring o str) ) ) ) (princ) ) What it does is search the string with "two spaces side-by-side " then rebuild the string. BTW: its not limited to 2 spaces Edited June 27, 2012 by pBe Quote Link to comment Share on other sites More sharing options...
ryoerger Posted June 27, 2012 Share Posted June 27, 2012 Welcome to Cad Tutor What it does is search the string with "two spaces side-by-side " then rebuild the string. BTW: its not limited to 2 spaces Thank you! ...and, I have a feeling this often happens... It work beautifully as designed, per my request, but now I realize I did not ask for what I really need. In a text string like this (where the dashes represent spaces): ----SUMP-PUMP--1-CURRENT---MONITOR------ Your code created this: -SUMP-PUMP-1-CURRENT-MONITOR- Cool! But I really needed this: SUMP-PUMP-1-CURRENT-MONITOR Where there are no spaces on either end of the text string. (something keeps telling me I need to become a programmer... ) Quote Link to comment Share on other sites More sharing options...
SLW210 Posted June 27, 2012 Share Posted June 27, 2012 ryoerger, Please read the CODE POSTING GUIDELINES and edit your post! Quote Link to comment Share on other sites More sharing options...
pBe Posted June 27, 2012 Share Posted June 27, 2012 (edited) Are you sure the space at the end remains? (defun c:removespcs ( / e str l p) (vl-load-com) (while (setq e (car (nentsel))) (if (and (vlax-property-available-p (setq o (vlax-ename->vla-object e)) 'TextString) (setq str (vla-get-TextString o)) (vl-string-search " " str)) (progn (while (setq p (vl-string-position 32 str nil t)) (setq l (cons (strcat " " (substr str (+ 2 p))) l) str (substr str 1 p))) (setq str [b][color=blue](vl-string-left-trim " "[/color][/b] (strcat str (apply 'strcat (vl-remove-if '(lambda (j)(eq j " ")) l)))) l nil) (vla-put-textstring o str) ) ) ) (princ) ) EDIT: hang on.. i assumed every string would have a prefix at the front.. Edited June 27, 2012 by pBe add vl-string-left trim 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.