Visual LISP, AutoLISP and General Customization
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Getting length of a polyline segment and storing it to a variable

4 REPLIES 4
SOLVED
Reply
Message 1 of 5
silambua36
2260 Views, 4 Replies

Getting length of a polyline segment and storing it to a variable

Hi everyone!
I'm a beginner trying to learn Autolisp functions!
I'm actually trying to write a routine that can calculate the number of objects to be placed at the given spacing along a line or a polyline! So I need to get the length of the line or a polyline segment (just a segment) first. Obviously i can do it with getdist function! But it works for a straight line, when it comes to arc i need to measure the arc length and enter it manually!
So I'm looking for an Autolisp routine that can get the length of a line or a particular segment of a polyline consiting of both straight line and curves and store it to a variable! If I can get the length stored to a variable i can workout the calculations! And important thing is I don't want the total length of polyline just a segment length as different segments have different spacing


Thanks in advance!
4 REPLIES 4
Message 2 of 5
Kent1Cooper
in reply to: silambua36


@silambua36 wrote:
…. get the length of a line or a particular segment of a polyline consiting of both straight line and curves and store it to a variable! …. I don't want the total length of polyline just a segment length as different segments have different spacing ….

 

Do I assume correctly that you would pick  on the segment you want the length of?  If so, try this [lightly tested]:

(setq
  plsel (entsel "\nSelect Polyline on segment to get length of: ")
  pl (car plsel)
  prepar (fix (vlax-curve-getParamAtPoint pl (osnap (cadr plsel) "_nea")))
  segmentlength
    (-
      (vlax-curve-getDistAtParam pl (1+ prepar))
      (vlax-curve-getDistAtParam pl prepar)
    )
)

You could add things such as to verify that you picked on a Polyline, etc.

Kent Cooper, AIA
Message 3 of 5
silambua36
in reply to: Kent1Cooper

Hi Kent Cooper

Thank you for replying! The code works just fine on polylines! But i need to also pickup line length sometimes! Can you modify this so i can get either line or polyline length?

Once again thank you so much!
Message 4 of 5
Kent1Cooper
in reply to: silambua36


@silambua36 wrote:
…. Can you modify this so i can get either line or polyline length? ….

 

This will do that, not just for a Line or Polyline, but also an Arc, Circle, or Spline.

(setq
  esel (entsel "\nSelect object or Polyline segment to get length of: ")
  ent (car esel)
  len
    (if (wcmatch (cdr (assoc 0 (entget ent))) "*POLYLINE")
      (- ; then
        (vlax-curve-getDistAtParam ent
          (1+
            (setq prepar (fix (vlax-curve-getParamAtPoint ent (osnap (cadr esel) "_nea"))))
          )
        )
        (vlax-curve-getDistAtParam ent prepar)
      )
      (vlax-curve-getDistAtParam ent (vlax-curve-getEndParam ent)); else
    )
)
Kent Cooper, AIA
Message 5 of 5
silambua36
in reply to: Kent1Cooper

It works...

Thank you so much!

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

AutoCAD Inside the Factory


Autodesk Design & Make Report