Scale calculation problem

Discussion in 'AutoCAD' started by rseyda, Dec 31, 2003.

  1. rseyda

    rseyda Guest

    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)
    )
     
    rseyda, Dec 31, 2003
    #1
  2. rseyda

    David Bethel Guest

    Watch out for division of integers

    (/ 3 2)

    returns 1

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

    -David
     
    David Bethel, Dec 31, 2003
    #2
  3. rseyda

    Tom Smith Guest

    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.

    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?
     
    Tom Smith, Dec 31, 2003
    #3
  4. rseyda

    Thomas Smith Guest

    Yeah! That's the ticket!
    Also, look at adding (Float X) to 1 of the numbers (like David Bethel said
    above...)
     
    Thomas Smith, Dec 31, 2003
    #4
  5. rseyda

    Paul Turvill Guest

    Just use (getreal ...) instead of (getint ...) to obtain your inputs. That
    way you'll be dividing reals instead of integers.
    ___

    kind of IF statement to determine which number is higher so I can then tell
    it which way to divide?
     
    Paul Turvill, Jan 7, 2004
    #5
Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.