Select text in particular range value

Select text in particular range value

Anonymous
Not applicable
5,405 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,406 Views
33 Replies
Replies (33)
Message 21 of 34

hak_vz
Advisor
Advisor

@JM_THS_4Y 

Attach sample drawing. Is your text laced in particular layer or we talk about all text entities with n decimal places?

Miljenko Hatlak

EESignature

Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.
0 Likes
Message 22 of 34

JM_THS_4Y
Participant
Participant

yes, the texts are in several layers and what I need is to select all the texts with 3 decimal places, for example the texts can be 1,005 or 0.350, or 9,125, 180,028...

 

The ideal would be to be able to select the number of decimals, with a prompt, so I can adapt this routine to future situations where I may have more or less decimals.
thank you

0 Likes
Message 23 of 34

ВeekeeCZ
Consultant
Consultant

Just in case you don't know how to use the built-in tools -- it's 15 sec job. SEE 

0 Likes
Message 24 of 34

devitg
Advisor
Advisor

@JM_THS_4Y please show us , both the dwg and lisp,  as far as you went. 

0 Likes
Message 25 of 34

JM_THS_4Y
Participant
Participant

 

Yes, the texts are in several layers and what I need is to select all the texts with 3 decimal places, for example the texts can be 1,005 or 0.350, or 9,125, 180,028...

 

The ideal would be to be able to select the number of decimals, with a prompt, so I can adapt this routine to future situations where I may have more or less decimals.
thank you

0 Likes
Message 26 of 34

JM_THS_4Y
Participant
Participant

ok, thank you.

 
0 Likes
Message 27 of 34

JM_THS_4Y
Participant
Participant
I think I have a problem here with my _find, it's not the same version as yours.
I have Autocad 2019 but apparently my find routine is not the same.
Can I ask you to please send me this version? If you can? Thanks
0 Likes
Message 28 of 34

JM_THS_4Y
Participant
Participant

_find_i_have.JPG

0 Likes
Message 29 of 34

Kent1Cooper
Consultant
Consultant

@JM_THS_4Y wrote:

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


For 3 specifically, and using the comma separator in your Messages 22 & 25:

 

(sssetfirst nil (ssget "_X" '((0 . "*TEXT") (1 . "*`,###"))))

 

For any number of decimal places, and using the period separator as in your drawing:

 

(defun C:GTDP (/ dec str); = Get Text by number of Decimal Places
  (setq
    dec (getint "\nNumber of Decimal Places: ")
    str "*."
  )
  (repeat dec (setq str (strcat str "#")))
  (sssetfirst nil (ssget "_X" (list '(0 . "*TEXT") (cons 1 str))))
)

 

Remove the "_X" to select yourself, rather than have it find all of them.

 

ALSO:  I notice some in the drawing have more than one period:

Kent1Cooper_0-1636465849306.png

My code will find some of those only when you ask for one decimal place [it looks only at the end of the string], but it won't find the one that ends with a period, no matter how many decimal places you ask for.  What would you want done with them -- do you want the number of decimal places between periods to find them?  I'm not sure how to achieve that, but it may be possible.

Kent Cooper, AIA
0 Likes
Message 30 of 34

ВeekeeCZ
Consultant
Consultant

Unfortunately, I can't send you that - it's a built-in command.

I also have 2016 and there is the same one (as mine)... I thought it's like that ever since I remember.

 

Do you have some sort of lisp routine? I honestly see this one of yours for the first time.

Maybe try .find to invoke the original command... 

0 Likes
Message 31 of 34

JM_THS_4Y
Participant
Participant
thank you very much
0 Likes
Message 32 of 34

JM_THS_4Y
Participant
Participant
Yes, if you could help me with this issue of the number of decimal places between points.

Sometimes files come to me like this, with several entries and then I need to isolate some points.

thank you,
you already helped me a lot
0 Likes
Message 33 of 34

Kent1Cooper
Consultant
Consultant

@JM_THS_4Y wrote:
Yes, if you could help me with this issue of the number of decimal places between points. ....

As a start, this will give the number of characters between periods in a text string saved to a variable called 'str', if it contains two periods:

(- (vl-string-position 46 str 1 T) (vl-string-position 46 str) 1)

 

If it contains only one period, that returns -1.

 

So in theory, the selection would need to be of all text objects [whether in the User's selection or in the entire drawing], and each one's contents could be tested in that way.  If the result is positive but not the desired number of decimal places, it would be removed from the selection set.  If the result is -1, it would need to be tested again for the number of decimal places:

(- (strlen str) (vl-string-position 46 str) 1)

and if that's not the right number, remove it from the selection set.

 

[I'm curious to know:  What does a text string with two periods in it represent?]

Kent Cooper, AIA
0 Likes
Message 34 of 34

JM_THS_4Y
Participant
Participant
As for the question of "What does a text string with two periods in it represent?"
the answer is that I sometimes get drawings from topography, or points transformed from other coordinate systems, and that causes errors.
That's why I then need to isolate these "errors" and separate this type of information.

thanks
Joao
0 Likes