Jump to content

AutoLisp for removing all linebreaks, and leave selection on


Highvoltage

Recommended Posts

Posted (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 by Highvoltage
Link to comment
Share on other sites

Posted (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:

image.png.2c7b8654f60159321b989b9d20fc642b.png

After:

image.png.bfe75700cd215f91418daab5faa05b5b.png

Edited by pkenewell
Link to comment
Share on other sites

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)
 

Link to comment
Share on other sites

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.

  • Like 1
Link to comment
Share on other sites

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

Screenshot_5.png

  • Agree 1
Link to comment
Share on other sites

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.

  • Like 1
Link to comment
Share on other sites

Posted (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 by Highvoltage
Link to comment
Share on other sites

Posted (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 by pkenewell
  • Like 1
Link to comment
Share on other sites

Posted (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 by mhupp
Updated code
  • Like 2
Link to comment
Share on other sites

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

Posted (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:

 

image.thumb.png.7343586c8e50cb0aab69724725b09b4a.png

After:

image.thumb.png.014d25657bee1f867efb8b4911eeb74f.png

 

 

 

HideTextwNumbers.lsp

Edited by pkenewell
Link to comment
Share on other sites

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!

  • Like 2
Link to comment
Share on other sites

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.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...