Routine is flakey, why?

Discussion in 'AutoCAD' started by SD CA USA, Apr 28, 2004.

  1. SD CA USA

    SD CA USA Guest

    Group,
    I have a routine, see below. It is called linelength and is used to select
    lines of a certain length. I seems to work with either longer lines, or of a
    length of a whole number. For example it will find all 1'' lines but will
    not find lines of say 89/259". I have worked with units and precision but no
    luck.

    Here it is, any ideas?
    Thanks!

    (defun c:linelength()
    (if (not asked-length)(setq asked-length 660.0)) ; just a length
    (setq answer-asked-length (getreal (strcat "Enter length <" (rtos
    asked-length) ">:")))
    (if answer-asked-length (setq asked-length answer-asked-length))
    (setq tolerance 1e-12)
    (setq entity-list nil)
    (setq entity-list (ssadd)) ; create new, empty selection set

    (setq teller 0)
    (setq entlyst (ssget "X")) ; select every thing in the drawing
    (setq entlystl (sslength entlyst))

    (while (< teller entlystl) ; test through all entities
    (setq entityname (ssname entlyst teller))
    (setq entdatalyst (entget(ssname entlyst teller)))
    (setq enttype (cdr(assoc 0 entdatalyst)))

    (if (= enttype "LINE") ; test if entity is a line
    (progn

    (setq assoc10 (assoc 10 entdatalyst))
    (setq p10 (cdr assoc10)) ; WCS coordinates
    (setq p10 (trans p10 0 1)) ; UCS coordinates

    (setq assoc11 (assoc 11 entdatalyst))
    (setq p11 (cdr assoc11)) ; WCS coordinates
    (setq p11 (trans p11 0 1)) ; UCS coordinates

    (setq line-length (distance p10 p11))

    (if (< (abs(- line-length asked-length))tolerance) ; test length of line
    (setq entity-list (ssadd entityname entity-list))
    )

    );progn
    );if

    (setq teller (+ 1 teller))
    );while

    (setq set entity-list) ; short name for the set of selected objects
    (princ (sslength set))(princ " lines selected")(princ)
    (princ ", Call this set in responce to 'select objects' with: !set")(princ)
    );defun

    (princ "\nStart command: linelength")(princ)
     
    SD CA USA, Apr 28, 2004
    #1
  2. SD CA USA

    Devin Guest

    I think this statement is causing the flaky results...
    line

    I think it's the same thing roughly as...

    (if
    (equal line-length asked-length tolerance)
    ...
    )

    The tolerance value argument in the equal function is the degree of variance
    allowed to still result as equal when the line-length and asked-length are
    compared.

    But I think the (abs) is causing problems. So try the (equal) and let me
    know if it does what it is that you want. If I'm going to help further
    though, then you will need to tell me the logic that your program uses to
    accept line lengths into your selection set. I'm not sure but I think your
    logic is flawed in the top statement above.

    HTH,

    Devin
     
    Devin, Apr 28, 2004
    #2
  3. SD CA USA

    SD CA USA Guest

    That took care of it, thank you very much!
    TEW

     
    SD CA USA, Apr 28, 2004
    #3
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.