Way to quickly calculate gradient between two points as shown?

Way to quickly calculate gradient between two points as shown?

dseedG2894
Observer Observer
2,414 Views
7 Replies
Message 1 of 8

Way to quickly calculate gradient between two points as shown?

dseedG2894
Observer
Observer

Hi there,

 

I am a relatively new (6 months) UK Civil Engineer, who is very keen on efficiency when trying to complete level designs etc in AutoCAD for residential sites. 

 

I was wondering if there is a LISP routine, addon or feature in Autocad 2d or something I'm missing to quickly work out gradients like that shown in the picture (Distance/A-B = 1/67) and produce a note showing the 1/67 for example as opposed to working it out on a calculator each time.


Any help would be greatly appreciated.

0 Likes
2,415 Views
7 Replies
Replies (7)
Message 2 of 8

ВeekeeCZ
Consultant
Consultant

Well, this was a reason I learned LISP.

The main issue is the workflow.

1) pick a text1, specify a point1, text2, specify point2. inefficient, but covers all cases.

2) pick a text1 and get a point from it automatically, pick a text2a and get pt2 from it. Much faster, but it depends on whether a text is somehow related to place... (block, or the insertion point match the place)

3) pick a text, take a point automatically, but be able to change to... combination

 

or you might have a drawing in 3d... who knows, hard to tell from a picture, post a portion of your dwg.

0 Likes
Message 3 of 8

dseedG2894
Observer
Observer

Hi @ВeekeeCZ, Interesting, the points are just text with no z values. We do have software to convert our topographical surveys to 3D, however we export this back to 2D for AutoCAD once we have the level design.

0 Likes
Message 4 of 8

ВeekeeCZ
Consultant
Consultant

Try this. You would need blocks for the arrow in drawing/ searchable path/or list the file path in lisp and remove the semicolon.

 

(defun c:Grade ( / pt1 pt2 h1 h2 d12 ang ptm arr)
  (if (and (setq pt1 (getpoint "\nPick first point: "))
	   (setq el1 (car (entsel "\nSelect its elevation label: ")))
	   (setq el1 (distof (cdr (assoc 1 (entget el1)))))
	   (setq pt2 (getpoint pt1 "\nPick second point: "))
	   (setq el2 (car (entsel "\nSelect its elevation label: ")))
	   (setq el2 (distof (cdr (assoc 1 (entget el2)))))
	   (not (equal pt1 pt2))
	   (setq pt1 (reverse (cdr (reverse pt1)))
		 pt2 (reverse (cdr (reverse pt2)))
		 d12 (distance pt1 pt2)
		 ang (angle pt1 pt2)
		 ptm (polar pt1 ang (/ d12 2))))
    (progn
      (setq arr (cond ((= slp 0) 0)
			((< (- el1 el2) 0.) -1)
			(1)))
      (if (< (* pi 0.5) ang (* pi 1.5))
	(setq ang (+ ang pi)
	      arr (* arr -1)))
      (entmakex (list (cons 00 "TEXT")
                      (cons 10  (trans ptm 1 0))
                      (cons 11  (trans ptm 1 0))
                      (cons 01  (strcat "1:" (rtos (abs (/ d12 (- el1 el2))) 2 1)))
                      (cons 07 (getvar 'TEXTSTYLE))
                      (cons 40 (getvar 'TEXTSIZE))
                      (cons 50 (angle (trans '(0 0 0) 1 0) (trans (polar '(0 0 0) ang 1e6) 1 0))) ; by John Uhden
                      (cons 72 1)
                      (cons 73 1)
                      ))
      (command "_-insert" (strcat ; "c:/Users/AppData/Local/Autodesk/AutoCAD 2015/R20.0/enu/Support/"  ; add a file path to a block or add it into searchable pathes
                                  "Arrow" (itoa arr) ".dwg") "_none" ptm (getvar 'TEXTSIZE) "" (angtos ang))))
  (princ)
)

 

Message 5 of 8

Kent1Cooper
Consultant
Consultant

@dseedG2894 wrote:

.... the points are just text with no z values. ....


And are the little + signs objects that can be selected with an insertion point that could be used, or is something like @ВeekeeCZ 's approach using (getpoint) the way to get the locations to measure the distance between?  How precise do you need the locations to be?

 

EDIT:  Also, I see your image uses 1-in-integer-value numbers for the slope, whereas @ВeekeeCZ 's suggestion calls for one decimal place.  If you ever deal with comparatively steep slopes, that could matter -- there's a significant difference between 1:0.9 and 1:1.4, but both would be shown as 1:1 if integer values are used, or [perhaps more realistically] 1:1.6 and 1:2.4 would both show as 1:2, but they're meaningfully different:

Kent1Cooper_0-1645624723218.png

Kent Cooper, AIA
0 Likes
Message 6 of 8

Sea-Haven
Mentor
Mentor

We do have software to convert our topographical surveys to 3D

 

If its CIV3D label slope is a built in feature.

0 Likes
Message 7 of 8

john.uhden
Mentor
Mentor

@Kent1Cooper & @ВeekeeCZ 

1st:  I am thrilled to see that BeekeeCZ has her meaningful ID back.

2nd:  Maybe that's the way they do it in the UK, but in the states we prefer to publish fine grades in percent to 2 places.

          Admittedly we show show steep slopes as a horizontal to vertical ratio (3:1).

In any case, I have often seen grading points published as a point or point block with separate adjacent text, or a "SPOT" block with an elevation attribute.  Besides the C3D Cogo_Point, the block with attribute is the best because you can just entsel the insertion and get x y + z, where z comes from the attribute value.

In fact, I recall our going through this many times over the years back in the Compuserve days.  I think the SPOT blocks are the best because you can change its location, easily edit the elevation, and change the scale, layer, angle,  and attribute appearance and location, and not have to concern yourself with point numbers and point groups and label styles.

John F. Uhden

0 Likes
Message 8 of 8

calderg1000
Mentor
Mentor

Regards @dseedG2894 

Calculate the gradient between two points although it is a simple operation with a calculator, but in the situation you have with texts and points it is usually laborious.
Here I attach the following code that is executed by selecting at the same time the point and the text, start and end. the result is the value of the gradient with the arrow in the direction of the point selection, indicating whether the gradient is positive or negative.

 

(defun c:GradX (/ s i e sp st dt pmid dc m f ang angs spm)
  (princ "\nSelect Pair Text and Point:")
  (setq s (ssget '((0 . "point,*Text"))))
  (repeat (setq i (sslength s))
    (Setq e (entget (ssname s (setq i (1- i)))))
    (if (= (cdr (assoc 0 e)) "POINT")
      (setq sp (cons (cdr (assoc 10 e)) sp))
      (progn
        (setq st (cons (atof (cdr (assoc 1 e))) st)
              ht (cdr (assoc 40 e))
        )
      )
    )
  )
  (setq dt   (distance (car sp) (cadr sp))
        pmid (mapcar '(lambda (x y) (/ (+ x y) 2)) (car sp) (cadr sp))
        ang  (angle (car sp) (cadr sp))
        dc   (- (cadr st) (car st))
        m    (abs (/ dt dc))
  )
  (if (> dc 0)
    (setq f "+")
    (setq f "-")
  )
  (if (< (* pi 0.5) ang (* pi 1.5))
    (setq angs (+ ang pi))
    (setq angs ang)
  )
  (setq
    spm (vla-get-modelspace (vla-get-activedocument (vlax-get-acad-object)))
  )
  (setq
    tf (vla-addtext spm (strcat f "1/" (rtos m 2 2)) (vlax-3d-point pmid) 1.0)
  )
  (vla-put-rotation tf angs)
  (vla-put-alignment tf acalignmentcenter)
  (vla-put-textalignmentpoint tf (vlax-3d-point pmid))
  (vla-update tf)
  (AA)
  (vl-cmdf "_insert"
           "A"
           "_none"
           (mapcar '- pmid (list 0. (* 0.7 ht) 0.))
           (* 4 ht)
           ""
           (angtos ang)
  )
)   

(defun AA (/)
  (setq blockname "A"
        objlayer "AR"
        objcolor 1
  )
  (entmake (list (cons 0 "BLOCK")
                 (cons 2 blockname)
                 (cons 10 '(0.0 0.0 0.0))
                 (cons 70 2)
           )
  )
  (entmake (list '(0 . "line")
                 (cons 8 objlayer)
                 (cons 10 '(-0.5 0.0 0.0))
                 (cons 11 '(0.5 0.0 0.0))
                 (cons 62 objcolor)
           )
  )
  (entmake (list '(0 . "line")
                 (cons 8 objlayer)
                 (cons 10 '(0.5 0.0 0.0))
                 (cons 11 '(0.4 0.07 0.0))
                 (cons 62 objcolor)
           )
  )
  (entmake (list '(0 . "line")
                 (cons 8 objlayer)
                 (cons 10 '(0.5 0.0 0.0))
                 (cons 11 '(0.4 -0.07 0.0))
                 (cons 62 objcolor)
           )
  )
  (entmake (list (cons 0 "ENDBLK") (cons 8 "0")))
)

 

 


Carlos Calderon G
EESignature
>Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.

0 Likes