Select text in particular range value

Select text in particular range value

Anonymous
Not applicable
5,392 Views
33 Replies
Message 1 of 34

Select text in particular range value

Anonymous
Not applicable

Dear Experts,

 

I am searching for a long time for this requirement.

 

The requirement is to select the text, which are in a particular range.

 

Suppose the drawing has a lot of thousands of numbers.

 

If the user wants to select the numbers which are between 10.5 to 25.4, then only those numbers should be selected from user selection and remaining to be unselected from user selection.

 

Lisp should consider the values even text has alphabets and decimals.

 

you can consider the below code for further editing, if possible.

(defun c:MMA (/ ss lst numlst txt2num)
(defun txt2num (txt / num)
(or (setq num (distof txt 5))
(setq num (distof txt 2))
(setq num (distof txt 1))
(setq num (distof txt 4))
(setq num (distof txt 3))
)
num
)
(prompt "\nSelect text to analize numbers.")
(if (setq ss (ssget '((0 . "TEXT,MTEXT"))))
(progn
(setq lst (vl-remove-if 'listp (mapcar 'cadr (ssnamex ss))))
(mapcar '(lambda (x) (setq numlst (cons (txt2num (cdr (assoc 1 (entget x)))) numlst)))
lst
)
(if (setq numlst (vl-remove-if 'listp numlst))
(progn
(print "Min number ")
(princ (apply 'min numlst))
(print "Max number ")
(princ (apply 'max numlst))
(print "Average of numbers ")
(princ (/ (apply '+ numlst) (length numlst)))
)
(prompt "\nNo numberf found.")
)
)
)
(princ)
)

 Advanced thank you.

0 Likes
Accepted solutions (1)
5,393 Views
33 Replies
Replies (33)
Message 2 of 34

devitg
Advisor
Advisor

@Anonymous Please upload your sample.dwg

0 Likes
Message 3 of 34

Kent1Cooper
Consultant
Consultant

@Anonymous wrote:

....

Lisp should consider the values even text has alphabets and decimals.

....


How many kinds of configurations might that take?  I ask because, for example,

(atof "12.345ABC")

returns 12.345, so if letters occur only after  the numerical part you want, (atof) could be used without modifying the text content.  But

(atof "ABC12.345")

returns 0.0, so if letters can come before  the numerical part, the text content would need to have non-numerical characters stripped off the beginning before conversion to a number.

And if you need to have other-than-decimal formats and use (distof), applying that to either  of those strings returns nil, so for that, non-numerical characters would need to be stripped off both  ends before it could do anything with the string.

 

Also, could there ever be more than one  numerical part in the same string, such as "abc123.45xyz543.21"?

 

Finally, I see you have MTEXT accepted for selection.  Do you ever use Mtext containing stacked fractions ?  The special coding in the string content to make them stack would mess up any analysis of the number represented, or would require some more sophisticated code to pull the fraction out.

Kent Cooper, AIA
Message 4 of 34

devitg
Advisor
Advisor

as @Kent1Cooper  ask 

 

How many kinds of configurations might that take?

 

 

A sample dwg will solve all questions 

 

 

0 Likes
Message 5 of 34

Sea-Haven
Mentor
Mentor

I tried using a ssget filter with < > etc but it found numbers ok but once the range was added did not work someone smarter than me may know a ssget way using -4 "and" ### < >.

 

The only way may be to get all text then check if < > adding to a list.

 

(setq ss1 (ssget "x" '((0 . "TEXT")(1 . "#,##,###,####,#####")(410 . "Model"))))

0 Likes
Message 6 of 34

Anonymous
Not applicable

Dear Sir,

 

Please find attacahed drawing having lot of numbers. Marked some circles where alphabets also included in text. Some Texts have Prefixes and some have suffixes and some have both Prefixes and suffixes.Range Selection.JPG 

0 Likes
Message 7 of 34

pbejse
Mentor
Mentor

@Anonymous wrote:

Please find attacahed drawing having lot of numbers. Marked some circles where alphabets also included in text. Some Texts have Prefixes and some have suffixes and some have both Prefixes and suffixes. 


 

Its actually easier if you filter the selection by their Z value instead of the string @Anonymous .

See how easy for us to suggest if there is a an actual drawing to look into 🙂

 

Try that filter with ssget, give us a shout if you need help with that.

 

Something ike this:

(setq ss (ssget "_X" '((0 . "TEXT") (-4 . "*,*,>=") (10 0.0 0.0 7.83)(-4 . "*,*,<=")
                           				  (10 0.0 0.0 8.55) )))

 

We can build a range by prompting for lowest and highest point.

 

0 Likes
Message 8 of 34

pbejse
Mentor
Mentor

Try it like this

 

(Setq low (getreal "\nEnter Low point: "))
(Setq high (getreal "\nEnter High point: "))
(setq ss (ssget "_X" (list '(0 . "TEXT")'(-4 . "*,*,>=")
		        (list 10 0.0 0.0 low)
		       '(-4 . "*,*,<=")
		       (list 10 0.0 0.0 high) )))

 

 

You can also jsut use the Z value after selection is already set

(< low (caddr (cdr (assoc 10 (entget en)))) high)

HTH

 

0 Likes
Message 9 of 34

Anonymous
Not applicable

Thanks for responding Sir,

 

But here the task is to select the numbers in particular range (Suppose 2.5 to 8), then only those numbers to be selected from user selection, and remaining to be unselected. Some texts may include alphabets either on prefix or suffix or includes both prefix and suffix.

0 Likes
Message 10 of 34

pbejse
Mentor
Mentor

@Anonymous wrote:

Thanks for responding Sir,

 

But here the task is to select the numbers in particular range (Suppose 2.5 to 8), then only those numbers to be selected from user selection, and remaining to be unselected. Some texts may include alphabets either on prefix or suffix or includes both prefix and suffix.


 

Hello @Anonymous ,

 

Please try what i suggested first, the string prefix and suffix has nothing to do with the selection using the filter shown on my previous post, it will still select tha numerical value of those TEXT based on the values you provided via Low and High variable

 

By collecting the Z values of the selected TEXT, you can get the high and low values as well.

 

Cheers

 

 

 

 

0 Likes
Message 11 of 34

pbejse
Mentor
Mentor
(defun c:MMA (/ ss lst numlst txt2num)
  (prompt "\nSelect text to analize numbers.")
  (if (setq ss (ssget '((0 . "TEXT,MTEXT"))))
    (progn
      (setq lst (vl-remove-if 'listp (mapcar 'cadr (ssnamex ss))))
      (foreach x lst
	(setq numlst (cons
		       (caddr (cdr (assoc 10 (entget x)))) numlst)))
	  (print "Min number ")
	  (princ (apply 'min numlst))
	  (print "Max number ")
	  (princ (apply 'max numlst))
	  (print "Average of numbers ")
	  (princ (/ (apply '+ numlst) (length numlst)))
	) ;_ end of progn
	(prompt "\nNo numberf found.")
      )
  (princ)
)
0 Likes
Message 12 of 34

Anonymous
Not applicable

Sir,

Nothing text is selecting by this code. It showing like below pic.

Error.JPG

Here I need only selection of numbers in between the user-defined range irrespective of any other text properties, whether it has alphabetical or z elevations or in different layers.

 

Thans a lot Sir for spending your valuable time.

0 Likes
Message 13 of 34

pbejse
Mentor
Mentor

@Anonymous wrote:

Sir,

Nothing text is selecting by this code. It showing like below pic.


I just run the MMA from post#11

Select objects:
"Min number " 0.38
"Max number " 896.54
"Average of numbers " 10.0203

Please check again. 🙂

 

 

0 Likes
Message 14 of 34

Anonymous
Not applicable

Dear Sir,

 

I have attached drawing for your reference.

 

I need exactly only text selections which falls in between user defined range. The lisp command should ask as below at command prompt.

 

"Please enter Min value of Range = " (Suppose user enters 6.5)

"Please enter Max value of Range = " (Suppose user enters 8.2)

 

Then the texts, which have values in between 6.5 and 8.2, shall be selected and remaining shall be unselected from user selection.

 

The text may have alphabets sometimes with both prefix and suffix also. (I have marked them in yellow circles)

 

Thanks in advance Sir.

0 Likes
Message 15 of 34

pbejse
Mentor
Mentor

Strange that the first drawing file you submitted is different from the second one

 

 

(defun c:MMA (/ ss minval maxval numlst x str n i)

(prompt "\nSelect text to analize numbers.")
(if (and
          
          (setq numlst nil
                minval (getreal  "Please enter Min value of Range = "))
          (setq maxval (getreal  "Please enter Min value of Range = "))
          (setq ss (ssget "_X" '((0 . "TEXT,MTEXT"))))          
          )
    
    (progn
          (repeat (setq i (sslength ss))
                (setq x   (entget (ssname ss (setq i (1- i))))
                      str (strcase (cdr (assoc 1 x)))
                      n   (read
                                (vl-list->string
                                      (vl-remove-if
                                            '(lambda (c)
                                                   (<= 65 c 90))
                                            (vl-string->list str)
                                            )
                                      )
                                )
                      )
                  	(if (<= minval n maxval)                            
                                  (setq numlst (cons n numlst))))
      
	  (print "Min number ")
	  (princ (apply 'min numlst))
	  (print "Max number ")
	  (princ (apply 'max numlst))
	  (print "Average of numbers ")
	  (princ (/ (apply '+ numlst) (length numlst)))
	)
    )
      (princ)
            )

 

 

 

"Min number " 6.5
"Max number " 8.2
"Average of numbers " 7.3712

This one will rub a little bit longer as it involves convertsion

 

HTH.

 

PS: if you had stayed on the original format. keeping the Z values it would have been a lot faster.  Now everything is flatten

Looking for an old routine of mine that removes the none numbers on the string. its way faster than the one i post here.

 

 

 

 

0 Likes
Message 16 of 34

Anonymous
Not applicable

Dear Sir,

 

Please forget about z elevations and min, max & avergae values of text.

 

The lisp code I have provided is for just editing.

 

The exact requirement is to selection only. 

 

The lisp should select those numbers, which are in user input range (Suppose in between 4.5 to 5.0).

 

Here there is no matter of finding minimum, maximum and average value of text.

 

It's matter about only selection of text, which are having text value in between certain range of min and max values fed by user.

 

Please have a look on my attached image once, which autoselected the values between 4.5 to 5.0 and remaining to be unselected from user selection set. If you see in snapshot all selected values are in between 4.5 to 5.0 only.

My requirement.JPG

0 Likes
Message 17 of 34

pbejse
Mentor
Mentor
Accepted solution
(defun c:MMA  (/ ss minval maxval numlst x str n i ssetfound)

      (prompt "\nSelect text to analize numbers.")
      (if (and

                (setq minval
                           (getreal
                                 "Please enter Min value of Range = "))
                (setq maxval
                           (getreal
                                 "Please enter Min value of Range = "))
                (setq ssetfound (ssadd)
                      ss      (ssget "_X"
                                     '((0 . "TEXT,MTEXT")
                                       (410 . "Model"))))
                )

            (progn
                  (repeat (setq i (sslength ss))
                        (setq x   (entget (Setq e    (ssname ss
                                                             (setq i (1- i)))))
                              str (strcase (cdr (assoc 1 x)))
                              n   (read
                                        (vl-list->string
                                              (vl-remove-if
                                                    '(lambda (c)
                                                           (<= 65
                                                               c
                                                               90))
                                                    (vl-string->list
                                                          str)
                                                    )
                                              )
                                        )
                              )
                        (if (<= minval n maxval)
                              (ssadd e ssetfound))
                        )
                  (sssetfirst nil ssetfound)
                  )
            )
      (princ)
      )

 

Dont forget to set the Grips limit -> GRIPOBJLIMIT

or Options/Selection/Grips/Object Selection limit for display of grips

 

 

 

 

 

 

 

Message 18 of 34

Anonymous
Not applicable

Dear Sir,

 

Thanks a lot, you saved lot of drafting time, Excellent.

0 Likes
Message 19 of 34

pbejse
Mentor
Mentor

You are welcome, plus you have tons of lisp code on this thread from various members, Hope you can learn from those.

 

Also , please do this for us, next time, be clear on the what you're requesting for and avoid posting conflicting information. The clearer the goal the faster you get correct results.

 

Cheers

 

0 Likes
Message 20 of 34

JM_THS_4Y
Participant
Participant

Good morning,
I'm sorry, can someone help me?
I need to select all texts with 3 decimal places, but I can't use the filter with this type of selection.
Can someone help me, with a routine that selects all the texts present in a drawing with X number of decimal places?
Thank you all for your help.

João

 
0 Likes