Rounding up selected values to user input standard values (Please see attachment

Rounding up selected values to user input standard values (Please see attachment

Anonymous
Not applicable
2,386 Views
23 Replies
Message 1 of 24

Rounding up selected values to user input standard values (Please see attachment

Anonymous
Not applicable

Hi Experts,

 

I need a favor, to update the selected texts to standard values mentioned by user.

 

Please have a look on attached dwg.

 

Advanced Thank you all.

0 Likes
Accepted solutions (3)
2,387 Views
23 Replies
Replies (23)
Message 21 of 24

pbejse
Mentor
Mentor

@john.uhden wrote:
Instead of that myopic RealorInt function, I think it's simpler...
Command: (type 3) INT
Command: (type 3.0) REAL

 

That also is true, but regardless of what method was used, you still need the output of rtos precision argument.

type

 

(if (Eq (type n) 'INT) 0 2)

 

rem

 

(if (zerop (rem n 1)) 0 2)

 

I  usualy create a sub that i re-use and include on my toolbox whenever needed. 🙂

 

0 Likes
Message 22 of 24

john.uhden
Mentor
Mentor
Correct. I was just pointing out that a rem of zero does not necessarily
mean an integer.

John F. Uhden

0 Likes
Message 23 of 24

pbejse
Mentor
Mentor

@john.uhden wrote:
Correct. I was just pointing out that a rem of zero does not necessarily
mean an integer.

 

Correct thumbsup.gif,

Guess i'm more into using math for evaluation since i switch from one program language to another. 

Hoepfully the OP would not include the trailing zeros on the source file. 20.00

But you right about zero. 

 

Taking John's advice.

 

(defun c:RoundUpFromRange ( / _L2S RealorInt range rangeSource opf a i s ent v)
;;		pBe May 2020		;;

(defun _L2S (s a)
  ((lambda (v)
     (setq s (vl-string-right-trim v s)
	   s (vl-string-Left-trim v s)))
    (strcat "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz" a))
  )

(setq RealorInt (lambda  (n)
      (if (Eq (type n) 'INT) 0 2)
       )
      )
  

(if (and
	(setq range nil
	      rs (getfiled "Select Source file"
				    (if	rs (vl-filename-directory rs)
				      (getvar 'dwgprefix)) "txt" 16)
	      )
	(setq range
	       (progn
		 (setq opf (open rs "r"))
		 (while	(setq a (read-line opf))
		   (if (numberp (setq a (Read a)))
		   (setq range (cons a range)))
		 )
		 (close opf)
		 (reverse range))
		       )	
	(princ "\nActual values, ")
	(setq s (ssget "_:L" '((0 . "TEXT"))))
	)
 (repeat (setq i (sslength s))
   	(if
	  (setq	e (ssname s (setq i (1- i)))
		v   (atof (_L2S (getpropertyvalue e "TextString") ""))
		v   (Vl-some '(lambda (n m)
				(cond
				  ((<= v n) n)
				  ((<= n v m) m)
				)
			      ) range (Cdr range)
		    )
	  )
	  (setpropertyvalue e "TextString" (rtos v 2 (RealorInt v))))
	  	)
	  )
  (princ)
  )

 

 

0 Likes
Message 24 of 24

Sea-Haven
Mentor
Mentor

A front end. The options are dynamic limited by screen size row spacing reduces for more selections.

 

screenshot207.png

0 Likes