Continuous Sum Arcs & Lines

Discussion in 'AutoCAD' started by kb, May 17, 2004.

  1. kb

    kb Guest

    I need a function where I can select arc and lines; and get a total length of all the objects seleted. With coco commands I'm not able to select arcs and lines while keeping a running total. Is there a way that I could combine these two lisp routines in order to do just that? This function is to be used with Autocad 2004

    Line Lisp:

    (defun C:LINESUM ()
    (setq sset (ssget '((0 . "LINE"))))
    (if sset
    (progn
    (setq tot 0.0)
    (setq num (sslength sset) itm 0)
    (while (< itm num)
    (setq hnd (ssname sset itm))
    (setq ent (entget hnd))
    (setq pt1 (cdr (assoc 10 ent)))
    (setq pt2 (cdr (assoc 11 ent)))
    (setq dis (distance pt1 pt2))
    (setq tot (+ tot dis))
    (setq itm (1+ itm))
    )
    (princ (strcat "\nTotal Distance = " (rtos tot)))
    )
    )
    (princ)
    )

    Arc Lisp:

    (defun c:arcsum ()
    (setq tlen 0.0)
    (setq sset (ssget '((0 . "ARC"))))
    (setq num (sslength sset) itm 0)
    (while (< itm num)
    (setq hnd (ssname sset itm))
    (setq ent (entget hnd))
    (setq rads (cdr (assoc 40 ent)))
    (setq sang (cdr (assoc 50 ent)))
    (setq eang (cdr (assoc 51 ent)))
    (if (> eang sang)
    (setq iang (- eang sang))
    (setq iang (+ (- 6.28319 sang) eang))
    )
    (setq larc (* iang rads))
    (setq tlen (+ tlen larc))
    (setq itm (1+ itm))
    )
    (princ (strcat "\nTotal = " (rtos tlen)))
    (princ)
    )
     
    kb, May 17, 2004
    #1
  2. kb

    R.K. McSwain Guest

    What are 'coco' commands?

    BTW, the lisp code you posted is missing it's headers and is not supposed to be posted in a public forum per the author.
     
    R.K. McSwain, May 17, 2004
    #2
  3. kb

    MTV4 Guest

    Are the author of the posted routines?
     
    MTV4, May 17, 2004
    #3
  4. kb

    MTV4 Guest

    Are you the author of the posted routines?
     
    MTV4, May 17, 2004
    #4
  5. kb

    Jeff Mishler Guest

    Here's one I wrote to do this.

    Jeff

    (defun c:linarcsum (/ ans)
    (vl-load-com)
    (initget "New Continue")
    (setq ans (getkword "\nNew set or continue adding?[New/Continue]: "))
    (cond ((= ans "New")(setq *totallength 0))
    ((not *totallength)(setq *totallength 0))
    )
    (if (ssget '((0 . "LINE,ARC")))
    (vlax-for ent (vla-get-activeselectionset
    (vla-get-activedocument
    (vlax-get-acad-object)))
    (if (wcmatch (vla-get-objectname ent) "*Line*")
    (setq *totallength (+ *totallength (vla-get-length ent)))
    (setq *totallength (+ *totallength (vla-get-arclength ent)))
    )
    )
    )
    (if (> *totallength 0)
    (princ (strcat "\n Total length of selected arcs and lines = " (rtos
    *totallength)))
    )
    (princ)
    )


    of all the objects seleted. With coco commands I'm not able to select
    arcs and lines while keeping a running total. Is there a way that I could
    combine these two lisp routines in order to do just that? This function is
    to be used with Autocad 2004
     
    Jeff Mishler, May 17, 2004
    #5
  6. kb

    R.K. McSwain Guest

    No.
     
    R.K. McSwain, May 17, 2004
    #6
  7. kb

    kb Guest

    Thanks Jeff, that's what I was looking for.

    No, I wasnt' the author of the code I posted, but I thought I would save space by not posting the comments, since it was not relavient to my question. My appologies. I will not be using the routines now after the replys.

    If you would like the header that was in the code here it is:

    ; ----------------------------------------------------------------------
    ; (Returns the sum of selected arc objects)
    ; Copyright (C) 1998 DotSoft, All Rights Reserved
    ; Website: www.dotsoft.com
    ; ----------------------------------------------------------------------
    ; DISCLAIMER: DotSoft Disclaims any and all liability for any damages
    ; arising out of the use or operation, or inability to use the software.
    ; FURTHERMORE, User agrees to hold DotSoft harmless from such claims.
    ; DotSoft makes no warranty, either expressed or implied, as to the
    ; fitness of this product for a particular purpose. All materials are
    ; to be considered ‘as-is’, and use of this software should be
    ; considered as AT YOUR OWN RISK.
    ; ----------------------------------------------------------------------
     
    kb, May 17, 2004
    #7
  8. kb

    kb Guest

    As well, this routine I am using does not state anywhere that it cannot be posted on a forum.

    That was a typo above, I was refering to 'CoGo'
     
    kb, May 17, 2004
    #8
  9. Modify to suit your needs

    ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
    ;; CRVLEN.LSP Copyright 2003, Tony Tanzillo
    ;;
    ;; Provided for private use only, reproduction or
    ;; redistribution expressly prohibited.
    ;;
    ;; Adds LENGTH command to AutoCAD which when used, will report
    ;; the total length of all selected 2D curves (including lines,
    ;; polylines, arcs, splines, and elliptical curves).
    ;;
    ;; Does not add length of CIRCLES.

    (defun C:LENGTH ( / ss len i)
    (vl-load-com)
    (setq ss (ssget '((0 .
    "LINE,ARC,SPLINE,ELLIPSE,POLYLINE,LWPOLYLINE")))
    len 0.0
    )
    (repeat (setq i (sslength ss))
    (setq len (+ len (getlength (ssname ss (setq i (1- i))))))
    )
    (write-line (strcat "\nTotal length = " (rtos len)))
    (princ)
    )

    (defun getLength (ename / acurve len)
    (setq ACurve (vlax-ename->vla-object ename))
    (setq len 0.0)
    (vl-catch-all-apply
    '(lambda ()
    (setq len
    (vlax-curve-getDistAtParam
    ACurve
    (vlax-curve-getEndParam ACurve)
    )
    )
    )
    )
    len
    )

    ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;




    commands I'm not able to select arcs and lines while keeping a running total. Is there a way that I could combine these
    two lisp routines in order to do just that? This function is to be used with Autocad 2004
     
    Tony Tanzillo, May 18, 2004
    #9
  10. kb

    R.K. McSwain Guest

    The website from which it was downloaded, does state this.
     
    R.K. McSwain, May 18, 2004
    #10
  11. kb

    kb Guest

    thanks Tony!! Very cool, this is exactly the information I was looking for.
     
    kb, May 18, 2004
    #11
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.