Jump to content

Showing the Gradient Of a Line


tomtomtom

Recommended Posts

Hello everyone

 

I am using autocad 2011 (first time using it). I have a line that is drawn at an angle, but i want to show the gradient of the line in 1 in x terms is this possible and of so can anyone tell me how.

 

Showing the gradient in anyform would be great.

 

Please help.

 

Thank you.

Link to comment
Share on other sites

Here's a quick bit of code to display the gradient:

 

(defun c:lgrad ( / an en p1 p2 p3 )
 ;; © Lee Mac 2011
 (if
   (and
     (setq en (car (entsel "\nSelect Line: ")))
     (eq "LINE" (cdr (assoc 0 (setq en (entget en)))))
   )
   (progn
     (setq p1 (cdr (assoc 10 en))
           p2 (cdr (assoc 11 en))
           an (angle p1 p2)
           p3 (mapcar '(lambda ( a b ) (/ (+ a b) 2.)) p1 p2)
           p3 (polar p3 (+ an (/ pi 2.)) (getvar 'TEXTSIZE))
     )
     (entmakex
       (list
         (cons 0 "TEXT")
         (cons 7  (getvar 'TEXTSTYLE))
         (cons 10 p3)
         (cons 11 p3)
         (cons 40 (getvar 'TEXTSIZE))
         (cons 50
           (cond
             ( (and (> an (/ pi 2)) (<= an pi))
               (- an pi)
             )
             ( (and (> an pi) (<= an (/ (* 3 pi) 2)))
               (+ an pi)
             )
             ( an )
           )
         )
         (cons 1 (strcat "1 in " (rtos (/ 1. (/ (sin an) (cos an))))))
         (cons 72 1)
         (cons 73 2)
       )
     )
   )
 )
 (princ)
)

Link to comment
Share on other sites

Heres another as % used for cross sections pick multiple lines in one go

 

(defun rtd (a)(/ (*  a 180.0) pi))
(defun c:xfp ()

  (setvar "cmdecho" 0)
  (setq dimz (getvar "DIMZIN"))
  (setvar "DIMZIN" 0)
  (setq oldsnap (getvar "osmode"))
  (setvar "osmode" 0)
(SETQ ANGBASEE (GETVAR "ANGBASE"))
(SETQ ANGDIRR (GETVAR "ANGDIR"))
(SETQ LUNITSS (GETVAR "LUNITS"))
(SETQ LUPRECC (GETVAR "LUPREC"))
(SETQ AUNITSS (GETVAR "AUNITS"))
(SETQ AUPRECC (GETVAR "AUPREC"))
(SETVAR "LUNITS" 2)
(SETVAR "ANGBASE" 0.0)
(SETVAR "ANGDIR" 0)
(SETVAR "LUPREC" 3)
(SETVAR "AUNITS" 0)
(SETVAR "AUPREC" 3)
(if (= horiz nil) 
   (progn
  (setq horiz (getint "\nEnter Horizontal scale:<100>:"))
  (if (= horiz nil) (setq horiz 100))
  (prompt "\nEnter Vertical scale:<50>:")
  (setq vert (getint))
  (if (= vert nil) (setq vert 50))
  (prompt "\nEnter number of decimal places:<3>:")
  (setq prec (getint))
  (if (= prec nil) (setq prec 3))
  )             ; end progn
  )             ; end if
  (setq ss1 (ssget '((0 . "LINE"))))
  (setq n (sslength ss1))
  (setq count 0)
  (repeat n
     (setq a (entget (ssname ss1 count)))
     (setq count (+ count 1)) 
     (setq pt1 (cdr (assoc 10 a)))
     (setq pt2 (cdr (assoc 11 a)))
     (setq ang (angle pt1 pt2))
     (setq dist (distance pt1 pt2))
     (if (> dist 0)
        (progn 
           (setq halfdist (/ dist 2))
           (setq pt3 (polar pt1 ang halfdist))
           (if (> ang pi) (setq ang (- ang pi)))
           (if (> ang (/ pi 2)) (setq pt4ang (- ang (/ pi 2))) (setq pt4ang (+ ang (/ pi 2))))
           (setq pt4 (polar pt3 pt4ang 0.75))
           (if (> ang (/ pi 2)) (setq ang (+ ang pi)))
           (setq tang (rtd ang))
           (setq pt1y (cadr pt1))
           (setq pt2y (cadr pt2))
           (setq pt1x (car pt1))
           (setq pt2x (car pt2))
           (if (> pt1y pt2y) (setq ydist (- pt1y pt2y)) (setq ydist (- pt2y pt1y)))
           (if (> pt1x pt2x) (setq xdist (- pt1x pt2x)) (setq xdist (- pt2x pt1x)))
           (setq xfall (* (/ (* ydist vert) (* xdist horiz)) 100))
           (setq xfall (rtos xfall 2 prec))
           (setq xfall (strcat xfall "%"))
           (command "TEXT" "J" "C" pt4 "" tang xfall "")
        );progn
     ):if dist=0
  );repeat n
(setvar "DIMZIN" dimz)
(SETVAR "ANGBASE" ANGBASEE)
(sETVAR "ANGDIR" ANGDIRR)
(sETVAR "LUNITS" LUNITSS)
(sETVAR "LUPREC" LUPRECC)
(sETVAR "AUNITS" AUNITSS)
(sETVAR "AUPREC" AUPRECC)
(setvar "osmode" oldsnap)
  (princ)
)

Link to comment
Share on other sites

I draw a pline over 12 units and then up and measure the intersection of the grade to the vertex of the pline. Call me old school.

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...