Jump to content
whosa

Round Down 0.50

Recommended Posts

whosa

Hi Guys,

 

i would like to add a round down 0.50 to this lisp.

 

 ex. 15.15 = 15.00 -  15.60=15.50

 

Exception <0.50 slould be =0 .50 (not 0.00)

 

It is possible?

 

Someone can help me?

 

 

many thanks

(defun C:but ( / e o p d )
	(setvar 'errno 0)
	(and
		vlax-get-acad-object
		(while (/= 52 (getvar 'errno))
			(setq e (car (nentsel "\nSelect text to fill: ")))
			(cond 
				((= 7 (getvar 'errno))
					(princ "\nMissed, try again.") (setvar 'errno 0)
				)
				((and e (not (vlax-property-available-p (setq o (vlax-ename->vla-object e)) 'TextString)))
					(princ "\nThis is not a text object.") (setq e nil)
				)
				((and o (eq (vla-get-Lock (vla-item (vla-get-Layers (vla-get-ActiveDocument (vlax-get-acad-object))) (vla-get-Layer o))) :vlax-true))
					(princ "\nThis object is on a locked layer.") (setq e nil)
				)
				(e
					(if 
						(and 
							(setq p (getpoint "\nSpecify first point: ")) 
							(cadr (setq p (cons p (list (getpoint "\nSpecify second point: " p)))))
							(setq d (rtos (abs (/ (apply '- (mapcar 'last (mapcar '(lambda (x) (trans x 1 0)) p))) 1000.)) 2 2))
						)
						(cond
							( (= "ATTDEF" (cdr (assoc 0 (entget e)))) (vla-put-TagString o d) )
							( T (vla-put-TextString o d) )
						)
					)
					(setvar 'errno 52)
				)
				(T nil)
			)
		)
	)
	(princ)
);| defun |; (or vlax-get-acad-object (vl-load-com)) (princ)

 

Share this post


Link to post
Share on other sites
whosa

thanks for your reply. I found this fix but i don't understand how i can add it on my lisp.

 

Share this post


Link to post
Share on other sites
Lee Mac
1 hour ago, whosa said:

thanks for your reply. I found this fix but i don't understand how i can add it on my lisp.

 

 

Copy the function definition to the end of your code, and then change this:

(setq d (rtos (abs (/ (apply '- (mapcar 'last (mapcar '(lambda (x) (trans x 1 0)) p))) 1000.)) 2 2))

To:

(setq d (rtos (LM:rounddown (abs (/ (apply '- (mapcar 'last (mapcar '(lambda (x) (trans x 1 0)) p))) 1000.)) 0.5) 2 2))

 

@Emmanuel Delay Thanks for the recommendation :thumbsup:

Edited by Lee Mac
  • Like 2

Share this post


Link to post
Share on other sites
whosa
25 minutes ago, Lee Mac said:

 

Copy the function definition to the end of your code, and then change this:


(setq d (rtos (abs (/ (apply '- (mapcar 'last (mapcar '(lambda (x) (trans x 1 0)) p))) 1000.)) 2 2))

To:


(setq d (rtos (LM:rounddown (abs (/ (apply '- (mapcar 'last (mapcar '(lambda (x) (trans x 1 0)) p))) 1000.)) 0.5) 2 2))

 

@Emmanuel Delay Thanks for the recommendation :thumbsup:

 

 

Thanks, work really well.

 

I would like to ask you:

 

  1. Is it possible to round UP just when the value is <0.50?
  2. Is it possible to get a planar distance between two point insted the height value using the same structure of the lisp?

 

Thank a lot.

 

Share this post


Link to post
Share on other sites
Lee Mac
4 hours ago, whosa said:

1. Is it possible to round UP just when the value is <0.50

 

Copy the definition for my LM:roundup function to the end of your code, and then change:

(setq d (rtos (LM:rounddown (abs (/ (apply '- (mapcar 'last (mapcar '(lambda (x) (trans x 1 0)) p))) 1000.)) 0.5) 2 2))

to:

(setq d (abs (/ (apply '- (mapcar 'last (mapcar '(lambda (x) (trans x 1 0)) p))) 1000.))
      d (rtos ((if (< d 0.5) LM:roundup LM:rounddown) d 0.5) 2 2)
)

 

4 hours ago, whosa said:
  1. Is it possible to get a planar distance between two point insted the height value using the same structure of the lisp?

 

Copy the function definition for the main program, change the syntax of the copied definition from c:but to c:somethingelse, and change:

(setq d (abs (/ (apply '- (mapcar 'last (mapcar '(lambda (x) (trans x 1 0)) p))) 1000.))
      d (rtos ((if (< d 0.5) LM:roundup LM:rounddown) d 0.5) 2 2)
)

to:

(setq d (abs (/ (apply 'distance (mapcar '(lambda ( x ) (list (car x) (cadr x))) p)) 1000.))
      d (rtos ((if (< d 0.5) LM:roundup LM:rounddown) d 0.5) 2 2)
)

This will calculate the 2D distance between the points in the UCS plane.

  • Like 1

Share this post


Link to post
Share on other sites
whosa

Thanks a lot. You are the guru of the LIPS.

 

I will try it on Monday.

 

Thanks

Share this post


Link to post
Share on other sites
Lee Mac

You're most welcome and thank you for your compliments - let me know how you get on.

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


×
×
  • Create New...