Distance output in decimal

Discussion in 'AutoCAD' started by chall73, Mar 29, 2005.

  1. chall73

    chall73 Guest

    I am trying to use the distance command between two picked points. When I call the variable back up it is in decimal form and I need it to be in feet and inches. The units of the drawing are set in Feet and inches and if I use the dist command it works but I can't call two points p1 and p2 in the dist command.

    What am I doing wrong

    Thanks
     
    chall73, Mar 29, 2005
    #1
  2. chall73

    ECCAD Guest

    Try this lisp:
    (defun C:DFI ( / p1 p2 L FT IN ); Distance in Feet and Inches.
    (setq p1 (getpoint "\nPick 1st point:"))
    (setq p2 (getpoint p1 "\nPick 2nd point:"))
    (setq L (distance p1 p2))
    (if L
    (progn
    (setq FT (fix (/ L 12.0)))
    (setq IN (- L (* FT 12)))
    (setq IN (fix (atoi (rtos IN 2 0))))
    (prompt (strcat "\n ( The Length is: " (itoa FT) "'-" (itoa IN) (chr 34) ")"))
    (princ)
    ); progn
    ); if
    ); function

    Bob
     
    ECCAD, Mar 29, 2005
    #2
  3. chall73

    chall73 Guest

    This is should be a simple list i would think. I am using to try and teach myself something. You helped me before so would you mind looking at this lisp and tell me what I am doing write and wrong.
    I just wanted a lisp that would draw a pline and insert the length of that line nearby. I think that I am making the angle way too difficult and my p3 won't work

    (defun c:LD (/ p1 p2 p3 d1 a1 a2 a3 oldsnap oldlayer )
    ;DEFINE THE FUNCTION
    (while
    (setq oldsnap (getvar "osmode"))
    ;save snap settings

    (setq oldlayer (getvar "clayer"))
    ;get currant layer

    (setq p1 (getpoint "\nEnter the First Point: "))
    ;get the first point

    (setq p2 (getpoint "\nEnter the Second Point: "))
    ;get the second point

    (setvar "clayer" "cnr-design-zone")
    ;set to proper layer

    (setq d1 (distance p1 p2 ))
    ;get distance between two points

    (setq p3 (polar p1 1 12))

    (setq a1 (angle p1 p2 ))

    (setq a2 (* a1 180))

    (setq a3 (/ a2 pi ))

    (command "_pline" p1 p2 "")
    ;draw pline between p1 p2

    (command "text" p3 a3 d1 "")
    ;insert text at p1 with distance between p1 and p2
    )
    (setvar "osmode" oldsnap)
    ;reset snap

    (setvar "clayer" oldlayer)
    ;reset oldlayer

    (princ)
    ;clean running
    )
     
    chall73, Mar 29, 2005
    #3
  4. chall73

    ECCAD Guest

    Try this approach.
    :)

    ;; Degrees to Radians, Radians to Degrees
    (defun dtr (d) (* pi (/ d 180.0)))
    (defun rtd (r) (* 180.0 (/ r pi)))
    (defun c:LD (/ p1 p2 p3 d1 a1 a2 a3 oldsnap oldlayer )
    ;DEFINE THE FUNCTION
    (while
    (setq oldsnap (getvar "osmode"))
    ;save snap settings

    (setq oldlayer (getvar "clayer"))
    ;get currant layer

    (setq p1 (getpoint "\nEnter the First Point: "))
    ;get the first point

    (setq p2 (getpoint "\nEnter the Second Point: "))
    ;get the second point

    (setvar "clayer" "cnr-design-zone")
    ;set to proper layer

    (setq d1 (distance p1 p2 ))
    ;get distance between two points

    (setq TSZ 0.5); TEXT SIZE
    (setq MP (polar p1 (angle p1 p2) (/ (distance p1 p2) 2.0))); MidPoint of Line
    (setq ang (angle p1 p2)); angle
    (setq rot (+ ang (dtr 270))); perp
    (setq TIP (polar MP rot (* TSZ 1.0))); Offset Below
    (if (and (> ang (dtr 90))(<= ang (dtr 271)))
    (setq ang (+ ang (dtr 180)))
    ); if

    ;(setq p3 (polar p1 1 12))

    ;(setq a1 (angle p1 p2 ))

    ;(setq a2 (* a1 180))

    ;(setq a3 (/ a2 pi ))

    (command "_pline" p1 p2 "")
    ;draw pline between p1 p2

    ;(command "text" p3 a3 d1 "")
    (command "text" tip ang tsz "ADDED TEXT" "")

    ;insert text at p1 with distance between p1 and p2
    )
    (setvar "osmode" oldsnap)
    ;reset snap

    (setvar "clayer" oldlayer)
    ;reset oldlayer

    (princ)
    ;clean running
    )

    Bob
     
    ECCAD, Mar 29, 2005
    #4
  5. chall73

    Adesu Guest

    Hi chall73,try this
    (defun c:ld (/ p1 p2 p3 d1 a1 a2 a3 oldsnap oldlayer )
    (setq oldsnap (getvar "osmode"))
    (setvar "osmode" 1)
    (setq oldlayer (getvar "clayer"))
    (setq p1 (getpoint "\nEnter the First Point: "))
    (setq p2 (getpoint p1"\nEnter the Second Point: "))
    (command "_layer" "m" "cnr-design-zone" "")
    (setq d1 (distance p1 p2 ))
    (setq d1 (rtos (/ d1 25.4) 2 3))
    (setq p3 (polar p1 1 12))
    (setq a1 (angle p1 p2 ))
    (setq a2 (* a1 180))
    (setq a3 (/ a2 pi ))
    (if (= a3 0)(setq a3 1))
    (command "_pline" p1 p2 "")
    (command "text" p3 a3 "" d1 "")
    (setvar "osmode" oldsnap)
    (setvar "clayer" oldlayer)
    (princ)
    )


    call the variable back up it is in decimal form and I need it to be in feet
    and inches. The units of the drawing are set in Feet and inches and if I use
    the dist command it works but I can't call two points p1 and p2 in the dist
    command.
     
    Adesu, Mar 30, 2005
    #5
  6. chall73

    chall73 Guest

    Okay got a couple questions for you?

    What is this line trying to do?
    (setq TIP (polar MP rot (* TSZ 1.0))); Offset Below

    Also I was trying to match the angle of the text to the angle of the line and get the insertion point off the line.
    As the program runs now the insertion point of the text is the mid point of the line. The angle works fine for 0 degrees but if you go 90 then the text is rotated 1 degree.

    Thanks for the help earlier. I went and download the Afrolips help files. They are helping a lot.
     
    chall73, Mar 30, 2005
    #6
  7. chall73

    ECCAD Guest

    What is this line trying to do?
    (setq TIP (polar MP rot (* TSZ 1.0))); Offset Below<<
    TIP is 'text insertion point', MP is 'midpoint' of line.
    rot is rotation in degrees..perpendicular to line..
    TSZ is text size..
    This line sets TIP - relative to MP, at rot (90 or 270),
    and at a distance Text Size * 1.0.
    In other words, calculate TIP from Midpoint of line, perp +/-,
    and at text-height distance.
    Rotation of text (in order to follow line), should be:
    (setq text_rotation (rtd (angle p1 p2)))

    Not very clear is it..
    Bob
     
    ECCAD, Mar 30, 2005
    #7
  8. chall73

    chall73 Guest

    thanks,
    using the rtos worked great
     
    chall73, Mar 30, 2005
    #8
  9. chall73

    Adesu Guest

    You are welcome
     
    Adesu, Mar 31, 2005
    #9
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.