Need help with a lisp routine

Discussion in 'AutoCAD' started by bmossman, Aug 10, 2004.

  1. bmossman

    bmossman Guest

    I'm trying to make some mods to this handy routine. Here's a rundown on what the routine does:
    INL = calcs lower invert calc
    INU = calcs upper invert calc
    SLO = calcs slope of line
    In regards to the INU, INU & SLO functions, how can i modify to do the following:
    1. prompt user to draw pline in lieu of selecting a single line for calculations
    2. prompt user to pick text insertion point & rotation angle for slope label in
    lieu of defaulting to midpoint of selected line & 0 rotation

    Code:
    (defun INV( Pos1 Pos2 / a b c d e f a10 a11 slopeins result insp slop oce)
    (setq oce (getvar "cmdecho"))
    (setvar "cmdecho" 0)
    (setq a (entsel (strcat "\nSelect " Pos1 " elevation: ")))
    (setq b (cdr (assoc 1 (entget (car a)))))
    (setq c (distof b))
    (setq d (entsel "\nSelect line: "))
    (setq slop (getreal "\nEnter slope percentage: "))
    (setq e (entget (car d)))
    (setq a10 (cdr (assoc 10 e)))
    (setq a11 (cdr (assoc 11 e)))
    (setq f (distance a10 a11))
    (setq slopeins (list (/(+(car a10)(car a11))2)
    (+(/(+(cadr a10)(cadr a11))2)(* (getvar "textsize")2))
    0.0))
    (if (>(cdr(assoc 40 (tblsearch "style" (getvar "textstyle"))))0)
    (command "_text" "j" "mc" slopeins "" (strcat(rtos slop 2 2)"%"))
    (command "_text" "j" "mc" slopeins "" "" (strcat(rtos slop 2 2)"%"))
    )
    (if (= Pos1 "Upper")
    (setq result (rtos (- c (/(* f slop)100))2))
    (setq result (rtos (+ c (/(* f slop)100))2))
    )
    (setq insp (getpoint (strcat "\nSelect " Pos2 " elevation insertion point: ")))
    (if (>(cdr(assoc 40 (tblsearch "style" (getvar "textstyle"))))0)
    (command "_text" "j" "mc" insp "" result)
    (command "_text" "j" "mc" insp "" "" result)
    )
    (setvar "cmdecho" oce)
    (princ)
    )

    (defun C:SLO( / a aa b bb c cc d e f a10 a11 slopeins result oce)
    (setq oce (getvar "cmdecho"))
    (setvar "cmdecho" 0)
    (setq a (entsel "\nSelect Upper elevation: "))
    (setq b (cdr (assoc 1 (entget (car a)))))
    (setq c (distof b))
    (setq aa (entsel "\nSelect Lower elevation: "))
    (setq bb (cdr (assoc 1 (entget (car aa)))))
    (setq cc (distof bb))
    (setq d (entsel "\nSelect line: "))
    (setq e (entget (car d)))
    (setq a10 (cdr (assoc 10 e)))
    (setq a11 (cdr (assoc 11 e)))
    (setq f (distance a10 a11))
    (setq slopeins (list (/(+(car a10)(car a11))2)
    (+(/(+(cadr a10)(cadr a11))2)(* (getvar "textsize")2))
    0.0))
    (setq result (/(- c cc)(/ f 100)))
    (if (>(cdr(assoc 40 (tblsearch "style" (getvar "textstyle"))))0)
    (command "_text" "j" "mc" slopeins "" (strcat(rtos result 2 2)"%"))
    (command "_text" "j" "mc" slopeins "" "" (strcat(rtos result 2 2)"%"))
    )
    (setvar "cmdecho" oce)
    (princ)
    )

    (defun C:INL()
    (INV "Upper" "Lower")
    )
    (defun C:INU()
    (INV "Lower" "Upper")
    )
    (defun C:INV()
    (INV "Upper" "Lower")
    )
    (princ)
    (princ "\n-----> INL to run lower invert calc")
    (princ "\n-----> INU to run upper invert calc")
    (princ "\n-----> SLO to run slope calc")
     
    bmossman, Aug 10, 2004
    #1
  2. bmossman

    bmossman Guest

    I'm trying to make some mods to this handy routin. Here's a rundown on what the routine does:
    INL = calcs lower invert calc
    INU = calcs upper invert calc
    SLO = calcs slope of line
    In regards to the INU, INU & SLO functions, how can i modify to do the following:
    1. prompt user to draw pline in lieu of selecting a single line for calculations

    (defun INV( Pos1 Pos2 / a b c d e f a10 a11 slopeins result insp slop oce)
    (setq oce (getvar "cmdecho"))
    (setvar "cmdecho" 0)
    (setq a (entsel (strcat "\nSelect " Pos1 " elevation: ")))
    (setq b (cdr (assoc 1 (entget (car a)))))
    (setq c (distof b))

    ;;(setq d (entsel "\nSelect line: "))
    (setq p1 (getpoint "\nDraw the line, Enter starting point: "))
    (setq p2 (getpoint p1 "\nEnter end point: "))
    (if (and p1 p2)
    (command "._line" p1 p2 "")
    (quit)
    )
    (setq e (entget(entlast)))
    ;(setq e (entget (car d)))

    (setq slop (getreal "\nEnter slope percentage: "))
    (setq a10 (cdr (assoc 10 e)))
    (setq a11 (cdr (assoc 11 e)))
    (setq f (distance a10 a11))
    ;(setq slopeins (list (/(+(car a10)(car a11))2)
    ; (+(/(+(cadr a10)(cadr a11))2)(* (getvar "textsize")2))
    ; 0.0))
    (prompt "\nSelect location and angle for slope.")
    (if (>(cdr(assoc 40 (tblsearch "style" (getvar "textstyle"))))0)
    (command "_text" "j" "mc" pause pause (strcat(rtos slop 2 2)"%"))
    (command "_text" "j" "mc" pause "" pause (strcat(rtos slop 2 2)"%"))
    )

    (if (= Pos1 "Upper")
    (setq result (rtos (- c (/(* f slop)100))2))
    (setq result (rtos (+ c (/(* f slop)100))2))
    )
    (setq insp (getpoint (strcat "\nSelect " Pos2 " elevation insertion point: ")))

    (if (>(cdr(assoc 40 (tblsearch "style" (getvar "textstyle"))))0)
    (command "_text" "j" "mc" insp "" result)
    (command "_text" "j" "mc" insp "" "" result)
    )
    (setvar "cmdecho" oce)
    (princ)
    )

    (defun C:SLO( / a aa b bb c cc d e f a10 a11 slopeins result oce)
    (setq oce (getvar "cmdecho"))
    (setvar "cmdecho" 0)
    (setq a (entsel "\nSelect Upper elevation: "))
    (setq b (cdr (assoc 1 (entget (car a)))))
    (setq c (distof b))
    (setq aa (entsel "\nSelect Lower elevation: "))
    (setq bb (cdr (assoc 1 (entget (car aa)))))
    (setq cc (distof bb))
    ;(setq d (entsel "\nSelect line: "))
    ;(setq e (entget (car d)))
    (setq p1 (getpoint "\nDraw the line, Enter starting point: "))
    (setq p2 (getpoint p1 "\nEnter end point: "))
    (if (and p1 p2)
    (command "._line" p1 p2 "")
    (quit)
    )
    (setq e (entget(entlast)))


    (setq a10 (cdr (assoc 10 e)))
    (setq a11 (cdr (assoc 11 e)))
    (setq f (distance a10 a11))
    ;;(setq slopeins (list (/(+(car a10)(car a11))2)
    ;; (+(/(+(cadr a10)(cadr a11))2)(* (getvar "textsize")2))
    ;; 0.0))
    (setq result (/(- c cc)(/ f 100)))

    (prompt "\nSelect location and angle for slope.")

    (if (>(cdr(assoc 40 (tblsearch "style" (getvar "textstyle"))))0)
    (command "_text" "j" "mc" pause pause (strcat(rtos result 2 2)"%"))
    (command "_text" "j" "mc" pause "" pause (strcat(rtos result 2 2)"%"))
    )
    (setvar "cmdecho" oce)
    (princ)
    )

    (defun C:INL()
    (INV "Upper" "Lower")
    )
    (defun C:INU()
    (INV "Lower" "Upper")
    )
    (defun C:INV()
    (INV "Upper" "Lower")
    )
    (princ)
    (princ "\n-----> INL to run lower invert calc")
    (princ "\n-----> INU to run upper invert calc")
    (princ "\n-----> SLO to run slope calc")
     
    bmossman, Aug 11, 2004
    #2
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.