View Full Version : Slope in a 2D drawing.
SRBalliet
2008-12-01, 04:49 PM
I am looking for a lisp routine that will do the following:
Read the Y coordinates from the end points of a line or polyline, Subtract those coordinate numbers, Then divide that answer by the length of the line.
It doesn't matter to me if I have to pick the line itself or the end points seperately.
It also doesn't matter if it just lists the answer or actually labels it, although labeling would be the best.
Anybody have something like that?
(I wish I had the time to learns this myself)
lpseifert
2008-12-01, 05:41 PM
try this
;;;returns slope of line/polyline in profile... LPS 2008 w/ help from guys at the Swamp
(defun c:sl ()
(vl-load-com)
(setq ent (entsel))
(if (= (cdr (assoc 0 (entget (car ent)))) "LINE")
(progn
(setq lst (entget (car ent))
pt1 (cdr (assoc 10 lst))
pt2 (cdr (assoc 11 lst))
x1 (car pt1)
y1 (cadr pt1)
x2 (car pt2)
y2 (cadr pt2)
dy (- y2 y1)
dx (- x2 x1)
slp (* 100 (/ dy dx))
slp2 (/ dx dy)
txtx (rtos (abs dx) 2 2)
txty (rtos dy 2 2)
txts (rtos slp 2 2)
txts2 (rtos slp2 2 2)
) ;setq
) ;progn
(progn
(setq pt (osnap (cadr ent) "nea")
ent (car ent)
) ;setq
(defun getadjacentplinevertices (ent pt / i p1 p2)
(if (= (cdr (assoc 0 (entget ent))) "LWPOLYLINE")
(progn
(setq i (fix (vlax-curve-getParamAtPoint
ent
(vlax-curve-getClosestPointTo ent pt)
)
)
p1 (vlax-curve-getPointAtParam ent i)
p2 (vlax-curve-getPointAtParam ent (+ 1 i))
)
(setq ls1 (list p1 p2))
) ;progn
) ;if
) ;defun
(getadjacentplinevertices ent pt)
(setq p1x (car (car ls1))
p1y (cadr (car ls1))
p2x (car (cadr ls1))
p2y (cadr (cadr ls1))
dx (- p2x p1x)
dy (- p2y p1y)
slp (* 100 (/ dy dx))
slp2 (/ dx dy)
txtx (rtos (abs dx) 2 2)
txty (rtos dy 2 2)
txts (rtos slp 2 2)
txts2 (rtos slp2 2 2)
) ;setq
) ;progn
) ;if
(prompt (strcat "\nHorizontal distance = " txtx "'"
"\nRelief = " txty "'"
"\nSlope is " txts "%..." txts2 ":1")
)
(princ)
)
SRBalliet
2008-12-01, 05:59 PM
How do you guys write that so fast?
Sorry, but I'm getting:
Command:
Command:
Command: _appload GRADE.LSP successfully loaded.
Command:
Command:
Command: GRADE
Unknown command "GRADE".
irneb
2008-12-01, 06:49 PM
I'm supposing you've copied Ipseifert's code into a GRADE.LSP file since you're loading it with APPLOAD? If you copied it directly (not modifying anything) the command is actually SL. Notice the (defun c:sl ... this means "Define a function as a command called SL".
Usually most simple LISP routines would simply be saved into a file named the same as the command. But this is not a necessity, you could have multiple new commands in one file as well.
SRBalliet
2008-12-01, 07:03 PM
Thanks to both of you, it works great!
vBulletin® v3.6.7, Copyright ©2000-2010, Jelsoft Enterprises Ltd.