Rounding down dimension values

Rounding down dimension values

curro.aguilera
Participant Participant
4,823 Views
31 Replies
Message 1 of 32

Rounding down dimension values

curro.aguilera
Participant
Participant

Hi!

Please help me, I would like a LISP to round down existing dimension values, for example:

5,87-> 5,80

6,79->6,70

 

One important thing is that the value the lisp would get to round is the real value of the dimension, in case that dimension changes in the future so I can run the lisp again.

 

I've searched a lot and I only found a lisp to round up, and it's in feets&inches.

 

Thank you very much!

0 Likes
Accepted solutions (1)
4,824 Views
31 Replies
Replies (31)
Message 21 of 32

john.uhden
Mentor
Mentor
@Kent1Cooper
The idea was just something that oozed out of my head, so I thought I would
write it down. Then I found that it actually seemed to work, so I posted
it. My apologies if it offended you or anyone else.

John F. Uhden

0 Likes
Message 22 of 32

Kent1Cooper
Consultant
Consultant

No offense -- I found it interesting that it might eliminate the workaround of forcing the value up a little as a way of preventing rounding "exact" values down too far.

Kent Cooper, AIA
0 Likes
Message 23 of 32

john.uhden
Mentor
Mentor
@Kent1Cooper
It's not good enough anyway...

Command: (rounddown "5.009000000" 2)
"5.00"

Shouldn't the answer be "5.01?"
I dunno. It's been a stressful day.

John F. Uhden

0 Likes
Message 24 of 32

Kent1Cooper
Consultant
Consultant

@john.uhden wrote:
....
Command: (rounddown "5.009000000" 2)
"5.00"
Shouldn't the answer be "5.01?"
....

Not in this Topic -- that's what the "down" part is about.  See the topic title and Message 1.

Kent Cooper, AIA
0 Likes
Message 25 of 32

john.uhden
Mentor
Mentor

It doesn't need to be a string as the (read ...) operation converts the string to a real.

So it could be:

;; Where object is the dimension vla-object
(defun rounddown (object places)
  (rtos (/ (fix (* (expt 10 places)(vlax-get object "measurement")))(expt 10.0 places)) 2 places)
)

Architectural units would probably require a modified approach.

Anyway, be sure that DIMZIN=1

John F. Uhden

0 Likes
Message 26 of 32

Kent1Cooper
Consultant
Consultant

@john.uhden wrote:

It doesn't need to be a string as the (read ...) operation converts the string to a real.

So it could be:

;; Where object is the dimension vla-object
(defun rounddown (object places)
  (rtos (/ (fix (* (expt 10 places)(vlax-get object "measurement")))(expt 10.0 places)) 2 places)
)

....


Again, that's exactly what the code at the end of Message 10 does.  But see Messages 15 through 17, and the "fix" they did in Message 17 to prevent rounding down too far for "exact" values that turn out not to be so exact.

 

I think [untested] that the adjustment in Message 20 should obviate the need for that "fix," by pulling the value as a text string, not to all the decimal places in the measurement value, then (read)ing that to get the value without the risk of its being rounded down too far.

Kent Cooper, AIA
0 Likes
Message 27 of 32

curro.aguilera
Participant
Participant
Hi @Kent1Cooper, thanks you again!
That seems to work perfectly! My workaround was working but it could lead to wrong values in some specific cases. Your solution seems much better. I'm gonna try it a little more.
Thank you very much, Kent!
0 Likes
Message 28 of 32

Kent1Cooper
Consultant
Consultant

And thanks to @john.uhden for the string-based concept.

Kent Cooper, AIA
0 Likes
Message 29 of 32

john.uhden
Mentor
Mentor

Okay, okay.  This isn't nuclear physics.

Presuming clearly that AutoCAD treats the measurement just like the rtos function, then we do the same...

;; This converts the actual measurement into a string before rounding.
;; Where object is the dimension vla-object
(defun rounddown (object places)
  (rtos (/ (fix (* (expt 10 places)(read (rtos (vlax-get object "measurement") 2 (1+ places)))))(expt 10.0 places)) 2 places)
)

John F. Uhden

0 Likes
Message 30 of 32

Kent1Cooper
Consultant
Consultant

That's exactly the VLA-object-based equivalent of Message 20's (getpropertyvalue) entity-name-based approach.

Kent Cooper, AIA
0 Likes
Message 31 of 32

john.uhden
Mentor
Mentor
@Kent1Cooper,
I am happy to hear that.
I have not as yet used getpropertyvalue as my mind is still geared to
supporting 2002 add-ons.

John F. Uhden

0 Likes
Message 32 of 32

Kent1Cooper
Consultant
Consultant

@john.uhden wrote:
.... I have not as yet used getpropertyvalue as my mind is still geared to supporting 2002 add-ons.

I don't know in which version the (getpropertyvalue)/(setpropertyvalue) scheme came in, but I like them because they take mere entity names, eliminating the VLA-object conversion for a lot of purposes [but not for everything that VLA objects are good for, so those still have their uses].

Kent Cooper, AIA
0 Likes