Automating calculating slope and drawing its values

Automating calculating slope and drawing its values

Anonymous
Not applicable
920 Views
5 Replies
Message 1 of 6

Automating calculating slope and drawing its values

Anonymous
Not applicable

Let's say I have 2 points of known value (eg. one is 120.00 and the other 121.00). I want to draw the line between these two points, input value of these two points with length of the line between them so that AutoCAD can calculate the slope. By now I am doing this manually, using windows calc but it's really annoying to alt+tab (to switch windows) all the time between CAD and calculator. Is there any way to do this using AutoCAD only?
Now the second part: after that I would like the AutoCAD to divide the line into equal sections of length=1 unit and put calculated values (based on slope) next to them. I am not sure if that's even possible to automate this. I attach a screen of the final result I need to get. These calculated values don't have to be put like that but they have to be visible (I will delete them anyway).
Thanks in advance for any kind of help 😄

0 Likes
921 Views
5 Replies
Replies (5)
Message 2 of 6

dlanorh
Advisor
Advisor

A sample drawing (saved as AutoCAD 2010 format) showing before and after would be helpful and avoid a lot of questions.

I am not one of the robots you're looking for

0 Likes
Message 3 of 6

Anonymous
Not applicable

Sorry, file in attachment.

0 Likes
Message 4 of 6

dlanorh
Advisor
Advisor

Try the rough and ready below. Will loop until you select NO at the "Another ?" prompt. If I've got this wrong let me know.

 

 

(defun rh:get_ent (msg typ / sel ent)
  (while (not ent)
    (setq sel (entsel (strcat "\n" msg)))
    (if (wcmatch (strcase (cdr (assoc 0 (entget (car sel))))) typ) (setq ent (car sel)))
  );end_while
  ent
);end_defun

(defun rh:eml (p1 p2) (entmakex (list '(0 . "LINE") (cons 10 p1) (cons 11 p2))))

(defun rh:emt (p1 a ht txt) (entmakex (list '(0 . "TEXT") (cons 10 p1) (cons 40 ht) (cons 1 (strcat " " txt)) (cons 50 a) (cons 11 p1) '(72 . 0) '(73 . 2))))

(defun rh:tan (x) (if (equal (cos x) 0.0 1.0e-16) (if (minusp x) -1.0e200 1.0e200) (/ (sin x) (cos x))))

(defun c:MLL (/ pd ans pt1 t_ent z1 tht pt2 z2 l_ent len h_ang v v_ang d pt3 z3)

  (initget 7)
  (setq pd (getreal "\nEnter Distance between required Points : ")
        ans "Yes"
  );end_setq

  (while (= ans "Yes")
    (setq pt1 (cdr (assoc 10 (entget (rh:get_ent "Select Start Point Entity : " "INSERT"))))
          t_ent (rh:get_ent "Select Start Point Entity Level : " "*TEXT")
          z1 (atof (cdr (assoc 1 (entget t_ent))))
          tht (* 0.5 (cdr (assoc 40 (entget t_ent))))
          pt2 (cdr (assoc 10 (entget (rh:get_ent "Select End Point Entity : " "INSERT"))))
          z2 (atof (cdr (assoc 1 (entget (rh:get_ent "Select End Point Entity Level : " "*TEXT")))))
          l_ent (rh:eml pt1 pt2)
          len (distance pt1 pt2)
          h_ang (angle pt1 pt2)
          v (- z2 z1)
          v_ang (atan (/ v len))
          d pd
    );end_setq
    (while (< d len)
      (setq pt3 (vlax-curve-getpointatdist l_ent d)
            z3 (+ z1 (* (rh:tan v_ang) d))
      );end_setq
      (rh:eml (polar pt3 (- h_ang (* pi 0.5)) 0.25) (polar pt3 (+ h_ang (* pi 0.5)) 0.25))
      (rh:emt (polar pt3 (- h_ang (* pi 0.5)) 0.25) (- h_ang (* pi 0.5)) tht (rtos z3 2 2))
      (setq d (+ d pd))
    );end_while
    (initget "Yes No")
    (setq ans (cond ( (getkword "\nAnother ? [Yes/No] <Yes> ")) ("Yes")))
  );end_while
  (princ)
);end_defun

 

 

Type MLL to run

I am not one of the robots you're looking for

0 Likes
Message 5 of 6

Kent1Cooper
Consultant
Consultant

@Anonymous wrote:

... I would like the AutoCAD to divide the line into equal sections of length=1 unit and put calculated values (based on slope) next to them. ....



BIG question that arises:  Since you say "(based on slope)", should that 1 unit spacing of the sections be along the slope of the Line if it actually had different Z coordinates at its ends?  Or purely in the XY plane as in your sample?  Since your sample drawing does not actually have anything at different Z coordinates, I can't tell what your intent really is.  Given the very slight slope represented [but not drawn  at a slope] in the sample, the result wouldn't look very different either way, but the calculated values could round a little differently depending on the number of decimal places, and at steeper changes in level the visible difference would become more meaningful.

Kent Cooper, AIA
0 Likes
Message 6 of 6

john.uhden
Mentor
Mentor

I presume you are drawing a 2D profile, where Y is the elevation (or level as some say), and wish to extract intermediate elevations (levels).

My first question is how can you divide the length into equal separations when the length is not an exact multiple of the separation?

2nd, why are your tic marks not vertical (perhaps even down to a datum line), as one would draw in a real profile?

3rd, have you any AutoLisp capabilities yourself?  I personally like to help people cook for themselves, rather than providing them a prepared meal (so to speak).

John F. Uhden

0 Likes