Speed suggestions?

Discussion in 'AutoCAD' started by C Witt, Jul 16, 2004.

  1. C Witt

    C Witt Guest

    I have attached a lisp we have been using for converting existing dim
    styles..

    I've been trying to think of a way to speed it up.. but so far i'm
    drawing a blank. suggestions welcome.

    TIA.

    (defun switch ()
    ;(princ "\nStarting switch")
    (setq E (ssget "X" (list (cons -4 "<OR")(cons 0 "DIMENSION")(cons 0 "LEADER")(cons -4 "OR>"))))
    (setq COUNT 0)
    (if (/= E nil)(setq EN (ssname E COUNT)))
    (if (/= E nil)(setq EL (entget EN))(setq EN nil))
    (WHILE (/= EN nil)
    (setq EL (entget EN))
    (setq CURDIM (cdr (assoc 3 EL)))
    (setq DTYPE (cdr (assoc 0 EL)))
    (if (or (= CURDIM "AT&T1-16")(= CURDIM "TRKIMP1-16")(= CURDIM "TRK1-16"))(progn(setq NEWDIM "1-16'' - 1FT")(UPTONEW)))
    (if (or (= CURDIM "AT&T3-32")(= CURDIM "TRKIMP3-32")(= CURDIM "TRK3-32"))(progn(setq NEWDIM "3-32'' - 1FT")(UPTONEW)))
    (if (or (= CURDIM "AT&T1-8")(= CURDIM "TRKIMP1-8")(= CURDIM "TRK1-8"))(progn(setq NEWDIM "1-8'' - 1FT")(UPTONEW)))
    (if (or (= CURDIM "AT&T3-16")(= CURDIM "TRKIMP3-16")(= CURDIM "TRK3-16"))(progn(setq NEWDIM "3-16'' - 1FT")(UPTONEW)))
    (if (or (= CURDIM "AT&T1-4")(= CURDIM "TRKIMP1-4")(= CURDIM "TRK1-4"))(progn(setq NEWDIM "1-4'' - 1FT")(UPTONEW)))
    (if (or (= CURDIM "AT&T3-8")(= CURDIM "TRKIMP3-8")(= CURDIM "TRK3-8"))(progn(setq NEWDIM "3-8'' - 1FT")(UPTONEW)))
    (if (or (= CURDIM "AT&T1-2")(= CURDIM "TRKIMP1-2")(= CURDIM "TRK1-2"))(progn(setq NEWDIM "1-2'' - 1FT")(UPTONEW)))
    (if (or (= CURDIM "AT&T3-4")(= CURDIM "TRKIMP3-4")(= CURDIM "TRK3-4"))(progn(setq NEWDIM "3-4'' - 1FT")(UPTONEW)))
    (if (or (= CURDIM "AT&T1")(= CURDIM "AT&T1FT")(= CURDIM "TRKIMP1")(= CURDIM "TRK1"))(progn(setq NEWDIM "1'' - 1FT")(UPTONEW)))
    (if (or (= CURDIM "AT&T1-1-2")(= CURDIM "AT&T1-1-2FT")(= CURDIM "TRKIMP1-1-2")(= CURDIM "TRK1-1-2"))(progn(setq NEWDIM "1 1-2'' - 1FT")(UPTONEW)))
    (if (or (= CURDIM "AT&T2")(= CURDIM "AT&T2FT")(= CURDIM "TRKIMP2")(= CURDIM "TRK2"))(progn(setq NEWDIM "2'' - 1FT")(UPTONEW)))
    (if (or (= CURDIM "AT&T3")(= CURDIM "AT&T3FT")(= CURDIM "TRKIMP3")(= CURDIM "TRK3"))(progn(setq NEWDIM "3'' - 1FT")(UPTONEW)))
    (if (or (= CURDIM "AT&T1-1")(= CURDIM "TRKIMP1-1")(= CURDIM "TRK1-1"))(progn(setq NEWDIM "1'' - 1''")(UPTONEW)))
    (if (or (= CURDIM "AT&T1-10")(= CURDIM "AT&T1-10FT")(= CURDIM "TRKIMP1-10")(= CURDIM "TRK1-10"))(progn(setq NEWDIM "1'' - 10FT")(UPTONEW)))
    (if (or (= CURDIM "AT&T1-20")(= CURDIM "AT&T1-20FT")(= CURDIM "TRKIMP1-20")(= CURDIM "TRK1-20"))(progn(setq NEWDIM "1'' - 20FT")(UPTONEW)))
    (if (or (= CURDIM "AT&T1-30")(= CURDIM "AT&T1-30FT")(= CURDIM "TRKIMP1-30")(= CURDIM "TRK1-30"))(progn(setq NEWDIM "1'' - 30FT")(UPTONEW)))
    (if (or (= CURDIM "AT&T1-40")(= CURDIM "AT&T1-40FT")(= CURDIM "TRKIMP1-40")(= CURDIM "TRK1-40"))(progn(setq NEWDIM "1'' - 40FT")(UPTONEW)))
    (if (or (= CURDIM "AT&T1-50")(= CURDIM "AT&T1-50FT")(= CURDIM "TRKIMP1-50")(= CURDIM "TRK1-50"))(progn(setq NEWDIM "1'' - 50FT")(UPTONEW)))
    (if (or (= CURDIM "AT&T1-70")(= CURDIM "AT&T1-70FT")(= CURDIM "TRKIMP1-70")(= CURDIM "TRK1-70"))(progn(setq NEWDIM "1'' - 70FT")(UPTONEW)))
    (if (or (= CURDIM "AT&T1-75")(= CURDIM "AT&T1-75FT")(= CURDIM "TRKIMP1-75")(= CURDIM "TRK1-75"))(progn(setq NEWDIM "1'' - 75FT")(UPTONEW)))
    (if (or (= CURDIM "AT&T1-80")(= CURDIM "AT&T1-80FT")(= CURDIM "TRKIMP1-80")(= CURDIM "TRK1-80"))(progn(setq NEWDIM "1'' - 80FT")(UPTONEW)))
    (if (or (= CURDIM "AT&T1-100")(= CURDIM "AT&T1-100FT")(= CURDIM "TRKIMP1-100")(= CURDIM "TRK1-100"))(progn(setq NEWDIM "1'' - 100FT")(UPTONEW)))
    (if (or (= CURDIM "AT&T1-120")(= CURDIM "AT&T1-120FT")(= CURDIM "TRKIMP1-120")(= CURDIM "TRK1-120"))(progn(setq NEWDIM "1'' - 120FT")(UPTONEW)))
    (if (or (= CURDIM "AT&T1-150")(= CURDIM "AT&T1-150FT")(= CURDIM "TRKIMP1-150")(= CURDIM "TRK1-150"))(progn(setq NEWDIM "1'' - 150FT")(UPTONEW)))
    (if (or (= CURDIM "AT&T1-200")(= CURDIM "AT&T1-200FT")(= CURDIM "TRKIMP1-200")(= CURDIM "TRK1-200"))(progn(setq NEWDIM "1'' - 200FT")(UPTONEW)))
    (if (or (= CURDIM "AT&T1-300")(= CURDIM "AT&T1-300FT")(= CURDIM "TRKIMP1-300")(= CURDIM "TRK1-300"))(progn(setq NEWDIM "1'' - 300FT")(UPTONEW)))
    (if (or (= CURDIM "AT&T1-400")(= CURDIM "AT&T1-400FT")(= CURDIM "TRKIMP1-400")(= CURDIM "TRK1-400"))(progn(setq NEWDIM "1'' - 400FT")(UPTONEW)))
    (if (or (= CURDIM "AT&T1-500")(= CURDIM "AT&T1-500FT")(= CURDIM "TRKIMP1-500")(= CURDIM "TRK1-500"))(progn(setq NEWDIM "1'' - 500FT")(UPTONEW)))
    (if (or (= CURDIM "AT&T1-1000")(= CURDIM "AT&T1-1000FT")(= CURDIM "TRKIMP1-1000")(= CURDIM "TRK1-1000"))(progn(setq NEWDIM "1'' - 1000FT")(UPTONEW)))
    (if (= CURDIM "TRKMET1-2")(progn(setq NEWDIM "1-2")(UPTONEW)))
    (if (= CURDIM "TRKMET1-5")(progn(setq NEWDIM "1-5")(UPTONEW)))
    (if (= CURDIM "TRKMET1-10")(progn(setq NEWDIM "1-10")(UPTONEW)))
    (if (= CURDIM "TRKMET1-15")(progn(setq NEWDIM "1-15")(UPTONEW)))
    (if (= CURDIM "TRKMET1-20")(progn(setq NEWDIM "1-20")(UPTONEW)))
    (if (= CURDIM "TRKMET1-25")(progn(setq NEWDIM "1-25")(UPTONEW)))
    (if (= CURDIM "TRKMET1-30")(progn(setq NEWDIM "1-30")(UPTONEW)))
    (if (= CURDIM "TRKMET1-35")(progn(setq NEWDIM "1-35")(UPTONEW)))
    (if (= CURDIM "TRKMET1-40")(progn(setq NEWDIM "1-40")(UPTONEW)))
    (if (= CURDIM "TRKMET1-45")(progn(setq NEWDIM "1-45")(UPTONEW)))
    (if (= CURDIM "TRKMET1-50")(progn(setq NEWDIM "1-50")(UPTONEW)))
    (if (= CURDIM "TRKMET1-55")(progn(setq NEWDIM "1-55")(UPTONEW)))
    (if (= CURDIM "TRKMET1-60")(progn(setq NEWDIM "1-60")(UPTONEW)))
    (if (= CURDIM "TRKMET1-65")(progn(setq NEWDIM "1-65")(UPTONEW)))
    (if (= CURDIM "TRKMET1-70")(progn(setq NEWDIM "1-70")(UPTONEW)))
    (if (= CURDIM "TRKMET1-75")(progn(setq NEWDIM "1-75")(UPTONEW)))
    (if (= CURDIM "TRKMET1-80")(progn(setq NEWDIM "1-80")(UPTONEW)))
    (if (= CURDIM "TRKMET1-85")(progn(setq NEWDIM "1-85")(UPTONEW)))
    (if (= CURDIM "TRKMET1-90")(progn(setq NEWDIM "1-90")(UPTONEW)))
    (if (= CURDIM "TRKMET1-95")(progn(setq NEWDIM "1-95")(UPTONEW)))
    (if (= CURDIM "TRKMET1-100")(progn(setq NEWDIM "1-100")(UPTONEW)))
    (if (= CURDIM "TRKMET1-125")(progn(setq NEWDIM "1-125")(UPTONEW)))
    (if (= CURDIM "TRKMET1-150")(progn(setq NEWDIM "1-150")(UPTONEW)))
    (if (= CURDIM "TRKMET1-175")(progn(setq NEWDIM "1-175")(UPTONEW)))
    (if (= CURDIM "TRKMET1-200")(progn(setq NEWDIM "1-200")(UPTONEW)))
    (if (= CURDIM "TRKMET1-250")(progn(setq NEWDIM "1-250")(UPTONEW)))
    (if (= CURDIM "TRKMET1-300")(progn(setq NEWDIM "1-300")(UPTONEW)))
    (if (= CURDIM "TRKMET1-350")(progn(setq NEWDIM "1-350")(UPTONEW)))
    (if (= CURDIM "TRKMET1-400")(progn(setq NEWDIM "1-400")(UPTONEW)))
    (if (= CURDIM "TRKMET1-450")(progn(setq NEWDIM "1-450")(UPTONEW)))
    (if (= CURDIM "TRKMET1-500")(progn(setq NEWDIM "1-500")(UPTONEW)))
    (if (= CURDIM "TRKMET1-750")(progn(setq NEWDIM "1-750")(UPTONEW)))
    (if (= CURDIM "TRKMET1-1000")(progn(setq NEWDIM "1-1000")(UPTONEW)))
    (if (= CURDIM "TRKMET1-1250")(progn(setq NEWDIM "1-1250")(UPTONEW)))
    (if (= CURDIM "TRKMET1-1500")(progn(setq NEWDIM "1-1500")(UPTONEW)))
    (if (= CURDIM "TRKMET1-1750")(progn(setq NEWDIM "1-1750")(UPTONEW)))
    (if (= CURDIM "TRKMET1-2000")(progn(setq NEWDIM "1-2000")(UPTONEW)))
    (if (= CURDIM "TRKMET1-2500")(progn(setq NEWDIM "1-2500")(UPTONEW)))
    (setq COUNT (1+ COUNT))
    (setq EN (SSNAME E COUNT))
    )
    ;(princ "\nDone switch")
    (princ)
    )
     
    C Witt, Jul 16, 2004
    #1
  2. C Witt

    ECCAD Guest

    You could shorten up several lines:
    (if (= CURDIM "TRKMET1-2500")(progn(setq NEWDIM "1-2500")(UPTONEW)))
    by doing:
    (setq new_dim (substr curdim 7 6))
    (setq newdim new_dim)
    (uptonew)

    Bob
     
    ECCAD, Jul 16, 2004
    #2
  3. C Witt

    Paul Turvill Guest

    The first thing I'd try is substituting a single (cond ...) function for all
    of those (if ...) statements. A (cond ...) function branches immediately
    when it encounters a specific condition; your current code checks every (if
    ....) clause, even after it's acted on the one actual case encountered.
    ___
     
    Paul Turvill, Jul 16, 2004
    #3
  4. C Witt

    C Witt Guest

    but in some of our drawings it is possible to encounter 75%+ of the
    listed dims.. so i don't want it stopping if it finds 1 or 2..
     
    C Witt, Jul 16, 2004
    #4
  5. C Witt

    ECCAD Guest

    Also,
    I see a problem with a portion of many lines, such as:
    (setq NEWDIM "1'' - 20FT")......should be
    (setq NEWDIM "1 - 20FT")

    Bob
     
    ECCAD, Jul 16, 2004
    #5
  6. C Witt

    C Witt Guest

    no.. that is the way we want it...

    so the dim style name reads 1" - 20FT

    the '' shows as "
     
    C Witt, Jul 16, 2004
    #6
  7. I think you're not understanding what Paul said about
    using a single COND in place of many IF's.

    The fact is that given a single test value, only one of
    the many IF tests can succeed, but because you're
    using many distinct IF tests, all of them are evaluated,
    even after one succeeds. Since only one can succeed
    for each given test string, the need to evaluate the
    remaining ones is entirely pointless.

    This may help understand why:

    (setq test_string "a")

    (if (eq test_string "a") <then>)
    (if (eq test_string "b") <then>)
    (if (eq test_string "c") <then>)

    only one of the above three expressions can succeed,
    because they are all testing against the same value.

    However, if the value of test_string is "a", then it
    is obvious that the last two IF tests cannot succeed,
    but they are evaluated anyway, needlessly.

    In contrast:

    (cond
    ( (eq test_string "a") <then>)
    ( (eq test_string "b") <then>)
    ( (eq test_string "c") <then>)
    )

    In the above, if 'test_string is "a", then the second
    two equality tests are never evaluated.

    Get it?

    When using COND in this manner you can also further optimize your
    code, by ordering the tests so that the ones that are most-likely to
    succeed are first. IOW, using the above example, if you know that
    the value of the 'test_string is most commonly the string "c", then
    you would rearrange the test so that the most likely value appears
    first, like so:

    (cond
    ( (eq test_string "c") <then>) ;; <- "c" is most frequent value
    ( (eq test_string "a") <then>)
    ( (eq test_string "b") <then>)
    )
     
    Tony Tanzillo, Jul 16, 2004
    #7
  8. C Witt

    C Witt Guest

    *light goes on*

    Now I see.

    that should help alot..

    Thank you both.
     
    C Witt, Jul 16, 2004
    #8
  9. C Witt

    C Witt Guest

    that could work.

     
    C Witt, Jul 16, 2004
    #9
  10. C Witt

    R.K. McSwain Guest


    Why not just use the regular quote mark (") ?

    (setq NEWDIM (strcat "1" (chr 34) "- 150FT")
     
    R.K. McSwain, Jul 16, 2004
    #10
  11. C Witt

    C Witt Guest

    nope.. that returns "1-16\" - 1FT"

     
    C Witt, Jul 16, 2004
    #11
  12. Which is exactly what you need. The \
    is required to show the extra "" in a string.
     
    Jason Piercey, Jul 16, 2004
    #12
  13. C Witt

    Tom Smith Guest

    Why not just use the regular quote mark (") ?

    It's an illegal character.
     
    Tom Smith, Jul 16, 2004
    #13
  14. C Witt

    Tom Smith Guest

    Which is exactly what you need.

    But it's still an illegal character in a dimstyle name.
     
    Tom Smith, Jul 16, 2004
    #14
  15. Correct, 3 times now :)
     
    Jason Piercey, Jul 16, 2004
    #15
  16. C Witt

    ECCAD Guest

    So....Tom,
    What's the 'fix' for his situation ?
    If you can't mark it with a \" and can't use (chr 34)..then
    how are ya gonna get it to be "1" - 12FT"
    ::??::

    Bob
     
    ECCAD, Jul 16, 2004
    #16
  17. My guess is that you don't. I just use the scale
    factor for the name. Dim_96 or whatever.
     
    Jason Piercey, Jul 16, 2004
    #17
  18. C Witt

    Jeff Mishler Guest

    Just like he's already doing it....2 ' next to each other gives '' which IS
    valid in a dimstyle name.
     
    Jeff Mishler, Jul 16, 2004
    #18
  19. C Witt

    jclaidler Guest

    here's a question...
    Why create a dimstyle based on scale factor ??
     
    jclaidler, Jul 16, 2004
    #19
  20. C Witt

    ECCAD Guest

    Oh, I see. (now). The " you have is really ''
    Kinda hard to see the difference (even with glasses)..
    :)
    Bob
     
    ECCAD, Jul 16, 2004
    #20
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.