adding arc lengths

Discussion in 'AutoCAD' started by CVL Dneill, Jan 10, 2005.

  1. CVL Dneill

    CVL Dneill Guest

    I have a lisp routine that takes lines and lwpolylines and adds the lengths to give total lengths of all lines. I am trying to add to the routine to have it add in with the lines and lwpolylines the lengths of arcs as well but am having troubles making it happen. Any suggestions
     
    CVL Dneill, Jan 10, 2005
    #1
  2. CVL Dneill

    Adesu Guest

    lengths to give total lengths of all lines. I am trying to add to the
    routine to have it add in with the lines and lwpolylines the lengths of arcs
    as well but am having troubles making it happen. Any suggestions

    Hi CVL Dneill ,you can try from BillZ,here it's code

    ;03/09/04 Bill Zondlo
    ;program to get chord and arc length
    ;then figure included angle, radius and center point.

    (defun c:arc_2p (/ ctr d h k pt1 pt2 rad s theta x)
    (initget 1)
    (setq pt1 (getpoint "\nFirst point:")) ;first arc
    point.
    (initget 1)
    (setq pt2 (getpoint pt1 "\nSecond point:")) ;end of arc
    point (chord).
    (prompt (strcat "\n Length of Chord: < " (rtos (distance pt1 pt2) 2 4) "
    (initget 7)
    (setq s (getdist "\nEnter Length of Arc: < inches >"))
    (setq chord (distance pt1 pt2)
    k (/ chord s)
    y (- 1.0 k)
    x (- 24.0 (* 24.0 k)))
    (cond ((> s chord)
    ;---;
    (repeat 8
    (if (not (equal x 0.0 1e-5))
    (setq x (- x (/ (- (sin x)(* k x))(- (cos x) k)))
    ;Newton's Method - if arc lengths are not close to chord length.
    )
    )
    )
    ;end repeat.
    ;---;
    (if (or (minusp x)
    ;if arc length is close to chord length.
    (equal x 0.0 1e-5))
    (setq x (sqrt (* (* 6.0 y)(+ 1
    ;accuracy suffers on arc lengths that are very
    (/ (* 3.0 y) 20.0)
    ;much longer than the chord or that are very
    (/ (* 321.0 (* y 2.0)) 5600.0)
    ;close to chord length.
    (/ (* 3197.0 (* y 3.0))
    112000.0)
    (/ (* 445617.0 (* y 4.0))
    27596800.0)
    (/ (* 1766784699.0 (* y 5.0))
    179379200000.0)
    )
    )
    )
    ) ;end setq
    ) ;end minusp if
    ;---;
    (setq theta (* x 2.0)
    rad (/ s theta)
    d (* rad (cos x))
    ;center to chord distance.
    h (- rad d)
    ;bulge distance (if needed).
    ctr (polar pt1 (+ (angle pt1 pt2)(atan d (* (distance pt1
    pt2) 0.5))) rad)
    )
    (entmake (list (cons 0 "ARC")(cons 8 "0")(cons 10 ctr)(cons 40
    rad)(cons 50 (angle ctr pt1))(cons 51 (angle ctr pt2))))
    )
    ((<= s chord)
    (prompt "\nArc length is shorter or equal to chord.")
    )
    )
    ;end cond.
    (princ)
    )
     
    Adesu, Jan 11, 2005
    #2
  3. CVL Dneill

    Jimmy D Guest

    And here's another one I use:

    (defun c:CurveLength ( / ee eelen cnt strcnt ename oname param len lentot)
    (princ "\n***Length of different lines / objects - by Jimmy***")
    (vl-load-com)
    (defun *error* (msg)
    (princ "\nError: ")
    (Alert "Wrong selection.....")
    (princ)
    )
    (setq CNT 0 LenTot 0 Len 0)
    (setq EE (ssget))
    (setq EELen (sslength EE))
    (while (/= CNT EELen)
    (progn
    (setq
    oname (vlax-ename->vla-object (ssname EE CNT))
    param (vlax-curve-getEndParam oname) ; End parameter
    len (vlax-curve-getDistAtParam oname param)
    LenTot (+ LenTot Len)
    len 0
    CNT (+ CNT 1)
    )
    );end progn
    );end while
    (if
    (> CNT 1 )
    (setq StrCnt (strcat "\nTotal length of " (itoa CNT ) " selected" "\nobjects."))
    (setq StrCnt (strcat "\nTotal length of " (itoa CNT ) " selected" "\nobject."))
    );end if
    (setq FullTxt (strcat StrCnt " is : " (rtos LenTot) " mm." ))
    (alert Fulltxt)
    (vlax-release-object oname)
    (princ)
    )


    Jim
     
    Jimmy D, Jan 11, 2005
    #3
  4. The routine Adesu sent appears to ASK FOR the arc length from the user,
    whereas I took the original post to be wanting to select a pre-existing arc
    and CALCULATE the length of it, to be added to the lengths of other selected
    things.

    Here's one way to calculate the length of a selected arc:

    (setq arclist (entget (car (entsel "Select ARC: "))))
    (setq arcrad (cdr (assoc 40 arclist))
    ang1 (cdr (assoc 50 arclist))
    ang2 (cdr (assoc 51 arclist))
    )
    (if (> ang1 ang2)
    (setq sweep (+ ang2 (- (* 2 pi) ang1)))
    (setq sweep (- ang2 ang1))
    )
    (setq arclength (* arcrad sweep))

    Use the "arclength" variable in your cumulative addition.

    If you want to just select objects at random, you'd have to do some
    object-type testing, and if the object is an arc, feed it in there in place
    of the (entsel) part in the top line.
     
    Kent Cooper, AIA, Jan 11, 2005
    #4
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.