Scale calculation problem

rseyda

Usenet Archive
Joined
Aug 13, 2003
Messages
9
Reaction score
0
I have a statement in a lisp routine that is supposed to scale items based on user input scale factors. The different scale factors are 1, 4, 8, 12, 16, 24, 32, 48 and 96. The statement works when scaling up (i.e. from 4 to 32, etc...). But when I try to scale down (i.e. 32 to 4, etc...) it still scales the objects up instead of down. Could someone look at this lisp to see what is wrong?

Thanks,

(defun c:scd ( / xfrom xto xinsert xdetail xretrieve sf) (setq xdetail (ssget)) (setq xfrom (getint "\nCurrent scale factor: ")) (setq xto (getint "\nNew scale factor: ")) (if (> xfrom xto)(setq sf (/ xfrom xto))(setq sf (/ xto xfrom))) (setq xretrieve (getpoint "\nScale from box : ")) (setq xinsert (getpoint "\nScale to box : ")) (command "scale" xdetail "" xretrieve sf) (command "move" xdetail "" xretrieve xinsert)
)
 
Watch out for division of integers

(/ 3 2)

returns 1

Try:
(/ 3 (float 2))
(/ 3 2.)

-David
 
You're forcing it to always enlarge, by changing the ratio depending on whether xfrom > xto. You don't need that, the ratio should always be xto/xfrom. If you're going from 32 to 8, you need to divide xto/xfrom = 8/32=1/4. From 8 to 32 would be xto/xfrom=32/8=4.

rseyda said:
I have a statement in a lisp routine that is supposed to scale items based
on user input scale factors. The different scale factors are 1, 4, 8, 12, 16, 24, 32, 48 and 96. The statement works when scaling up (i.e. from 4 to 32, etc...). But when I try to scale down (i.e. 32 to 4, etc...) it still scales the objects up instead of down. Could someone look at this lisp to see what is wrong?
 
Yeah! That's the ticket!
Also, look at adding (Float X) to 1 of the numbers (like David Bethel said above...)
 
Just use (getreal ...) instead of (getint ...) to obtain your inputs. That way you'll be dividing reals instead of integers.
___

rseyda said:
So what would be the proper code in this matter then? Don't I need some
kind of IF statement to determine which number is higher so I can then tell it which way to divide?
 

Latest threads

Back
Top