Highlight line

Discussion in 'AutoCAD' started by Big 'D', Feb 4, 2005.

  1. Big 'D'

    Big 'D' Guest

    The routine below is used to join two line segments. I have not been successful in getting the routine to highlight the first line I select. If I happen to miss the line I do not know it until I select the second line and then it is too late. The attached is a working version without the highlight. Can someone help shed some "highlight" on this subject?

    Thanks,
    D
    (I love this group!)

    (DEFUN C:JL ()
    (SETQ B (ENTSEL "\nPick 1st Line: "))
    (IF (= B nil)(ERR))
    (IF (= "LINE" (CDR (ASSOC 0 (SETQ E (ENTGET (SETQ L (CAR B)))))))
    (PROGN (SETQ F (CDR (SETQ J (ASSOC 10 E))))
    (SETQ G (CDR (SETQ K (ASSOC 11 E)))))(ERR))
    (SETQ C (ENTSEL "\nPick 2nd Line: "))
    (IF (= C nil)(ERR))
    (IF (= "LINE" (CDR (ASSOC 0 (SETQ D (ENTGET (SETQ M (CAR C)))))))
    (PROGN (SETQ H (CDR (ASSOC 10 D)))
    (SETQ I (CDR (ASSOC 11 D)))
    (ENTDEL M))(ERR))
    (IF (< (DISTANCE F H) (DISTANCE F I))
    (PROGN
    (IF (< (DISTANCE G I) (DISTANCE F I))
    (PROGN (SETQ E (SUBST (CONS 11 I) K E)) (ENTMOD E))
    (PROGN (SETQ E (SUBST (CONS 10 I) J E)) (ENTMOD E))))
    (PROGN

    (IF (< (DISTANCE G H) (DISTANCE F H))
    (PROGN (SETQ E (SUBST (CONS 11 H) K E)) (ENTMOD E))
    (PROGN (SETQ E (SUBST (CONS 10 H) J E)) (ENTMOD E))))
    )(COMMAND)(COMMAND))
     
    Big 'D', Feb 4, 2005
    #1
  2. Big 'D'

    BillZ Guest

    You could make sure that you are picking the first line like this:

    (while (not (setq B (car (entsel "\nPick 1st line: < pick > ")))))
    (if b (redraw b 3))

    Bill
     
    BillZ, Feb 4, 2005
    #2
  3. Big 'D'

    BTO Guest

    hi,

    take a look in the help file to

    (redraw ename 3 ) to Highlight entity

    (redraw ename 4 ) to Unhighlight entity

    Bruno Toniutti
     
    BTO, Feb 4, 2005
    #3
  4. Big 'D'

    Alaspher Guest

    Minimal optimization:
    Code:
    (DEFUN C:JL (/ B C D E F G H I J K L M)
    (IF (and (SETQ B (ENTSEL "\nPick 1st Line: "))
    (= "LINE" (CDR (ASSOC 0 (SETQ E (ENTGET (SETQ L (CAR B)))))))
    (progn (redraw L 3) (SETQ C (ENTSEL "\nPick 2nd Line: ")))
    (= "LINE" (CDR (ASSOC 0 (SETQ D (ENTGET (SETQ M (CAR C)))))))
    )
    (PROGN (SETQ F (CDR (SETQ J (ASSOC 10 E)))
    G (CDR (SETQ K (ASSOC 11 E)))
    H (CDR (ASSOC 10 D))
    I (CDR (ASSOC 11 D))
    )
    (ENTDEL M)
    (IF (< (DISTANCE F H) (DISTANCE F I))
    (IF (< (DISTANCE G I) (DISTANCE F I))
    (PROGN (SETQ E (SUBST (CONS 11 I) K E)) (ENTMOD E))
    (PROGN (SETQ E (SUBST (CONS 10 I) J E)) (ENTMOD E))
    )
    (IF (< (DISTANCE G H) (DISTANCE F H))
    (PROGN (SETQ E (SUBST (CONS 11 H) K E)) (ENTMOD E))
    (PROGN (SETQ E (SUBST (CONS 10 H) J E)) (ENTMOD E))
    )
    )
    )
    (progn (princ "\nError! Bad selection!") (redraw L 4))
    )
    (princ)
    )
    (ERR) - is the bad way for breaking
     
    Alaspher, Feb 4, 2005
    #4
  5. Big 'D'

    Tom Smith Guest

    a) Turn off the caps lock
    b) Declare all variables local
    c) Give variables meaningful names
    d) Structure the program so that "err" bailouts are never necessary
    e) Make functions short, clear, and easy to follow. Programs should be
    designed primarily for human readability.

    You shouldn't need highlighting if the logic is correct -- the program
    shouldn't allow you to fail to select either line. I'd write a foolproof
    single-line-picking function first, something like:

    ;return edata for one line
    (defun getline (prmpt / sset edata)
    (while (null edata)
    (and
    (setq sset (ssget ":s:e" '((0 . "line"))))
    (setq edata (entget (ssname sset 0)))))
    edata)

    Then I'd write a function to take the entity data for two lines, merge the
    endpoints into one, and delete the other. I can't easily determine what
    you're doing because of the cryptic variable names, so I'll leave this to
    you to write.

    (defun mergelines (linedata1 linedata2 / <local vars>)
    <hocus pocus here>
    )

    Then I'd make the main routine as simple as possible:

    (defun c:jl (/ line1 line2)
    (command "undo" "begin")
    (setq
    line1 (getline "\n1st line: ")
    line2 (getline "\n2nd line: "))
    (mergelines line1 line2)
    (command "undo" "end")
    (princ))

    If I anticipated using the lesser functions elsewhere, I'd put them in a
    autoloading "utility" lisp, otherwise I'd make them local to this program,
    as in:

    (defun c:jl (/ getline mergelines line1 line2)
    (defun getline ... )
    (defun mergelines ... )

    (command "undo" "begin")
    (setq
    line1 (getline "\n1st line: ")
    line2 (getline "\n2nd line: "))
    (mergelines line1 line2)
    (command "undo" "end")
    (princ))
     
    Tom Smith, Feb 4, 2005
    #5
  6. Big 'D'

    Tom Smith Guest

    Correction, left out the prompt:

    ;return edata for one line
    (defun getline (prmpt / sset edata)
    (while (null edata)
    (and
    (princ prmpt)
    (setq sset (ssget ":s:e" '((0 . "line"))))
    (setq edata (entget (ssname sset 0)))))
    edata)
     
    Tom Smith, Feb 4, 2005
    #6
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.