Jump to content

Slope of a line


smorales02

Recommended Posts

Did a quick search and couldnt come up with anything so I thought I might post... I am wanting to be able to click on a line and have ACAD give me the Slope of the line...Is there something in ACAD that already does that and I just cant find it??? any help would be appreciated..

Link to comment
Share on other sites

if you use distance it will give you the delta X and delta Y. You could write a quick little program to automate that also

Link to comment
Share on other sites

try this

;;;returns slope of line/polyline LPS 2008 w/help from ronjomp @ 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))
       txtx (rtos (abs dx) 2 2)
       txty (rtos dy 2 2)
       txts (rtos slp 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)
)

Link to comment
Share on other sites

returns this error message when I select my line..

 

Select object: ; error: bad argument type: stringp nil

Link to comment
Share on other sites

I don't know what to tell you... I just copy/pasted the code into the Visual Lisp Editor, loaded and ran it and it worked fine. Anybody else try it and have problems?

Link to comment
Share on other sites

Civil Design is an add-on for Land Desktop (and Land Development Desktop prior). Land Desktop is a stand-alone product for survey and civil applications. Civil 3d is the newer product released in '04 I believe. It was meant to replace the Land Desktop and Civil Design package and it now has. Up through the '08 release Land Desktop was sold or given along with a Civil 3d seat as a "companion product" just until the development of Civil 3d was more complete and could perform all of the duties that the old Land/Civil package did. I believe Land Desktop and Civil Design are now pretty much finished.

 

Civil Design was for engineers to do the actual design work with profiles and pipes, etc. I don't recall if Land has the abilities to do the slope labels or if it was the Civil Design add-on that gave this functionality. Have you tried searching the help file? If I were at work I could check on this for you, but what with it being Sunday I don't have access to Land.

Link to comment
Share on other sites

OK I'm at work now. It appears that the Profiles menu is part of the Civil Design add-on so if you only have Land then you probably would have to go with the previous lisp or equivalent.

 

With Civil Design you would label it by going to Profiles > Label > Tangents

Link to comment
Share on other sites

try this

;;;returns slope of line/polyline LPS 2008 w/help from ronjomp @ 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))
       txtx (rtos (abs dx) 2 2)
       txty (rtos dy 2 2)
       txts (rtos slp 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)
)

it doesn work with autocad2006

it returns error:

Select object: ; error: bad argument type: stringp nil

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...