Need help modifying a lisp routine

  • Thread starter Thread starter bmossman
  • Start date Start date
B

bmossman

What lines do i have to add in order to be able to draw a pline & use it's length value in the following calculations in lieu of just drawing a single line?

(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")
 
Maybe I'm not seeing something quite right, but you already have the values for the start and end
points of your line/pline in the variables p1 and p2. Why not just use them instead of re-reading
them in from the object (change a10 and a11 to p1 and p2 )?

To draw a pline, just use pline instead of line in the command line.
(command "._pline" p1 p2 "")
 
i tried that & it restricts me to just a begining & ending point (p1 & p2).... i want to continue the pline with unlimited vertices until i hit enter & have the calculations performed using the pline's overall length in lieu of just 2 points.
 
You'll get more help if you provide an
image of what you're intending to do.
A sample drawing would be helpful
to your cause. Are you just trying to
determine the start and end vertices
of a multiple vertex lwpolyline you've
just drawn? If this is the case, after
drawing your lwpolyline, get the entity
name using this : (setq e (entlast))

To get the endpoints of the lwpolyline:

(setq startpt (cdr (assoc 10 (entget e))))
(setq endpt (cdr (assoc 10 (reverse (entget e)))))

For a heavy polyline, you need more code.
 
insert this in place of the "line" command

Code:
(command "._pline")
; while active command
(while (eq (logand (getvar "CmdActive") 1) 1)
; get user's input
(command pause)
;_ closes while
)
 
Back
Top