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,383 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,384 Views
23 Replies
Replies (23)
Message 2 of 24

ВeekeeCZ
Consultant
Consultant
Accepted solution

It's fairly easy, you should learn at least these basics.

 

(vl-load-com)

(defun c:RoundUpTo ( / s i e v)
  (if (setq s (ssget "_:L" '((0 . "TEXT"))))
    (repeat (setq i (sslength s))
      (if (setq e (ssname s (setq i (1- i)))
		v (getpropertyvalue e "TextString")
		v (atof (vl-list->string (vl-remove-if-not '(lambda (x) (or (= 46 x) (< 47 x 58))) (vl-string->list v))))
		v (cadr (member v (vl-sort (cons v '(6 10 16 32 64 100 125 160 200 250 300 415 600 800 1000 1200)) '<))))
	(setpropertyvalue e "TextString" (rtos v 2 0)))))
  (princ)
  ) 

 

Message 3 of 24

Anonymous
Not applicable

Excellent Sir,

 

Is there any other option to get the list from user selection from AutoCAD instead of mentioning in lisp code like below

(6 10 16 32 64 100 125 160 200 250 300 415 600 800 1000 1200)

 because some times the values may change as per AutoCAD text values.

Selection like below.

Roundingup Values.jpg

0 Likes
Message 4 of 24

Anonymous
Not applicable

Dear Sir,

 

Instead of feeding standard values in lisp code, Can we feed the standard values by selection method from AutoCAD like shown in below snapshot.

 

Roundingup Values.jpg 

0 Likes
Message 5 of 24

john.uhden
Mentor
Mentor

Yes, of course.

You could either provide a dialogue with a list box or you could actually create a list of text in the drawing for the user to select one.  Either way, though, you can't avoid using AutoLisp.

John F. Uhden

Message 6 of 24

Anonymous
Not applicable

Thank you Sir.

 

Can you Please help me?

0 Likes
Message 7 of 24

pbejse
Mentor
Mentor

@Anonymous wrote:

Instead of feeding standard values in lisp code, Can we feed the standard values by selection method from AutoCAD like shown in below snapshot. 


You mean NOT hard-codfing the values on a lisp routine, as those values are not always the same? and show those as allowable values on a list box?

 

 

 

0 Likes
Message 8 of 24

Anonymous
Not applicable

Yes Sir,

 

The standard values are not fixed values, those are some times variable values. That's why I asked selection input instead of mentioning in lisp code.

0 Likes
Message 9 of 24

ВeekeeCZ
Consultant
Consultant
Accepted solution
(vl-load-com)

(defun c:RoundUpToStandards ( / z s i e v)
  (if (and (princ "\nStandards, ")
	   (setq z (ssget "_:L" '((0 . "TEXT"))))
	   (setq z (apply 'list (mapcar '(lambda (x) (atoi (cdr (assoc 1 (entget x)))))
					(vl-remove-if 'listp (mapcar 'cadr (ssnamex z))))))
	   (princ "\nActual values, ")
	   (setq s (ssget "_:L" '((0 . "TEXT"))))
	   )
    (repeat (setq i (sslength s))
      (if (setq e (ssname s (setq i (1- i)))
		v (getpropertyvalue e "TextString")
		v (atof (vl-list->string (vl-remove-if-not '(lambda (x) (or (= 46 x) (< 47 x 58))) (vl-string->list v))))
		v (cadr (member v (vl-sort (cons v z) '<))))
	(setpropertyvalue e "TextString" (rtos v 2 0)))))
  (princ)
  )
Message 10 of 24

pbejse
Mentor
Mentor

@Anonymous wrote:

The standard values are not fixed values, those are some times variable values. That's why I asked selection input instead of mentioning in lisp code.


 

First of all, don't call me sir 🙂

 

Secondly, are the "Standard Values" column always available for selection?  I dont see the relation between "User Selection Values" and  the "Output Values" or should i jsut say UPDATED SV at all.  Do you already have a lisp code that shows a list box for SV and USV? what are you going to use the output values for anyway?   Were the  suggestions of @ВeekeeCZ  helped you in any way? Why did the chicken cross the road?

 

EDIT: Apprarently it did help, I did not even get to finish my post 😄

 

Message 11 of 24

Anonymous
Not applicable

Thanks a lot Sir, Working in a nice manner.

0 Likes
Message 12 of 24

pbejse
Mentor
Mentor

@ВeekeeCZ wrote:
...
		v (cadr (member v (vl-sort (cons v z) '<))))
...	

Now i get it 😄

2.1a   -> 6
a8.54  ->10

 

That is very clever @ВeekeeCZ .

 

0 Likes
Message 13 of 24

john.uhden
Mentor
Mentor
Rounding up reminds me of that scene in *The Mask* with Jim Carey as
Stanley Ipkus. He's got his POS car at a repair shop and the mechanic is
writing down each item of repair. Stanley says, "But there are no
numbers!" To which the mechanic replies "

John F. Uhden

0 Likes
Message 14 of 24

pbejse
Mentor
Mentor
Accepted solution

@Anonymous wrote:

Excellent Sir,

 

Is there any other option to get the list from user selection from AutoCAD instead of mentioning in lisp code ..

...


One quick way is to have an external file as the source for the range of numbers, either on the same folder as the drawing, or if you have a standard folder structure and place the source file there. 

 

Had time to burn.

(defun c:RoundUpFromRange ( / _L2S 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))
  )

(if (and
	(setq range nil
	      rangeSource
	       (findfile (strcat (getvar 'dwgprefix)
				 "Range for this project.txt")))
	(setq range
	       (progn
		 (setq opf (open rangeSource "r"))
		 (while	(setq a (read-line opf))
		   (setq range (cons (atoi 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 0)))
	  	)
	  )
  (princ)
  )

HTH

 

 

Message 15 of 24

pbejse
Mentor
Mentor

@john.uhden wrote:
 To which the mechanic replies "

"There will be", Hey I have to look that up, that was a long time ago John  😄 

The Mask 

 

 

0 Likes
Message 16 of 24

Anonymous
Not applicable

Thanks a lot for extra feature, by keeping the text file inside the same drawing path.

 

Instead of keeping in same drawing path, can we make an option to select file path from user end?

0 Likes
Message 17 of 24

pbejse
Mentor
Mentor

@Anonymous wrote:

Thanks a lot for extra feature, by keeping the text file inside the same drawing path.

 

Instead of keeping in same drawing path, can we make an option to select file path from user end?


Refer to updated attached file [ RoundUpFromRange.LSP ]

Snippet:

..
	(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))
		       )
..

HTH

 

0 Likes
Message 18 of 24

Anonymous
Not applicable

Thanks a lot,

 

working nice, except one thing

 

If input values having digits like 6.5, 10.25, 16.5, 32.5, Then output is coming like only 6, 10, 16, 32. 

 

The lisp command not taking any digits.

0 Likes
Message 19 of 24

pbejse
Mentor
Mentor

@Anonymous wrote:

Thanks a lot,

 

working nice, except one thing

 

If input values having digits like 6.5, 10.25, 16.5, 32.5, Then output is coming like only 6, 10, 16, 32. 

 

The lisp command not taking any digits.


Really @Anonymous ?  What did we say about being clear on what you are requesting.  Reminder 

 

Add the sub and edit the line that matches the  line shown below [ between ... ]

(setq RealorInt (lambda  (n)
      (if (zerop (rem n 1)) 0 2)
       )
      )
....
(setpropertyvalue e "TextString" (rtos v 2 (RealorInt v)))
....

 HTH

 

0 Likes
Message 20 of 24

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

John F. Uhden

0 Likes