Jump to content

Lisp To Select Multiple Text and MText Values Entered


Elektrik

Recommended Posts

For example, there are texts containing area, m2, 50, door, etc. I could select them one by one thanks to QuickSelect, Text or MText, Contents and Wildcard Match, but I want to select them all at the same time like entering Area*, m2*, etc. and select all texts and mtexts containing those values like selecting them with wildcard match or a lisp to select text and mtext containing the values I want to select in the entire drawing, like if you select area:50m2, it would select area:75m2 or area 40m2 as well. Either one of these kinds of lips would help. Thanks in advance.

Link to comment
Share on other sites

This will select/highlight any text that starts with "Area" or ends with "m2".

 

(defun C:seltxt (/ SS)
  (setq SS (ssget "_X" (list '(0 . "*TEXT") '(1 . "Area*,*m2") (cons 410 (getvar 'ctab)))))
  (sssetfirst nil ss)
  (princ)
)

 

Edited by mhupp
updated code.
  • Like 3
Link to comment
Share on other sites

@mhupp as long as you are highlighting objects then I believe it would be much better to get the ones in current active space only than selecting all matching objects in the other invisible spaces.

  • Like 1
  • Agree 1
Link to comment
Share on other sites

Thinking more about this maybe it would be  better to let the user decide what to search for. or use both top for common terms and this for not so common terms. You also have to input the * for wild cards and use , if you going to search for more then one term.  its also important to note when typing the search terms you can't use spaces.

 

(defun C:selTxt (/ SS txt)
  (setq txt (getstring "\nSearch Text for Terms: ")) ;hit enter for defult options.
  (if (eq txt "")
    (setq txt "Area*,*m2") ;set defult search options here
  )
  (if (setq SS (ssget "_X" (list '(0 . "*TEXT") (cons 1 txt) (cons 410 (getvar 'ctab)))))
    (sssetfirst nil ss)
    (prompt (strcat "\nText doesn't contain " txt))
  )
  (princ)
)

 

Example

Search Text for: area*,*m2                           This would work like above lisp.

Search Text for: *area*                                  This would select text that has the word "area" in it.

Search Text for: *door                                   This would select text that ends with "door"

Search Text for: area*,*m2,*area*,*door    This would select all 3 examples text in one go.

 

Edited by mhupp
combined the two commands into one.
  • Like 2
  • Thanks 1
Link to comment
Share on other sites

On 12/6/2021 at 3:38 AM, mhupp said:

Thinking more about this maybe it would be  better to let the user decide what to search for. or use both top for common terms and this for not so common terms. You also have to input the * for wild cards and use , if you going to search for more then one term.  its also important to note when typing the search terms you can't use spaces.

 


(defun C:selTxt (/ SS txt)
  (setq txt (getstring "\nSearch Text for Terms: ")) ;hit enter for defult options.
  (if (eq txt "")
    (setq txt "Area*,*m2") ;set defult search options here
  )
  (if (setq SS (ssget "_X" (list '(0 . "*TEXT") (cons 1 txt) (cons 410 (getvar 'ctab)))))
    (sssetfirst nil ss)
    (prompt (strcat "\nText doesn't contain " txt))
  )
  (princ)
)

 

Example

Search Text for: area*,*m2                           This would work like above lisp.

Search Text for: *area*                                  This would select text that has the word "area" in it.

Search Text for: *door                                   This would select text that ends with "door"

Search Text for: area*,*m2,*area*,*door    This would select all 3 examples text in one go.

 

 

This lips is good, thanks. But, is there any way to enter multiple text, mtext values at the same time to select texts, mtexts containing either one of those values separately? 

Link to comment
Share on other sites

I'm not understanding. you can search for multiple values at once just use a , in between them.

 

Do you then want to cycle through the text that match the search one at a time? to edit them or something?

Can you explain more what you want to do.

Link to comment
Share on other sites

You can use a simple (while  and just add the txt to a string.

 

(setq str "")
(while (/=  "" (setq txt (getstring "\nType text Enter to stop ")))
(setq str (strcat str "," txt))
)

 

 

  • Like 3
Link to comment
Share on other sites

8 hours ago, BIGAL said:

You can use a simple (while  and just add the txt to a string.

 


(setq str "")
(while (/=  "" (setq txt (getstring "\nType text Enter to stop ")))
(setq str (strcat str "," txt))
)

 

 

I couldn't make it work, but thanks.

Link to comment
Share on other sites

56 minutes ago, Elektrik said:

I couldn't make it work, but thanks.

 

This works for me, selects text with user input as BigAl suggested and MHupps first bit of code (slight modification to both, using "(getstring T....)" to allow for spaces in the text string and (cons 1 str) which mhupp uses n his second code)

 

(defun C:seltxt (/ SS str)
  (setq str "")
  (while (/=  "" (setq txt (getstring T "\nType text Enter to stop ")))
    (setq str (strcat str "," txt))
  )
  (setq SS (ssget "_X" (list '(0 . "*TEXT") (cons 1 str) (cons 410 (getvar 'ctab)))))
  (sssetfirst nil ss)
  (princ)
)

 

Noting that this is case sensitive, not sure how to do it otherwise,  and it also accepts wold cards, search term Hello won't select 'Hello World' text in the drawing. but search Hello* should pick it up (and so should *llo wo*)

 

  • Like 3
Link to comment
Share on other sites

1 hour ago, Steven P said:

 

This works for me, selects text with user input as BigAl suggested and MHupps first bit of code (slight modification to both, using "(getstring T....)" to allow for spaces in the text string and (cons 1 str) which mhupp uses n his second code)

 


(defun C:seltxt (/ SS str)
  (setq str "")
  (while (/=  "" (setq txt (getstring T "\nType text Enter to stop ")))
    (setq str (strcat str "," txt))
  )
  (setq SS (ssget "_X" (list '(0 . "*TEXT") (cons 1 str) (cons 410 (getvar 'ctab)))))
  (sssetfirst nil ss)
  (princ)
)

 

Noting that this is case sensitive, not sure how to do it otherwise,  and it also accepts wold cards, search term Hello won't select 'Hello World' text in the drawing. but search Hello* should pick it up (and so should *llo wo*)

 

This works great. Thank you all.

  • Like 1
Link to comment
Share on other sites

17 minutes ago, Elektrik said:

This works great. Thank you all.

 

17 minutes ago, Elektrik said:

This works great. Thank you all.

 

Not me, I just copied and pasted BigAl and Mhupp.....

  • Like 1
Link to comment
Share on other sites

  • 2 weeks later...
On 12/6/2021 at 7:38 AM, mhupp said:

Thinking more about this maybe it would be  better to let the user decide what to search for. or use both top for common terms and this for not so common terms. You also have to input the * for wild cards and use , if you going to search for more then one term.  its also important to note when typing the search terms you can't use spaces.

 


(defun C:selTxt (/ SS txt)
  (setq txt (getstring "\nSearch Text for Terms: ")) ;hit enter for defult options.
  (if (eq txt "")
    (setq txt "Area*,*m2") ;set defult search options here
  )
  (if (setq SS (ssget "_X" (list '(0 . "*TEXT") (cons 1 txt) (cons 410 (getvar 'ctab)))))
    (sssetfirst nil ss)
    (prompt (strcat "\nText doesn't contain " txt))
  )
  (princ)
)

 

Example

Search Text for: area*,*m2                           This would work like above lisp.

Search Text for: *area*                                  This would select text that has the word "area" in it.

Search Text for: *door                                   This would select text that ends with "door"

Search Text for: area*,*m2,*area*,*door    This would select all 3 examples text in one go.

 

dear mate, can you add automatically delete those selected text at the end of this lisp ? if would be great 

Link to comment
Share on other sites

17 minutes ago, uzumaki narudin said:

dear mate, can you add automatically delete those selected text at the end of this lisp ? if would be great 

 

output of this routine is selection.

 

so, just add 

(command "erase" )

 

before (princ), after ) in the last section

 

 

  • Agree 1
  • Thanks 1
Link to comment
Share on other sites

5 minutes ago, exceed said:

 

output of this routine is selection.

 

so, just add 

(command "erase" )

 

before (princ), after ) in the last section

 

 

thanks mate.. working 

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...