Insert slope between two picked points.

Discussion in 'AutoCAD' started by JonBaker, Apr 29, 2004.

  1. JonBaker

    JonBaker Guest

    I have the following lisp routine that works great. the only thing is that the "powers that be" want the entered slope to be displayed midway between the 2 selected points. I can do that, but the catch is that the text needs to be rotated similar to dimensions. catch #2 is that we would also like to have an arrow displayed just below the slope value.

    would it be easier to insert a block with an attribute? what are my other choices?

    tia...
    --
    Jonathan J. Baker
    Carroll & Lange, Inc.
    Professional Engineers & Land Surveyors
    Lakewood, Colorado
    ~~~~~~~~~~~~

    (defun c:ele ( / pt1 pt2 v1 tv) ;BLANK VARIABLES
    (while T ; do this forever until cancelled
    (setq
    pt1 (if pt2 pt2 (getpoint "\nPick Start Point:"))
    pt2 (getpoint "\nPick Point for Spot Elevation:")
    d1 (distance pt1 pt2)
    mid (list
    (/ (+ (car pt1) (car pt2)) 2)
    (/ (+ (cadr pt1) (cadr pt2)) 2)
    ; (/ (+ (caddr pt1) (caddr pt2)) 2)
    )
    )
    (if (= tval nil)
    (setq tval 2.0)
    )

    (princ "\nEnter the Slope Between Two Points in Percent Form (Use - for downward): <")
    (princ tval)
    (princ ">: ")
    (setq temp1 (getreal))
    (if (/= temp1 nil)
    (setq tval temp1)
    )

    (if (= v1 nil)
    (setq v1 10)
    (setq v1 (atof tv))
    )
    (princ "\nEnter the Elevation at Starting Point: <")
    (princ v1)
    (princ ">: ")
    (setq temp1 (getreal))
    (if (/= temp1 nil)
    (setq v1 temp1)
    )

    (setq
    sl1 (/ TVAL 100)
    pt3 (getpoint "\nPick insertion point of elevation text:")
    v2 (* d1 sl1)
    tv (rtos (+ v2 v1) 2 1)
    JON1 (RTOS TVAL 2 0)
    JON2 (strcat JON1 "%")
    )
    (COMMAND "-MTEXT" MID "J" "MC" "R" PT2 "W" 0 JON2 "")
    (command "_.leader" pt2 pt3 "" tv "")

    );end while
    )
     
    JonBaker, Apr 29, 2004
    #1
  2. Here's a routine I use to tell (in the command prompt area) the slope of a selected line, in all the formats I could imagine wanting (degrees, whatever-in-12, percentage, and 1-in-whatever), parts of which should be useful for you:

    [TellSlope]^C^C(setq sline (entget (car (entsel "Select LINE for Slope Report: ")))) \(setq rise (abs (- (caddr (assoc 11 sline)) (caddr +
    (assoc 10 sline)))) run (abs (- (cadr (assoc 11 sline)) (cadr (assoc 10 sline))))) (setq slope (/ rise run)) (setq epols +
    (rtos (/ 1 slope) 2 2)) (setq angdeg (angtos (atan rise run) 1 4) ang12 (rtos (* 12 slope) 2 2) pcnt (rtos (* 100 slope) 2 2)) +
    (strcat "Slope of LINE is " angdeg ", or " ang12 " in 12, or " pcnt " percent, or 1 in " epols ".")

    It's for absolute slope, so you'd probably want to mess with it if you need positive or negative answers, but then people have to be disciplined about which point they pick first.

    [I can't remember now what I meant by the quantity-name "epols" for the 1-in-whatever value...probably the last two letters are for Line Slope.]


    Your routine appears to ask the user to spell out the slope (which it seems might not need to have any relation to the ACTUAL slope between your pt1 & pt2), rather than to calculate the real slope for them (wouldn't that be preferred, if they're giving actual points?). You appear to want the slope as a percentage, so:
    - establish the rise and run between your pt1 & pt2 (in place of my assoc 10 & 11 for the endpoints of the selected line), something like:
    (setq rise (abs (- (cadr pt2) (cadr pt1))) run (abs (- (car pt2) (car pt1))))
    [If you left out the "abs" parts, this would give you positive results if pt2 was up and to the right of pt2, with variations for other directions.]
    - and calculate the slope as above:
    (setq slope (/ rise run))
    - and make the text content:
    (setq percenttext (strcat (rtos (* 100 slope) 2 2) "%"))
    - and set the angle for the text to match the slope, with "getangle" between pt1 & pt2, or as above:
    (setq angdeg (angtos (atan rise run) 1 4)

    You could have the text rounded to however many decimal places as you want, or here's a somewhat simpler way to prompt for the user to type something if you want them to "round" it, with the calculated text as a default they can accept:
    (setq slopeprompt (strcat "Slope Text <" percenttext ">: ")) (setq optionaltext (getstring T slopeprompt)) +
    (if (> (strlen optionaltext) 0) (setq percenttext optionaltext))

    or the last line there could be something like:
    (if (/= optionaltext nil) (setq percenttext optionaltext))

    - and put the text in:
    (command "TEXT" "S" "<your-text-style>" "M" mid <your-text-height-if-not-fixed> angdeg percenttext)
    [Plain old Text is a lot simpler to do this with than Mtext, unless you want the end result to be an Mtext entity for some reason.]

    I'd be inclined to use a block (designed around the expected size of the percentage text) for the arrow, because you can use that same mid-point and angle for inserting it. You could figure its X scale factor at 1 or -1 (or a scale-dependent multiple) depending on the positive/negative slope. You could probably also do that with an attribute, and assign the "percenttext" to the attribute, but someone else will have to figure that out -- I've never liked or had much use for attributes, so I don't work with them much.
    Kent Cooper, AIA

    ...
    I have the following lisp routine that works great. the only thing is that the "powers that be" want the entered slope to be displayed midway between the 2 selected points. I can do that, but the catch is that the text needs to be rotated similar to dimensions. catch #2 is that we would also like to have an arrow displayed just below the slope value.

    would it be easier to insert a block with an attribute? what are my other choices?

    tia...
    --
    Jonathan J. Baker
    Carroll & Lange, Inc.
    Professional Engineers & Land Surveyors
    Lakewood, Colorado
    ~~~~~~~~~~~~

    (defun c:ele ( / pt1 pt2 v1 tv) ;BLANK VARIABLES
    (while T ; do this forever until cancelled
    (setq
    pt1 (if pt2 pt2 (getpoint "\nPick Start Point:"))
    pt2 (getpoint "\nPick Point for Spot Elevation:")
    d1 (distance pt1 pt2)
    mid (list
    (/ (+ (car pt1) (car pt2)) 2)
    (/ (+ (cadr pt1) (cadr pt2)) 2)
    ; (/ (+ (caddr pt1) (caddr pt2)) 2)
    )
    )
    (if (= tval nil)
    (setq tval 2.0)
    )

    (princ "\nEnter the Slope Between Two Points in Percent Form (Use - for downward): <")
    (princ tval)
    (princ ">: ")
    (setq temp1 (getreal))
    (if (/= temp1 nil)
    (setq tval temp1)
    )

    (if (= v1 nil)
    (setq v1 10)
    (setq v1 (atof tv))
    )
    (princ "\nEnter the Elevation at Starting Point: <")
    (princ v1)
    (princ ">: ")
    (setq temp1 (getreal))
    (if (/= temp1 nil)
    (setq v1 temp1)
    )

    (setq
    sl1 (/ TVAL 100)
    pt3 (getpoint "\nPick insertion point of elevation text:")
    v2 (* d1 sl1)
    tv (rtos (+ v2 v1) 2 1)
    JON1 (RTOS TVAL 2 0)
    JON2 (strcat JON1 "%")
    )
    (COMMAND "-MTEXT" MID "J" "MC" "R" PT2 "W" 0 JON2 "")
    (command "_.leader" pt2 pt3 "" tv "")

    );end while
    )
     
    Kent Cooper, AIA, Apr 29, 2004
    #2
  3. JonBaker

    David Kozina Guest

    epols = slope spelled backwards?


    Here's a routine I use to tell (in the command prompt area) the slope of a
    selected line, in all the formats I could imagine wanting (degrees,
    whatever-in-12, percentage, and 1-in-whatever), parts of which should be
    useful for you:

    [TellSlope]^C^C(setq sline (entget (car (entsel "Select LINE for Slope
    Report: ")))) \(setq rise (abs (- (caddr (assoc 11 sline)) (caddr +
    (assoc 10 sline)))) run (abs (- (cadr (assoc 11 sline)) (cadr (assoc 10
    sline))))) (setq slope (/ rise run)) (setq epols +
    (rtos (/ 1 slope) 2 2)) (setq angdeg (angtos (atan rise run) 1 4) ang12
    (rtos (* 12 slope) 2 2) pcnt (rtos (* 100 slope) 2 2)) +
    (strcat "Slope of LINE is " angdeg ", or " ang12 " in 12, or " pcnt "
    percent, or 1 in " epols ".")

    It's for absolute slope, so you'd probably want to mess with it if you need
    positive or negative answers, but then people have to be disciplined about
    which point they pick first.

    [I can't remember now what I meant by the quantity-name "epols" for the
    1-in-whatever value...probably the last two letters are for Line Slope.]


    Your routine appears to ask the user to spell out the slope (which it seems
    might not need to have any relation to the ACTUAL slope between your pt1 &
    pt2), rather than to calculate the real slope for them (wouldn't that be
    preferred, if they're giving actual points?). You appear to want the slope
    as a percentage, so:
    - establish the rise and run between your pt1 & pt2 (in place of my assoc 10
    & 11 for the endpoints of the selected line), something like:
    (setq rise (abs (- (cadr pt2) (cadr pt1))) run (abs (- (car pt2) (car
    pt1))))
    [If you left out the "abs" parts, this would give you positive results if
    pt2 was up and to the right of pt2, with variations for other directions.]
    - and calculate the slope as above:
    (setq slope (/ rise run))
    - and make the text content:
    (setq percenttext (strcat (rtos (* 100 slope) 2 2) "%"))
    - and set the angle for the text to match the slope, with "getangle" between
    pt1 & pt2, or as above:
    (setq angdeg (angtos (atan rise run) 1 4)

    You could have the text rounded to however many decimal places as you want,
    or here's a somewhat simpler way to prompt for the user to type something if
    you want them to "round" it, with the calculated text as a default they can
    accept:
    (setq slopeprompt (strcat "Slope Text <" percenttext ">: ")) (setq
    optionaltext (getstring T slopeprompt)) +
    (if (> (strlen optionaltext) 0) (setq percenttext optionaltext))

    or the last line there could be something like:
    (if (/= optionaltext nil) (setq percenttext optionaltext))

    - and put the text in:
    (command "TEXT" "S" "<your-text-style>" "M" mid
    <your-text-height-if-not-fixed> angdeg percenttext)
    [Plain old Text is a lot simpler to do this with than Mtext, unless you want
    the end result to be an Mtext entity for some reason.]

    I'd be inclined to use a block (designed around the expected size of the
    percentage text) for the arrow, because you can use that same mid-point and
    angle for inserting it. You could figure its X scale factor at 1 or -1 (or
    a scale-dependent multiple) depending on the positive/negative slope. You
    could probably also do that with an attribute, and assign the "percenttext"
    to the attribute, but someone else will have to figure that out -- I've
    never liked or had much use for attributes, so I don't work with them much.
    Kent Cooper, AIA

    ...
    I have the following lisp routine that works great. the only thing is that
    the "powers that be" want the entered slope to be displayed midway between
    the 2 selected points. I can do that, but the catch is that the text needs
    to be rotated similar to dimensions. catch #2 is that we would also like to
    have an arrow displayed just below the slope value.

    would it be easier to insert a block with an attribute? what are my other
    choices?

    tia...
    --
    Jonathan J. Baker
    Carroll & Lange, Inc.
    Professional Engineers & Land Surveyors
    Lakewood, Colorado
    ~~~~~~~~~~~~

    (defun c:ele ( / pt1 pt2 v1 tv) ;BLANK VARIABLES
    (while T ; do this forever until cancelled
    (setq
    pt1 (if pt2 pt2 (getpoint "\nPick Start Point:"))
    pt2 (getpoint "\nPick Point for Spot Elevation:")
    d1 (distance pt1 pt2)
    mid (list
    (/ (+ (car pt1) (car pt2)) 2)
    (/ (+ (cadr pt1) (cadr pt2)) 2)
    ; (/ (+ (caddr pt1) (caddr pt2)) 2)
    )
    )
    (if (= tval nil)
    (setq tval 2.0)
    )

    (princ "\nEnter the Slope Between Two Points in Percent Form (Use - for
    downward): <")
    (princ tval)
    (princ ">: ")
    (setq temp1 (getreal))
    (if (/= temp1 nil)
    (setq tval temp1)
    )

    (if (= v1 nil)
    (setq v1 10)
    (setq v1 (atof tv))
    )
    (princ "\nEnter the Elevation at Starting Point: <")
    (princ v1)
    (princ ">: ")
    (setq temp1 (getreal))
    (if (/= temp1 nil)
    (setq v1 temp1)
    )

    (setq
    sl1 (/ TVAL 100)
    pt3 (getpoint "\nPick insertion point of elevation text:")
    v2 (* d1 sl1)
    tv (rtos (+ v2 v1) 2 1)
    JON1 (RTOS TVAL 2 0)
    JON2 (strcat JON1 "%")
    )
    (COMMAND "-MTEXT" MID "J" "MC" "R" PT2 "W" 0 JON2 "")
    (command "_.leader" pt2 pt3 "" tv "")

    );end while
    )
     
    David Kozina, Apr 29, 2004
    #3
  4. I guess that's probably it -- I wouldn't have thought I was that clever, but
    it was a long time ago.

    Kent Cooper, AIA

     
    Kent Cooper, AIA, Apr 29, 2004
    #4
  5. JonBaker

    Jamie Duncan Guest

    That's for slopes going the other way.....


    Jamie Duncan
     
    Jamie Duncan, Apr 30, 2004
    #5
  6. JonBaker

    John Uhden Guest

    Recommended choice is a "SlopeArrow" block (just made that up) that's rotated in
    the downhill direction. It's up to you if you want the slope label as an
    attribute, but it's probably less work to keep the text as a separate entity.
    Either way they'll most likely overlap something and need to be manually
    adjusted for readability. Then again, something I never got to is the same
    thing but along a curve, in which case a 3-vertex polyline with the first vertex
    having a graduated width would work better. Towns around here like to see all
    the driveway slopes on plot plans, and my most exotic client provides, er, quite
    exotic driveways. Right now I still use my FLARROW routine and then add the
    text manually <I should take care of myself before others, but that's the way it
    goes>.




    "JonBaker" <jbaker at carrol-lange dot com> wrote in message
    I have the following lisp routine that works great. the only thing is that the
    "powers that be" want the entered slope to be displayed midway between the 2
    selected points. I can do that, but the catch is that the text needs to be
    rotated similar to dimensions. catch #2 is that we would also like to have an
    arrow displayed just below the slope value.

    would it be easier to insert a block with an attribute? what are my other
    choices?

    tia...
    --
    Jonathan J. Baker
    Carroll & Lange, Inc.
    Professional Engineers & Land Surveyors
    Lakewood, Colorado
    ~~~~~~~~~~~~

    (defun c:ele ( / pt1 pt2 v1 tv) ;BLANK VARIABLES
    (while T ; do this forever until cancelled
    (setq
    pt1 (if pt2 pt2 (getpoint "\nPick Start Point:"))
    pt2 (getpoint "\nPick Point for Spot Elevation:")
    d1 (distance pt1 pt2)
    mid (list
    (/ (+ (car pt1) (car pt2)) 2)
    (/ (+ (cadr pt1) (cadr pt2)) 2)
    ; (/ (+ (caddr pt1) (caddr pt2)) 2)
    )
    )
    (if (= tval nil)
    (setq tval 2.0)
    )

    (princ "\nEnter the Slope Between Two Points in Percent Form (Use - for
    downward): <")
    (princ tval)
    (princ ">: ")
    (setq temp1 (getreal))
    (if (/= temp1 nil)
    (setq tval temp1)
    )

    (if (= v1 nil)
    (setq v1 10)
    (setq v1 (atof tv))
    )
    (princ "\nEnter the Elevation at Starting Point: <")
    (princ v1)
    (princ ">: ")
    (setq temp1 (getreal))
    (if (/= temp1 nil)
    (setq v1 temp1)
    )

    (setq
    sl1 (/ TVAL 100)
    pt3 (getpoint "\nPick insertion point of elevation text:")
    v2 (* d1 sl1)
    tv (rtos (+ v2 v1) 2 1)
    JON1 (RTOS TVAL 2 0)
    JON2 (strcat JON1 "%")
    )
    (COMMAND "-MTEXT" MID "J" "MC" "R" PT2 "W" 0 JON2 "")
    (command "_.leader" pt2 pt3 "" tv "")

    );end while
    )
     
    John Uhden, Apr 30, 2004
    #6
  7. You know, in looking at some other people's responses, I'm realizing I may have misunderstood where you're putting this slope and arrow in. I thought (and my first post was based on that assumption) you were doing it in SECTION. If you're talking about a PLAN, then much of my first post (the parts about calculating the actual slope between the picked points, and all that follows from that) is, if you'll pardon the expression, "pointless." The Plan view application would explain why you would have the user typing in what the slope percentage is. Oh, well... Maybe you can find a use for it all in Section or Elevation views, anyway.
    Kent Cooper, AIA

    ...
    ....
    Your routine appears to ask the user to spell out the slope (which it seems might not need to have any relation to the ACTUAL slope between your pt1 & pt2), rather than to calculate the real slope for them (wouldn't that be preferred, if they're giving actual points?).
    ....
     
    Kent Cooper, AIA, Apr 30, 2004
    #7
  8. JonBaker

    JonBaker Guest

    thanx guys.. sorry but I don't have internet connection but once a day.. (lunch time)

    the slopes are for plan view Plot Plans.. they still do that by hand here trying to bring them into the 20th century.. lol..

    I will tinker around and let ya know what I come up with..

    thanx again.

    --

    Jonathan J. Baker
    Carroll & Lange, Inc.
    Professional Engineers & Land Surveyors
    Lakewood, Colorado
    ~~~~~~~~~~~~

    "JonBaker" <jbaker at carrol-lange dot com> wrote in message I have the following lisp routine that works great. the only thing is that the "powers that be" want the entered slope to be displayed midway between the 2 selected points. I can do that, but the catch is that the text needs to be rotated similar to dimensions. catch #2 is that we would also like to have an arrow displayed just below the slope value.

    would it be easier to insert a block with an attribute? what are my other choices?

    tia...
    --
    Jonathan J. Baker
    Carroll & Lange, Inc.
    Professional Engineers & Land Surveyors
    Lakewood, Colorado
    ~~~~~~~~~~~~

    (defun c:ele ( / pt1 pt2 v1 tv) ;BLANK VARIABLES
    (while T ; do this forever until cancelled
    (setq
    pt1 (if pt2 pt2 (getpoint "\nPick Start Point:"))
    pt2 (getpoint "\nPick Point for Spot Elevation:")
    d1 (distance pt1 pt2)
    mid (list
    (/ (+ (car pt1) (car pt2)) 2)
    (/ (+ (cadr pt1) (cadr pt2)) 2)
    ; (/ (+ (caddr pt1) (caddr pt2)) 2)
    )
    )
    (if (= tval nil)
    (setq tval 2.0)
    )

    (princ "\nEnter the Slope Between Two Points in Percent Form (Use - for downward): <")
    (princ tval)
    (princ ">: ")
    (setq temp1 (getreal))
    (if (/= temp1 nil)
    (setq tval temp1)
    )

    (if (= v1 nil)
    (setq v1 10)
    (setq v1 (atof tv))
    )
    (princ "\nEnter the Elevation at Starting Point: <")
    (princ v1)
    (princ ">: ")
    (setq temp1 (getreal))
    (if (/= temp1 nil)
    (setq v1 temp1)
    )

    (setq
    sl1 (/ TVAL 100)
    pt3 (getpoint "\nPick insertion point of elevation text:")
    v2 (* d1 sl1)
    tv (rtos (+ v2 v1) 2 1)
    JON1 (RTOS TVAL 2 0)
    JON2 (strcat JON1 "%")
    )
    (COMMAND "-MTEXT" MID "J" "MC" "R" PT2 "W" 0 JON2 "")
    (command "_.leader" pt2 pt3 "" tv "")

    );end while
    )
     
    JonBaker, Apr 30, 2004
    #8
Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.