Jump to content

Search for a word within long Mtext ( above 250 characters) and select all text which contain that particular word


Mihail

Recommended Posts

Hi All,

 

Newbie into Lisp here. I am trying to find a way to search for a particular word within a long MTEXT and select all that text

 

I compiled a short code from what I found here on this forum but I can't make it work:

 

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

 

Any help with fixing this would be beneficial

 

Please find attached an example DWG

TEST1.dwg

Edited by SLW210
Added Code Tags!
Link to comment
Share on other sites

For your search you will need to put an OR statement to get the 1 or 3 texts, at the moment it is searching 1 and 3 and if true for both (Lee Mac has a good explanation and examples on his website)

 

I tried this and -quickly- just searching for '(3 . "*DESIGNER*") didn't work for me, but '(1 did... not sure why yet though.

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

like StevenP said

 

This needs an or logic. what your ssget is looking for text that have both 1and 3 strings. were you need to be looking for one or the other.

http://www.lee-mac.com/ssget.html#logical

 

(defun C:seltxt (/ SS)
  (setq SS (ssget "_X" (list '(0 . "*TEXT") '(-4 . "<OR") '(1 . "*DESIGNER*") '(3 . "*DESIGNER*")  '(-4 . "OR>") (cons 410 (getvar 'ctab)))))
  (sssetfirst nil ss)
  (princ)
)

 

--edit

 

'(3 . "*DESIGNER*") worked for me Steven. Looks like SLW210 updated the file maybe thats why?

Edited by mhupp
  • Like 2
  • Agree 1
Link to comment
Share on other sites

41 minutes ago, mhupp said:

'(3 . "*DESIGNER*") worked for me Steven. Looks like SLW210 updated the file maybe thats why?

 

It looked all OK, so was confused when it should have worked, was busy earlier so didn't work out why or give a link in my answer (lunch now)

 

Lee MAc SSGET reference page is: http://lee-mac.com/ssget.html

 

and for very-very long text code 3 4 1 172 304 should get -all- the text considered (250 characters for each)

Link to comment
Share on other sites

1 hour ago, mhupp said:

like StevenP said

 

This needs an or logic. what your ssget is looking for text that have both 1and 3 strings. were you need to be looking for one or the other.

http://www.lee-mac.com/ssget.html#logical

 

(defun C:seltxt (/ SS)
  (setq SS (ssget "_X" (list '(0 . "*TEXT") '(-4 . "<OR") '(1 . "*DESIGNER*") '(3 . "*DESIGNER*")  '(-4 . "OR>") (cons 410 (getvar 'ctab)))))
  (sssetfirst nil ss)
  (princ)
)

 

--edit

 

'(3 . "*DESIGNER*") worked for me Steven. Looks like SLW210 updated the file maybe thats why?

 

Thank you for your help! What I noticed it is indeed working with simple text bot not at all with MTEXT. I even tested only with MTEXT and no luck. Any ideea why?

Link to comment
Share on other sites

If you have super long text the 3 code could fail if the contents is not within the first entry:

image.png.1ed4460795b11bef19a9331f6201b28a.png

IMO it's much easier to select all text then remove items that don't match.

(defun c:seltxt	(/ ss)
  (if (setq ss (ssget "_X" (list '(0 . "*TEXT") (cons 410 (getvar 'ctab)))))
    (progn (foreach e (mapcar 'cadr (ssnamex ss))
	     (or (wcmatch (strcase (vla-get-textstring (vlax-ename->vla-object e))) "*DESIGNER*")
		 (ssdel e ss)
	     )
	   )
	   (sssetfirst nil ss)
    )
  )
  (princ)
)

But you could also use the FIND command to do the same.

image.png.81bf762e02533001bbff5628fe8c4c72.png

  • Like 3
Link to comment
Share on other sites

3 hours ago, Mihail said:

 

Thank you for your help! What I noticed it is indeed working with simple text bot not at all with MTEXT. I even tested only with MTEXT and no luck. Any ideea why?

 

Seems to work in BricsCAD. but @ronjonp to the rescue.

  • Like 1
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...