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

Getting length of closed polyline using VISUAL LISP EXTENSIONS

5 REPLIES 5
Reply
Message 1 of 6
jmodglin
195 Views, 5 Replies

Getting length of closed polyline using VISUAL LISP EXTENSIONS

Good day all. I have some routines that I am trying to get the length of a polyline. I use the follwing: (SETQ ENT (VLAX-ENAME->VLA-OBJECT (SSNAME SS (- CNT 1)))) (SETQ ELTH (VLAX-CURVE-GETDISTATPOINT ENT (VLAX-CURVE-GETENDPOINT ENT))) . That works fine unless the polyline is closed and then I have to resort to the old "AREA" command. Is there a Method (or Methods) that can get the distance of a closed Polyline? Thanks for any help. Joshua Modglin
5 REPLIES 5
Message 2 of 6
Anonymous
in reply to: jmodglin

Joshua,

I haven't worked with the curve functions a great deal. Have you tried
getting the end param and then using getDistAtParam?

There is an ActiveX wish list on the VBA group (the fact that is wasn't
posted here may be telling us something) where you could ask for a Length
property for polyline objects.
--
Cliff

"jmodglin" wrote in message
news:f084f7f.-1@WebX.maYIadrTaRb...
| Good day all. I have some routines that I am trying to get the length of a
polyline. I use the follwing: (SETQ ENT (VLAX-ENAME->VLA-OBJECT (SSNAME SS
(- CNT 1)))) (SETQ ELTH (VLAX-CURVE-GETDISTATPOINT ENT
(VLAX-CURVE-GETENDPOINT ENT))) . That works fine unless the polyline is
closed and then I have to resort to the old "AREA" command. Is there a
Method (or Methods) that can get the distance of a closed Polyline? Thanks
for any help. Joshua Modglin
|
Message 3 of 6
Anonymous
in reply to: jmodglin

Joshua,

My curiousity got the best of me. Try this out. I only tested it on a
closed old-style polyline.

(defun c:len ( / e ep d)
(if (setq e (car (entsel)))
(setq
e (vlax-ename->vla-object e)
ep (vlax-curve-getEndParam e)
d (vlax-curve-getDistAtParam e ep)
)
)
)
--
Cliff

"jmodglin" wrote in message
news:f084f7f.-1@WebX.maYIadrTaRb...
| Good day all. I have some routines that I am trying to get the length of a
polyline. I use the follwing: (SETQ ENT (VLAX-ENAME->VLA-OBJECT (SSNAME SS
(- CNT 1)))) (SETQ ELTH (VLAX-CURVE-GETDISTATPOINT ENT
(VLAX-CURVE-GETENDPOINT ENT))) . That works fine unless the polyline is
closed and then I have to resort to the old "AREA" command. Is there a
Method (or Methods) that can get the distance of a closed Polyline? Thanks
for any help. Joshua Modglin
|
Message 4 of 6
jmodglin
in reply to: jmodglin

Thanks Cliff, That was way too easy. I have never really understood the meaning of parameter as used by AutoCAD Methods. Could somebody give me direction on when (besides in this case) that I can used the **Param Methods? Thanks. Joshua Modglin
Message 5 of 6
Anonymous
in reply to: jmodglin

Already asked for there. I will reinforce the issue of a closed pline. But
it isn't only Autodesk that has forgotten about closed plines, in many cases
I have seen other routines to get pline length that forgot about closed
plines too (including closed *with* bulges!).

--
R. Robert Bell, MCSE
http://www.acadx.com


"Cliff Middleton" wrote in message
news:4F46884D584BA37A40E31A32AD620DC0@in.WebX.maYIadrTaRb...
| Joshua,
|
| I haven't worked with the curve functions a great deal. Have you tried
| getting the end param and then using getDistAtParam?
|
| There is an ActiveX wish list on the VBA group (the fact that is wasn't
| posted here may be telling us something) where you could ask for a Length
| property for polyline objects.
| --
| Cliff
|
Message 6 of 6
Anonymous
in reply to: jmodglin

The *PARAM* method means different things for different objects. In the
case of a polyline, it means a 'REAL number representing the position on the
polyline counting by primary vertices.
Here's an example:
(defun c:splitpoly ( / e ent etyp osmode cmd object closed
start end dist midp z)
(while (setq e (car (entsel "\nSelect a polyline to split: ")))
(setq ent (entget e)
etyp (cdr (assoc 0 ent))
object (vlax-ename->vla-object e)
)
(if (wcmatch etyp "LWPOLYLINE,POLYLINE")
(progn
(setq osmode (getvar "osmode")
cmd (getvar "cmdecho")
object (vlax-ename->vla-object e)
closed (= (logand (cdr (assoc 70 ent)) 1) 1)
end (vlax-curve-getendparam object)
dist (* 0.5 (vlax-curve-getDistAtParam object end))
midp (vlax-curve-getPointAtDist object dist)
)
(if (= etyp "LWPOLYLINE")
(setq z (cdr (assoc 38 ent))
start (cdr (assoc 10 ent))
start (list (car start)(cadr start) z)
midp (list (car midp)(cadr midp) z)
)
(setq start (cdr (assoc 10 (entget (entnext e)))))
)
(setvar "osmode" 0)
(setvar "cmdecho" 0)
(command "_.break" e (trans midp 0 1) "@")
(if (and closed (= etyp "LWPOLYLINE"))
(command "_.break" e (trans start 0 1) "@")
)
(setvar "osmode" osmode)
(setvar "cmdecho" cmd)
(prompt (strcat "\nPolyline split into " (rtos dist) " long
pieces"))
)
(prompt (strcat " Object selected is a(n) " etyp))
)
)
(princ)
)

--
John Uhden, Cadlantic/formerly CADvantage
--> mailto:juhden@cadlantic.com
--> http://www.cadlantic.com
2 Village Road
Sea Girt, NJ 08750
Tel. 732-974-1711
FAX 732-528-1332

"jmodglin" wrote in message
news:f084f7f.2@WebX.maYIadrTaRb...
> Thanks Cliff, That was way too easy. I have never really understood the
meaning of parameter as used by AutoCAD Methods. Could somebody give me
direction on when (besides in this case) that I can used the **Param
Methods? Thanks. Joshua Modglin
>

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

Post to forums  

Autodesk Design & Make Report

”Boost