plinelength

Discussion in 'AutoCAD' started by Marcel Janmaat, Nov 28, 2004.

  1. Has anybody got a suggestion for me on how to obtain (with lisp) the total
    length of a pline witch consists of several vertices?

    Thanx
    M
     
    Marcel Janmaat, Nov 28, 2004
    #1
  2. Marcel Janmaat

    ECCAD Guest

    Marcel, this seems to work.

    (defun C:gpl (/ obj oname len endpt begpt)
    (vl-load-com)
    (setq ent (car (entsel "\nSelect a Polyline:")))
    (setq obj (vlax-ename->vla-object ent))
    (setq oname (vlax-get obj 'ObjectName))
    (if (or (= "AcDbPolyline" oname)(= "AcDbArc" oname))
    (progn
    (setq len (vlax-curve-getdistatpoint obj (vlax-curve-getendpoint obj))); length
    (setq endpt (vlax-curve-getendpoint obj)); end point
    (setq begpt (vlax-curve-getstartpoint obj)); begin point
    ); progn
    ); if
    (if len
    (prompt (strcat "\n\nLength=" (rtos len)))
    ); if
    (princ)
    ); function

    Bob
     
    ECCAD, Nov 28, 2004
    #2
  3. Marcel Janmaat

    Rakesh Rao Guest

    Mercel,


    This is in the form of an AutoLisp function. Returns the length of any
    curve object line line, polyline, arc, spline etc.

    ;; !
    ***************************************************************************
    ;; ! MI_CurveLength
    ;; !
    ***************************************************************************
    ;; ! Function : Returns the linear slope length of the curve object.
    ;; ! and under it.
    ;; ! Argument : 'ename' - Curve object name
    ;; ! Returns : None
    ;; ! Updated : November 21, 2003
    ;; ! e-mail :
    ;; ! Web : www.4d-technologies.com
    ;; !
    ****************************************************************************

    (defun MI_CurveLength ( ename / oname param len )
    (setq
    oname (vlax-ename->vla-object ename)
    param (vlax-curve-getEndParam oname) ; End parameter
    len (vlax-curve-getDistAtParam oname param)
    )
    (vlax-release-object oname)
    len
    )

    Regards
    Rakesh



    --
    --
    - Rakesh Rao [ rakesh.rao (at)4d-technologies.com ]
    - Four Dimension Technologies
    [www.4d-technologies.com]
    - Get GeoTools, Work smarter: www.4d-technologies.com/geotools
    - Free Lisp downloads @ TechCenter: www.4d-technologies.com/techcenter
     
    Rakesh Rao, Nov 29, 2004
    #3
  4. Marcel Janmaat

    Jürg Menzi Guest

    Hi Marcel

    Visit my homepage -> Free Stuff and search for 'VxGetObjLength'.

    Cheers
     
    Jürg Menzi, Nov 29, 2004
    #4
  5. Thanx Bob! This, I needed.
    I don't know why you did put in the endpt and begpt though.

    But it works. Thanx!

    This is what i've made of it. Now it measures te length of both lines and
    plines.

    (defun lintel ()
    (setq tel 0 dl1 0)
    (repeat (sslength ss1)
    (setq el1 (entget (setq enm (ssname ss1 tel))))
    (if (= (cdr (assoc 0 el1)) "LINE")
    (setq dl1 (+ dl1 (distance (cdr (assoc 10 el1)) (cdr (assoc 11
    el1)))))
    )
    (setq onm (vlax-get (setq obj (vlax-ename->vla-object enm))
    'ObjectName))
    (if (or (= "AcDbPolyline" onm)(= "AcDbArc" onm))
    (setq dl1 (+ dl1 (vlax-curve-getdistatpoint obj
    (vlax-curve-getendpoint obj))))
    )
    (setq tel (1+ tel))
    )
    (dos_msgbox (strcat "The total length of all selected lines is " (rtos (/
    dl1 1000) 2 2) "meters.") "Opmerking!" 1 1)
    )

    Marcel
     
    Marcel Janmaat, Dec 1, 2004
    #5
  6. Marcel Janmaat

    Jeff Mishler Guest

    FWIW, here's one I use that will return the length of most objects that
    could have a length.......Spline, 2dPline, 3dPline, LWPline, Line, Arc

    (defun getlength (ent / objPoly len)
    (if (wcmatch (strcase (cdr (assoc 0 (entget (car ent))))) "*LINE,ARC")
    (setq objPoly (vlax-ename->vla-object (car ent))
    len (vlax-curve-getdistAtParam objPoly
    (vlax-curve-getEndParam objPoly))
    )
    )
    )

    (defun c:length ( / ent len)
    (if (setq ent (entsel "\nSelect object to obtain length for: "))
    (if (setq len (getlength ent))
    (princ (strcat "\nObject length is: " (rtos len)))
    (princ "\nObject doesn't have a length.")
    )
    (princ "\nNothing selected, exiting...")
    )
    (princ)
    )
     
    Jeff Mishler, Dec 1, 2004
    #6
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.
Similar Threads
There are no similar threads yet.
Loading...