Hello,
I made a search here on forum and I've seen Autodesk "About Findind and Replacing Text" help from Autodesk website, mainly using wild-card characters, but I can't get this done: My wish is to replace all text that comes afterwards the first "comma (,)" in the texts bellow:
From the image above, I want to keep only the Street/Avenue name and replace with blank/empty text everything that comes aftwards the first comma, leaving intact all the other texts in my drawing that have "comma (,) space" sequence inside them. As this adress is imported from Google Earth, using this plugin called GeoCode and Google API, it always comes with the following pattern:
"Avenue/Street Name" "comma" "space" "Number(#)" "space" "-(trace/subtraction symbol)" "space" "Neighborhood Name" "comma" "space" "City" "space" "-(trace/subtraction symbol)" "space" "State Abbreviation (2 letters)" "comma" "space" "ZIP Code" "comma" "space" "Country".
Any help with that? Thank you very much!
Solved! Go to Solution.
Solved by Kent1Cooper. Go to Solution.
Solved by Kent1Cooper. Go to Solution.
Solved by Kent1Cooper. Go to Solution.
Solved by Kent1Cooper. Go to Solution.
Start with posting this image as dwg twice - once with an initial state, the second as a wanted outcome. thx
btw it looks trivial - you should be able to manage it by your own means.
(defun C:TCS (/ txtent txt); = Truncate from Comma-&-Space
(setq
txtent (car (entsel "\nSelect Text to truncate from comma-&-space: "))
txt (getpropertyvalue txtent "TextString")
)
(setpropertyvalue txtent "TextString" (substr txt 1 (vl-string-search ", " txt)))
)
Here is the .dwg as it comes from the GoeCode plugin and the expected result. The problem is: in the same drawing it can exist many texts with the "comma space" sequence, so they could be replaced aswell.
Here's the version that finds all of them for you:
(defun C:TCS (/ ss n txtent txt); = Truncate from Comma-&-Space
(if (setq ss (ssget "_X" '((1 . "*`, *"))))
(repeat (setq n (sslength ss)); then
(setq
txtent (ssname ss (setq n (1- n)))
txt (getpropertyvalue txtent "TextString")
); setq
(setpropertyvalue txtent "TextString" (substr txt 1 (vl-string-search ", " txt)))
); repeat
); if
(princ)
); defun
@Anonymous wrote:
.... Can this LISP to be able to select lastest created object (using the "last (l")) or previous selected object when running?
(defun C:TLCS (/ txtent txt); = Truncate Last from Comma-&-Space
(setq
txtent (entlast)
txt (getpropertyvalue txtent "TextString")
)
(setpropertyvalue txtent "TextString" (substr txt 1 (vl-string-search ", " txt)))
)
Thanks for this one. I tried to execute it. It works perfetcly but aftects other texts in drawings that contains "comma space". Maybe it will be useful for some situations! Thanks a zilino!
@Anonymous wrote:
Thanks for this one. I tried to execute it, but I'm getting some error on command line: error: bad argument type: numberp: nil
They both [the find-them-all and the last-entity versions -- I'm not sure to which you are referring] work for me, in your sample drawing and in my own test drawing. I wondered whether it could be that [in the find-them-all version] there aren't any Text objects with the comma-&-space combination, or [in the last-entity version] that last one doesn't contain it, but in neither case do I get that error message. And in the last-entity version, if the last thing isn't Text at all, I get an error message, but not that one.
@Anonymous wrote:
Could you make this one to work with DText and MText aswell? This one it's just what I wanted. Thank you so much for this!
Oddly, I find that using the (setpropertyvalue) function doesn't do for Mtext. Its text-content property is named differently ["Text"] from that for regular Text ["TextString"], but in addition, for some reason it's Read-Only!
So I moved to the (vla-put-TextString) approach, because it can work on Mtext, and besides, the property in that context is named the same for both.
(vl-load-com); just in case
(defun C:TLCS (/ txtobj txt); = Truncate Last from Comma-&-Space
(setq
txtobj (vlax-ename->vla-object (entlast))
txt (vla-get-TextString txtobj)
)
(vla-put-TextString txtobj (substr txt 1 (vl-string-search ", " txt)))
)
Find-them-all version:
(defun C:TCS (/ ss n txtobj txt); = Truncate from Comma-&-Space
(if (setq ss (ssget "_X" '((1 . "*`, *"))))
(repeat (setq n (sslength ss)); then
(setq
txtobj (vlax-ename->vla-object (ssname ss (setq n (1- n))))
txt (vla-get-TextString txtobj)
); setq
(vla-put-TextString txtobj (substr txt 1 (vl-string-search ", " txt)))
); repeat
); if
(princ)
); defun
@Anonymous wrote:
.... how do I modify this LISP to replace the text "R." (abbreviation) by "RUA" ... and "AV." (abbreviation) by "AVENIDA" ....
In either of them, replace this line:
(vla-put-TextString txtobj (substr txt 1 (vl-string-search ", " txt)))
with this:
(vla-put-TextString txtobj
(vl-string-subst "RUA" "R."
(vl-string-subst "AVENIDA" "AV."
(substr txt 1 (vl-string-search ", " txt))
)
)
)
It's case-sensitive, but could be made to not be, if needed. And they would make that substitution of full words for abbreviations only in objects that contain the comma-&-space combination that are being truncated, but could be made to do the same in others that are not being truncated, if needed.
@Kent1Cooper wrote:
@Anonymous wrote:
.... how do I modify this LISP to replace the text "R." (abbreviation) by "RUA" ... and "AV." (abbreviation) by "AVENIDA" ....In either of them, replace this line:
(vla-put-TextString txtobj (substr txt 1 (vl-string-search ", " txt)))
with this:
(vla-put-TextString txtobj
(vl-string-subst "RUA" "R."
(vl-string-subst "AVENIDA" "AV."
(substr txt 1 (vl-string-search ", " txt))
)
)
)
It's case-sensitive, but could be made to not be, if needed. And they would make that substitution of full words for abbreviations only in objects that contain the comma-&-space combination that are being truncated, but could be made to do the same in others that are not being truncated, if needed.
Sorry for being dumb, but I wasn't able to succed in modifying your code to make those replacements:
Would be somehting like this:
(defun C:TCRA (/ ss n txtobj txt); = Truncate from Comma-&-Space
(if (setq ss (ssget "_X" '((1 . "*"))))
(repeat (setq n (sslength ss)); then
(setq
txtobj (vlax-ename->vla-object (ssname ss (setq n (1- n))))
txt (vla-get-TextString txtobj)
); setq
(vla-put-TextString txtobj
(vl-string-subst "RUA" "R."
(vl-string-subst "AVENIDA" "AV."
(substr txt 1 (vl-string-search ", " txt))
)
)
)
); repeat
); if
(princ)
); defun
(c:TCRA)
@Anonymous wrote:
.... I wasn't able to succed .... Would be somehting like this: ....
That looks right to me, without testing it, but you can test it easily enough.... But what does "I wasn't able to succeed" mean? Doesn't load? Loads but doesn't recognize the command name? Any error message(s)? Etc.
I see you've got it revised to select all objects with text content, not just those containing the comma-&-space combination. That also looks like it should work, since when (vl-string-search) doesn't find that combination, the entire string would be returned.
[I don't suppose it's likely that you'll have things like Dimensions with override text including those abbreviations, but those would also be found. In fact, all Dimensions would be found, since they all have a 1-code entry, even if there's no override. But they wouldn't be altered, since their text-content property is named differently. But it might give you an error for not finding the specified property.]
@Kent1Cooper wrote:
....... all Dimensions would be found, since they all have a 1-code entry, even if there's no override. .... But it might give you an error for not finding the specified property.]
If that's the problem, you can restrict it to finding only Text and/or Mtext, not Dimensions:
(setq ss (ssget "_X" '((0 . "*TEXT") (1 . "*"))))
Can't find what you're looking for? Ask the community or share your knowledge.