Viewport Scale

Discussion in 'AutoCAD' started by John Georgiev, Jun 28, 2004.

  1. Is there easy way to get the viewport scale in routine (instead of using the
    Express VPSCALE, which BTW I couldn't make work in AutoLisp). All I need is
    the scale factor (e.g. 24 for 1/2"=1'-0" or 10 for 1:10 etc.) and then I can
    use it to run specific command depending of it.
    Thanks.
    John
     
    John Georgiev, Jun 28, 2004
    #1
  2. John Georgiev

    T.Willey Guest

    T.Willey, Jun 28, 2004
    #2
  3. Thanks Tim, but I need to have the scale of the viewport currently active
    (not in paper space). See how Express VPSCALE works - this is close to what
    I need.
    John
     
    John Georgiev, Jun 28, 2004
    #3
  4. Tim, I found this:
    (defun xpfact ()
    (caddr (trans '(0 0 1) 2 3))
    )
    and by description it should do exactly what I want, but when I tested it
    returned strange results (for viewport 1:20 it returned 0.05, for 1/2"=1'-0"
    it returned 0.0416667 etc.). Do you know how to set it to work right?
    Thanks.
     
    John Georgiev, Jun 28, 2004
    #4
  5. Sorry about the previews stupid question. the results are OK - simply
    1/scale factor.
    John
     
    John Georgiev, Jun 28, 2004
    #5
  6. John Georgiev

    T.Willey Guest

    Looks like once you get that value you have to do some math work. This is the ending to one that I wrote. Just call the answer you get from your function "eq1". With this one you have to have your units set to the one you are working one. That is what "ut1" equals.

    (cond
    ((or (= ut1 0) (= ut1 1))
    (setq eq2 (* 12 eq1))
    (setq eq3 (rtos eq2 4 5))
    (setq tx1 (strcat "\n"eq3 "= 1'-0\""))
    );; when units are set to inches
    ((= ut1 2)
    (setq eq2 (/ 1 eq1))
    (setq eq3 (rtos eq2 5))
    (setq tx1 (strcat "\n1\" = "eq3"\'-0\""))
    );; when units are set to feet.
    ((or (= ut1 4) (= ut1 5) (= ut1 6) (= ut1 7) (= ut1 12) (= ut1 14) (= ut1 15) (= ut1 16) (= ut1 17))
    (cond
    ((= ut1 4)
    (setq tx2 "MILLIMETERS")
    )
    ((= ut1 5)
    (setq tx2 "CENTIMETERS")
    )
    ((= ut1 6)
    (setq tx2 "METERS")
    )
    ((= ut1 7)
    (setq tx2 "KILOMETERS")
    )
    ((= ut1 12)
    (setq tx2 "NANOMETERS")
    )
    ((= ut1 14)
    (setq tx2 "DECIMETERS")
    )
    ((= ut1 15)
    (setq tx2 "DECAMETERS")
    )
    ((= ut1 16)
    (setq tx2 "HECTOMETERS")
    )
    ((= ut1 17)
    (setq tx2 "GIGAMETERS")
    )
    )
    (setq eq2 (/ 1 eq1))
    (setq eq3 (rtos eq2 5))
    (setq tx1 (strcat "\n1 = "eq3" "tx2))
    );; when units are set to a metric measurement.

    )

    Try it and see if it works for you.

    Tim
     
    T.Willey, Jun 28, 2004
    #6
  7. Thanks, Tim
    For me the small one works fine.
    Generally the story is this:
    I have setup functions called MODE<scale factor> (e.g. MODE20 for 1:20 or
    MODE24 for 1/2"=1'-0" etc.). The function for paperspace is PSMODE. All
    setup functions are in the company's *.mnl file. If in one layout we have
    two or more viewports with different scales I want to make sure everything
    drawn in these viewports (dimensions, text, dash lines, blocks etc.) will
    look the same on the paper. So when the drafter switch between the viewports
    he have to click on the button with the right scale to set it right. But
    sometimes the guys forgetting to do this and we see the problem after it is
    printed (especially when the scales are close). This is why I decided to
    automate this. The result so far is this (thanks to Doug Broad for the
    reactor part):

    (if (null db:svr)
    (setq db:svr (vlr-sysvar-reactor
    '("CVPORT")
    '(:)vlr-sysvarchanged . setscale))
    )
    )
    )
    (defun setscale (r data)
    (if (member (car data) (vlr-data r))
    (cond
    ((> (getvar "cvport") 1)
    (setq xpf (rtos (/ 1 (caddr (trans '(0 0 1) 2 3))) 2 0))
    (setq setsc (strcat "mode" xpf))
    (setsc)
    )
    ((= (getvar "cvport") 1)
    (psmode)
    )
    )
    )
    )

    The only problem here is that it doesn't recognize the MODE functions (foe
    example: ; error: bad function: "mode20") even that they are loaded by the
    *.mnl file and are working fine from the command row (when I type
    (mode20) ). I don't remember what was the trick to make them work.
    John
     
    John Georgiev, Jun 28, 2004
    #7
  8. John Georgiev

    T.Willey Guest

    The reason it won't work is because it is trying to run a function that is labeled "mode48" (with quotes) instead or mode48. I'm note sure how to pass it in code, I have tried a couple things but haven't found a good result.

    If anyone know of a way to do it please post. I will also keep working on it and see if I can find a way, if you find one first please post how you did it.

    Thanks,
    Tim
     
    T.Willey, Jun 28, 2004
    #8
  9. Tim I will start new discussion about this issue. I'm not sure that the
    quotes are the only problem, because the function PSMODE at the end of the
    routine is defined already and the function name doesn't come from string.
    I got this error:
    error: no function definition: PSMODE
    Again - when I type it on the command row:
    Command: (psmode)
    everything is OK and it runs.
    John
    labeled "mode48" (with quotes) instead or mode48. I'm note sure how to pass
    it in code, I have tried a couple things but haven't found a good result.
    it and see if I can find a way, if you find one first please post how you
    did it.
     
    John Georgiev, Jun 29, 2004
    #9
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.