pkenewell Posted May 13 Share Posted May 13 @Highvoltage Try this change to mhupp's code. It all has to do with correctly using (wcmatch). HideTextwNumbers.lsp 1 Quote Link to comment Share on other sites More sharing options...
Highvoltage Posted May 13 Author Share Posted May 13 (edited) 23 minutes ago, pkenewell said: @Highvoltage Try this change to mhupp's code. It all has to do with correctly using (wcmatch). HideTextwNumbers.lsp 1.19 kB · 0 downloads EDIT: I had a double entry in my LSP file, texting again Thanks, but it does the same. It hides every text layer. No matter what i write for the wcmatch. Edited May 13 by Highvoltage Quote Link to comment Share on other sites More sharing options...
pkenewell Posted May 13 Share Posted May 13 (edited) 11 minutes ago, Highvoltage said: Thanks, but it does the same. It hides every text layer. No matter what i write for the wcmatch. Strange - it's working fine in the document I tested. Did you test my changes to mhupp's code? Do you have a drawing for me to test? EDIT: Here is another slight update. I realized I did not add the decimal point to the search. It is still working good for me, testing different MTEXTs with "+" "-" and decimals in the numbers. HideTextwNumbers.lsp Before: After: Edited May 13 by pkenewell Quote Link to comment Share on other sites More sharing options...
Highvoltage Posted May 13 Author Share Posted May 13 9 minutes ago, pkenewell said: Strange - it's working fine in the document I tested. Did you test my changes to mhupp's code? Do you have a drawing for me to test? EDIT: Here is another slight update. I realized I did not add the decimal point to the search. It is still working good for me, testing different MTEXTs with "+" "-" and decimals in the numbers. HideTextwNumbers.lsp 1.19 kB · 0 downloads It works now, i had a double entry in my LSP file, and even after i removed it i needed to restart AutoCAD, cause it got stuck. Now it works, but it hides every entry that has numbers in it. and i wanted to only hide objects that consists of only numbers. And preferably "just numbers and a maximum of 2 non-digits" so it removes things like D-1 and 29Dm, but not things like "29m cleared ground" But this might be a to much work. (I could do this with regex) Quote Link to comment Share on other sites More sharing options...
pkenewell Posted May 13 Share Posted May 13 17 minutes ago, Highvoltage said: Now it works, but it hides every entry that has numbers in it. and i wanted to only hide objects that consists of only numbers. And preferably "just numbers and a maximum of 2 non-digits" so it removes things like D-1 and 29Dm, but not things like "29m cleared ground" But this might be a to much work. (I could do this with regex) Oops - yeah, mine wasn't actually working correctly either. My wcmatch pattern was wrong in a few ways. Unfortunately, I don't know wcmatch good enough to make it work, and I am not even sure (wcmatch) will do the job. I think regular expression is the way to go. 1 Quote Link to comment Share on other sites More sharing options...
Highvoltage Posted May 13 Author Share Posted May 13 I think part of the problem is, that the content of the text is formatted, and therefore it will find numbers in every single instance 1 Quote Link to comment Share on other sites More sharing options...
mhupp Posted May 13 Share Posted May 13 12 minutes ago, Highvoltage said: I think part of the problem is, that the content of the text is formatted, and therefore it will find numbers in every single instance Yes. I will see if i can clean it up later tonight. 1 Quote Link to comment Share on other sites More sharing options...
Highvoltage Posted May 13 Author Share Posted May 13 (edited) 22 minutes ago, mhupp said: Yes. I will see if i can clean it up later tonight. I found a workaround for formatted text in another forum: (by Kent1Cooper) (defun C:SST# (/ n txt); = Selection Set of Text/Mtext numerical only (if (setq ss (ssget '((0 . "*TEXT")))) (progn ; then (repeat (setq n (sslength ss)) (setq txt (ssname ss (setq n (1- n)))) (if (not (distof (getpropertyvalue txt (if (= (getpropertyvalue txt "LocalizedName") "Text") "TextString" "Text" ; first for Text, second for Mtext ); if ); getpropertyvalue ); distof ); not (ssdel txt ss); remove it ); if ); repeat (if (> (sslength ss) 0) ; still any left? (sssetfirst nil ss); then -- select/grip/highlight (prompt "\nNo selected objects were numerical only."); else ); if ); progn (prompt "\nNo Text/Mtext selected."); else ); if (prin1) ); defun Here is the link for the topic This uses "getpropertyvalue" so it removes the formatting. The code works well, but it only selects plain numbers and it uses a function that i don't understand: "distof" But it selects decimal numbers, and +/- signs too, so it's a good start. Edited May 13 by Highvoltage Quote Link to comment Share on other sites More sharing options...
pkenewell Posted May 13 Share Posted May 13 (edited) @Highvoltage So - I started playing around with using regular expressions with windows scripting. Try the update attached. You might have to play around with the expression. It allows up to 2 letters, +, -, any length of numbers and a decimal. Seems to work OK in my tests but your texts might be different. HideTextwNumbers.lsp Edited May 13 by pkenewell 1 Quote Link to comment Share on other sites More sharing options...
mhupp Posted May 13 Share Posted May 13 (edited) All you really need to do is convert the selection set over to vla-object and pull the textstring value. with vla-get-property this strips out the formatting (like you linked) usually don't use mtext so my bad. on the coding. noticed my unhide command was missing a * so it was only finding text and not mtext. updated the code to only process the selection set once since everything is being converted over to vla-object names at the start then adding them to a list if a number is found in the string. processing the list at the end. Probably be negligible in time but it ends up being more effectuate. This will find any mtext and text with a number in HideTextwNumbers.lsp Edited May 13 by mhupp Updated code 2 Quote Link to comment Share on other sites More sharing options...
Highvoltage Posted May 13 Author Share Posted May 13 3 hours ago, pkenewell said: @Highvoltage So - I started playing around with using regular expressions with windows scripting. Try the update attached. You might have to play around with the expression. It allows up to 2 letters, +, -, any length of numbers and a decimal. Seems to work OK in my tests but your texts might be different. HideTextwNumbers.lsp 1.96 kB · 5 downloads Ok this works perfectly on Mtext that i created, without formatting. But it somehow does not work on the formatted text in my documents. It does not hide anything. 1 hour ago, mhupp said: All you really need to do is convert the selection set over to vla-object and pull the textstring value. with vla-get-property this strips out the formatting (like you linked) usually don't use mtext so my bad. on the coding. noticed my unhide command was missing a * so it was only finding text and not mtext. updated the code to only process the selection set once since everything is being converted over to vla-object names at the start then adding them to a list if a number is found in the string. processing the list at the end. Probably be negligible in time but it ends up being more effectuate. This will find any mtext and text with a number in HideTextwNumbers.lsp 1.08 kB · 1 download This also seem to work on non formatted text, but this one hides everything in the formatted docs. Uploaded a file. The coloured texts are unformatted, made by me, the scripts work on those. The white ones are from the plans i work on, and so far only the "getpropertyvalue" trick works on those. @pkenewell's regex is almost perfect, if somehow it could be merged with that. Drawing1.dwg Quote Link to comment Share on other sites More sharing options...
mhupp Posted May 13 Share Posted May 13 @Highvoltage updated my last code to use something from the Hide Numbers.mp4 Quote Link to comment Share on other sites More sharing options...
Highvoltage Posted May 14 Author Share Posted May 14 Last night i realized it should be much easier to look for three or more consecutive letters, and hide the rest. like this: [a-zA-Z]{3,} This way it should remove complex strings, but retain anything that resembles a word that needs translation. @mhupp that looks promising Quote Link to comment Share on other sites More sharing options...
pkenewell Posted May 14 Share Posted May 14 (edited) @Highvoltage OK - Here is my update to mhupp's code using regex, along with Lee Mac's code to remove formatting from the comparison. This does selectively hide MTEXT items based on your rules. But you will need to again, adjust the regex pattern to suit. **EDIT - I tweaked the pattern again to get more things, like a unit string on the end or % symbol, and spaces between. It could still be tweaked more, but I don't know exactly what your threshold is. Before: After: HideTextwNumbers.lsp Edited May 14 by pkenewell Quote Link to comment Share on other sites More sharing options...
Highvoltage Posted May 14 Author Share Posted May 14 1 hour ago, pkenewell said: OK - Here is my update to mhupp's code using regex, along with Lee Mac's code to remove formatting from the comparison. This does selectively remove MTEXT items. But you will need to again, adjust the regex pattern to suit. HideTextwNumbers.lsp 3.43 kB · 0 downloads Hey, @pkenewell and @mhupp You are legends! This works good enough that it clears the mess 80%. Tried my inverted method, with keeping anything that has "[a-zA-Z]{3,}" but somehow it got rid of a lot of text. Anyway 'im happy with this! 2 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.