My program can't run

Discussion in 'AutoCAD' started by Adesu, Jun 7, 2004.

  1. Adesu

    Adesu Guest

    I've create a program to measuring length of a line,after load in cad it
    program can't run,but if I load as step by step (line by line) it can run
    (not yet perfect),can anybody help to me to correct it,thanks a lot for your
    kind
    Best regards
    Ade Suharna

    ; ll is stand for measuring length of a line
    ; Design by Ade Suharna
    ; 6 June 2004
    (defun c:ll ()
    (setq alin (entget (entsel "Please choose start line: ")))
    (setq adot (entget (entlast)))
    (setq adot-1 (assoc 10 adot))
    (setq adot-2 (cdr adot-1))
    (setq blin (entget (entsel "Please choose end line: ")))
    (setq bdot (entget (entlast)))
    (setq bdot-1 (assoc 11 bdot))
    (setq bdot-2 (cdr bdot-1))
    (setq dist_ab (distance adot-2 bdot-2))
    (prompt "\nLENGTH OF LINE: ")
    (princ dist_ab)
    (princ)
    )
     
    Adesu, Jun 7, 2004
    #1
  2. Adesu

    TCEBob Guest

    Adesu,

    You do not need to pick the ends of the line as you never use th pick points.
    You must insert (car . . . before the entsel item.

    Here are some comments in the program I have capitalized changes:

    (defun c:ll ( / ALIN ADOT1 ADOT2 BDOT1 BDOT2 DIST_AB) ;ALWAYS DECLARE
    (setq alin (entget (CAR (entsel "Please choose start line: "))))
    ;(setq adot (entget (entlast))) ;YOU ALREADY HAVE IT AS ALIN
    (setq adot-1 (assoc 10 ALIN))
    (setq adot-2 (cdr adot-1))
    ;(setq blin (entget (CAR (entsel "Please choose end line: "))))
    ;(setq bdot (entget (entlast))) ;YOU HAVE ALREADY PICKED THE LINE
    (setq bdot-1 (assoc 11 ALIN))
    (setq bdot-2 (cdr bdot-1))
    (setq dist_ab (distance adot-2 bdot-2))
    (prompt "\nLENGTH OF LINE: ")
    (princ dist_ab)
    (princ)
    )

    When you get it so it works the way you want it you should try combining
    functions as you did in the first line. This COULD be written:

    (defun c:ll( / alin)
    (setq alin(entget(car(entsel "Please choose a line: "))))
    (princ
    (strcat "\nLENGTH OF LINE: "
    (rtos (distance (cdr(assoc 11 alin)) (cdr(assoc 10 alin))))
    )
    )
    (princ))

    rs
     
    TCEBob, Jun 7, 2004
    #2
  3. Adesu

    Adesu Guest

    Hi TCEBob,I've got it,and very glad,thanks a lot
     
    Adesu, Jun 7, 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.