Need a Lsip for Mtext and Text se;ection by rotation

Need a Lsip for Mtext and Text se;ection by rotation

saqib_tipa
Advocate Advocate
1,187 Views
16 Replies
Message 1 of 17

Need a Lsip for Mtext and Text se;ection by rotation

saqib_tipa
Advocate
Advocate

Hello all,

Can someone make a Lisp to select  Mtexts and Texts by rotation angle.

First it should ask to select Mtext or Text to take angle then it should ask to select objects then it should select all object with same angle.

Thank you.

0 Likes
1,188 Views
16 Replies
Replies (16)
Message 2 of 17

komondormrex
Mentor
Mentor

hey there,

(ssget (list '(0 . "text,mtext") (cons 50 (cdr (assoc 50 (entget (car (entsel "\nPick angle's sample M/Text :")))))))) 
0 Likes
Message 3 of 17

ec-cad
Collaborator
Collaborator

I think that should be:

(setq ss (ssget "X" (list '(0 . "text,mtext") (cons 50 (cdr (assoc 50 (entget (car (entsel "\nPick angle's sample M/Text :")))))))))

 

ECCAD

 

0 Likes
Message 4 of 17

paullimapa
Mentor
Mentor

or how's about this version:

(sssetfirst nil (ssget "X" (list '(0 . "text,mtext") (cons 50 (cdr (assoc 50 (entget (car (entsel "\nPick angle's sample M/Text :")))))))))

Paul Li
IT Specialist
@The Office
Apps & Publications | Video Demos
0 Likes
Message 5 of 17

Kent1Cooper
Consultant
Consultant

There's no need to pull the rotation away from its DXF index 50, and then consociate it with a 50 again.  Just leave that entry as it is:

 

(setq ss (ssget "X" (list '(0 . "*text") (assoc 50 (entget (car (entsel "\n[M]Text at desired rotation: ")))))))

 

BUT in any case, that's going to require very exact equality in rotation.  Do you need any kind of tolerance?

Kent Cooper, AIA
0 Likes
Message 6 of 17

komondormrex
Mentor
Mentor

that is not actually what op has asked for:

"First it should ask to select Mtext or Text to take angle then it should ask to select objects then it should select all object with same angle [within selected blue]."

0 Likes
Message 7 of 17

saqib_tipa
Advocate
Advocate

 

@komondormrex 

Please accept my apology, actually I want to select only Mtexts and Texts with same angle. I wrote that in subject but in the message I could not make it clear.

1st I want to select Text or Mtext and take it's rotation angle.

2nd I want to select objects (multiple or by window crossing) and it should only select Texts and Mtexts from that selection with same angle.

 

Thank you.

0 Likes
Message 8 of 17

ec-cad
Collaborator
Collaborator

Something like this seems to do it.

(setq ss (ssget "_+.:S:E" '((0 . "text,mtext"))))
(if ss
(progn
(setq ang (cdr (assoc 50 (entget (ssname ss 0))))); angle in radians
(setq selection (ssget "X" (list (cons 50 ang))))
); progn
); if

 

ECCAD

0 Likes
Message 9 of 17

saqib_tipa
Advocate
Advocate

 

@Kent1Cooper 

Thanks for reply. I need to select Texts with same rotation angle.

Thank you.

 

0 Likes
Message 10 of 17

saqib_tipa
Advocate
Advocate

 

@ec-cad 

Thank you for reply, I will try it tomorrow and let you know.

Thank you.

0 Likes
Message 11 of 17

Kent1Cooper
Consultant
Consultant

@saqib_tipa wrote:

.... I need to select Texts with same rotation angle....


I carried along the "X" from some others' suggestions, which has the routine find all qualifying objects.  To be asked to select them yourself after selecting one to establish the rotation, with only those matching the rotation of the first-selected one being "seen" in the selection, just omit the "X":

(setq ss (ssget (list '(0 . "*text") (assoc 50 (entget (car (entsel "\n[M]Text at desired rotation: ")))))))

That puts them into a selection set, but does not otherwise do anything with them.  You can use that in any command when asked to select objects, by typing it with a preceding exclamation point:  !ss

Or, you can have it leave you with them already selected/gripped/highlighted instead, to impose whatever command you want on them:

(sssetfirst nil (ssget (list '(0 . "*text") (assoc 50 (entget (car (entsel "\n[M]Text at desired rotation: ")))))))

NOTE that neither of those will include the first-selected one unless you include it again in your subsequent selection.  If you would always want it included without your selecting it again, that can be worked in.

And my earlier caveat still applies -- it will see only those with very precisely matching rotations.

Kent Cooper, AIA
0 Likes
Message 12 of 17

saqib_tipa
Advocate
Advocate

 

@Kent1Cooper 

Thank you for the explanations. and for codes. Your second command works fine as I want.

But it does not work when UCS in changed how to make it work alos in changed UCS.

How to add tolerance for example up to 5 degrees as you asked before.

 

Thank you.

 

 



I carried along the "X" from some others' suggestions, which has the routine find all qualifying objects.  To be asked to select them yourself after selecting one to establish the rotation, with only those matching the rotation of the first-selected one being "seen" in the selection, just omit the "X":

(setq ss (ssget (list '(0 . "*text") (assoc 50 (entget (car (entsel "\n[M]Text at desired rotation: ")))))))

That puts them into a selection set, but does not otherwise do anything with them.  You can use that in any command when asked to select objects, by typing it with a preceding exclamation point:  !ss

Or, you can have it leave you with them already selected/gripped/highlighted instead, to impose whatever command you want on them:

(sssetfirst nil (ssget (list '(0 . "*text") (assoc 50 (entget (car (entsel "\n[M]Text at desired rotation: ")))))))

NOTE that neither of those will include the first-selected one unless you include it again in your subsequent selection.  If you would always want it included without your selecting it again, that can be worked in.

And my earlier caveat still applies -- it will see only those with very precisely matching rotations.


 

0 Likes
Message 13 of 17

saqib_tipa
Advocate
Advocate

 

@komondormrex 

Thank you for the code. It works and does not keep selection and also for UCS changed.
Thank you.

 


@komondormrex wrote:

hey there,

 

(ssget (list '(0 . "text,mtext") (cons 50 (cdr (assoc 50 (entget (car (entsel "\nPick angle's sample M/Text :")))))))) 

 


 

0 Likes
Message 14 of 17

saqib_tipa
Advocate
Advocate

 

@paullimapa 

Thank you. for the code.

 


@paullimapa wrote:

or how's about this version:

 

(sssetfirst nil (ssget "X" (list '(0 . "text,mtext") (cons 50 (cdr (assoc 50 (entget (car (entsel "\nPick angle's sample M/Text :")))))))))

 


 

0 Likes
Message 15 of 17

saqib_tipa
Advocate
Advocate

 

@ec-cad 

Thank you for the code, it looks like it works in changed UCS. Can you please add tolerance of 5 degrees in it. 

Thank you.

 

 

Something like this seems to do it.

(setq ss (ssget "_+.:S:E" '((0 . "text,mtext"))))
(if ss
(progn
(setq ang (cdr (assoc 50 (entget (ssname ss 0))))); angle in radians
(setq selection (ssget "X" (list (cons 50 ang))))
); progn
); if

 

ECCAD


 

0 Likes
Message 16 of 17

Kent1Cooper
Consultant
Consultant

@saqib_tipa wrote:

....

How to add tolerance for example up to 5 degrees as you asked before.





I was afraid of that.  That is going to require not just plugging the rotation entry into the selection filter, but actually extracting the rotation and doing some calculations with it.  The biggest challenge is when the rotation is within the tolerance of 0°.  It's not hard to calculate that if the source rotation is 45°, you want to accept any other Text/Mtext objects that have rotations between 40° and 50°.  You want things with rotation that is 40° or more and also 50° or less.  But if the source is 2°, you want from 357° to 7°, and compared in a different way, because it's not between those two values, but only outside those two within the 360° range -- 7° or less, or [not and this time] 357° or more.  Not that it couldn't be worked out, but some working out is needed.

Kent Cooper, AIA
0 Likes
Message 17 of 17

saqib_tipa
Advocate
Advocate

 

@Kent1Cooper 

Thank you for reply. I see it is difficult to handle some 0-degree angle in the code. It is ok no problem. I thought it was not that difficult.  Thank you for your explanation.

Thank you.

0 Likes