Lisp

Lisp

Anonymous
Not applicable
1,355 Views
9 Replies
Message 1 of 10

Lisp

Anonymous
Not applicable

HI THERE , I WANNA ASK ABOUT A LISP THAT CAN approach NUMBERS IN A MTEXT CONTENT I HAVE A LOT OF NUMBERS LIKE 2.17 ,2.18 , 2.19 AND I WANNA TO APPROACH IT TO 2.20 JUST BY CLICKING THEM ALL ,,, IS THERE SOME LISP LIKE THAT ,,,, I HOPE THX  😉

0 Likes
Accepted solutions (1)
1,356 Views
9 Replies
Replies (9)
Message 2 of 10

ВeekeeCZ
Consultant
Consultant
If the mtext is plain, meaning without formatting, try
(cdr (assoc 1 (entget (car (entsel)))))

Next time better post some dwg example...
Message 3 of 10

Kent1Cooper
Consultant
Consultant

@Anonymous wrote:

.. I HAVE A LOT OF NUMBERS LIKE 2.17 ,2.18 , 2.19 AND I WANNA TO APPROACH IT TO 2.20 JUST BY CLICKING THEM ALL ,,,


A Search of this Forum will find various routines for rounding text content representing numbers.  Questions arise:  Do you want to round them to the nearest multiple of 0.1, whether up or down [whichever is closer]?  Or to the next multiple always upward from their current value [there was a request like that here recently]?  Or some other criterion?  Do you need that trailing zero, or would 2.2 be enough in your example values?

Kent Cooper, AIA
0 Likes
Message 4 of 10

Ranjit_Singh
Advisor
Advisor
Accepted solution

Try below for example. It will round up or down based on the value of your number.  If the mtext has any alphabetic characters then it won't work. You may need to post an example as suggested in post 2.

;;Ranjit Singh
(defun c:somefunc  (/ val etdata)
 (mapcar '(lambda (x)
           (and (distof (setq val (cdr (assoc 1 (setq etdata (entget x))))))
                (entmod (subst (cons 1 (rtos (atof (rtos (atof val) 2 1)) 2 2)) (assoc 1 etdata) etdata))))
         (vl-remove-if 'listp (mapcar 'cadr (ssnamex (ssget '((0 . "TEXT,MTEXT"))))))))
Message 5 of 10

Anonymous
Not applicable

I NEED TO approach numbers like 2.15 to 2.20 & 2.12 to 2.10 which mean nearst 0.5 

0 Likes
Message 6 of 10

ademercan1
Advocate
Advocate
;2.16 -> 2.15 / 2.18 -> 2.20

(defun c:tx (/ dc sl dz rl k1 k2 nm m) (vl-load-com)
  (if (and (ssget '((0 . "*text"))) (setq dc (vlax-get (vlax-get-acad-object)
        'activedocument) sl (vla-get-activeselectionset dc)
          dz (getvar 'dimzin) rl 0.05))
    (progn (setvar 'dimzin 0) (vla-startundomark dc)
      (vlax-for m sl
        (vla-put-TextString m (rtos (if (>= (- (setq k2 (+ (setq k1 (- (setq nm (atof
          (vla-get-TextString m))) (rem nm rl))) rl)) nm) (- nm k1)) k1 k2) 2 2)))
      (vla-endundomark dc) (vla-delete sl) (setvar 'dimzin dz)
    )
  ) (prin1)
)
0 Likes
Message 7 of 10

Kent1Cooper
Consultant
Consultant

@Anonymous wrote:

I NEED TO approach numbers like 2.15 to 2.20 & 2.12 to 2.10 which mean nearst 0.5 


I think you mean to the nearest multiple of 0.1.  @ademercan1's code in Post 6 is apparently to round to the nearest multiple of 0.05, but if that is your intent, 2.15 would not need to be changed to 2.20.

Kent Cooper, AIA
0 Likes
Message 8 of 10

ademercan1
Advocate
Advocate
(defun c:tx (/ dc sl dz rl nm m) (vl-load-com)
  (if (and (ssget '((0 . "*text"))) (setq dc (vlax-get (vlax-get-acad-object)
        'activedocument) sl (vla-get-activeselectionset dc)
          dz (getvar 'dimzin) rl 0.05))
    (progn (setvar 'dimzin 0) (vla-startundomark dc)
      (vlax-for m sl
        (vla-put-TextString m (rtos (+ (- (setq nm (atof (vla-get-TextString m)))
          (rem nm rl)) rl) 2 2)))
      (vla-endundomark dc) (vla-delete sl) (setvar 'dimzin dz)
    )
  ) (prin1)
)
0 Likes
Message 9 of 10

Ranjit_Singh
Advisor
Advisor

@Anonymous wrote:

I NEED TO approach numbers like 2.15 to 2.20 & 2.12 to 2.10 which mean nearst 0.5 



Isn't that what the code in post 4 does?

0 Likes
Message 10 of 10

Ranjit_Singh
Advisor
Advisor

@Kent1Cooper wrote:

@Anonymous wrote:

I NEED TO approach numbers like 2.15 to 2.20 & 2.12 to 2.10 which mean nearst 0.5 


I think you mean to the nearest multiple of 0.1.  @ademercan1's code in Post 6 is apparently to round to the nearest multiple of 0.05, but if that is your intent, 2.15 would not need to be changed to 2.20.


I agree. I believe OP intends to round to the tenth but says five tenths for some reason.

0 Likes