    # Thread: With LISP, how can I tell how many segments are in a LWPOLYLINE ?

1. Login to Give a bone

## With LISP, how can I tell how many segments are in a LWPOLYLINE ?

Guys,
I am clear on how to get the start point, end point and to set a specific distance of a LWPOLYLINE.

(setq ET (entlast))
(setq OBJ (vlax-ename->vla-object ET))
(setq STRTPT (vlax-curve-getStartPoint OBJ))
(setq ENDPT (vlax-curve-getendPoint OBJ))
(setq PLPT (vlax-curve-getpointatdist OBJ "MyPolylinePoint"))

This will give me the angle of the first segment, if i am correct. Not clear on how it is doing it. I have read a previous thread though couldn't follow.

(setq ANGL
(* (/ 180 pi)
(angle (list 0.0 0.0 0.0)
(vlax-curve-getFirstDeriv OBJ
(vlax-curve-getparamatdist OBJ 0.0001))
)
)
)

Is it possible with code to determin how many actual segments a polyline has ?
How do I cycle through and get the angle and direction for multiple segments of the LWPOLYLINE ?

Could someone please try an explain the small code above that determins the angle and what it is doing ? The "K.I.S.S." (keep it simple stupid) method is much preffered as i am simple.

Any assistance is much appreciated.

Stephen  Reply With Quote

2. Login to Give a bone

## Re: With LISP, how can I tell how many segments are in a LWPOLYLINE ?

try this:
(setq ET (entlast))
(setq OBJ (vlax-ename->vla-object ET))

(setq SEG-COUNT (vlax-curve-getendparam OBJ))  Reply With Quote

3. Login to Give a bone

## Re: With LISP, how can I tell how many segments are in a LWPOLYLINE ?

See the second post.

Also see kennet's post below that one.  Reply With Quote

4. Login to Give a bone

## Re: With LISP, how can I tell how many segments are in a LWPOLYLINE ?

Thank you CADmium, that gets me the mumber of segments.

Cab2k,
I have been over that thread already and now again though not understanding it all. I wan't to be able to get the angles and lengths of all the segments if possible ? The answer is most likely in my face but just not understanding Kennet. Is there another thread that covers this topic in any simpler detail.

Stephen  Reply With Quote

5. Login to Give a bone

## Re: With LISP, how can I tell how many segments are in a LWPOLYLINE ?

See if this helps explain it.
Code:
```(defun C:TEST (/ curve idx ang)
(command "_.pline"
"_non" '(0 0)
"_non" '(10 0)
"_non" '(0 10)
"_non" '(0 20)
"_non" '(-10 20)
"_non" '(-10 10)
"")
(setq curve (entlast))
(setq idx 0)
(repeat (fix (1- (vlax-curve-getendparam curve)))
(setq ang (angle '(0 0) (vlax-curve-getFirstDeriv curve idx))) ; (+ idx 0.005)
(print "Angle of segment #")
(princ idx)
(princ " is ")
(princ ang)  Reply With Quote