Index for length of "LWPOLYLINE"?

Index for length of "LWPOLYLINE"?

samparer
Participant Participant
1,065 Views
9 Replies
Message 1 of 10

Index for length of "LWPOLYLINE"?

samparer
Participant
Participant

New to lisp, I cannot figure out what the index is for getting the length of a "LWPOLYLINE" (if there is one). Along with this is there any tips on finding these index's? I am going off of AfraLISP DXF Group Codes but this still requires quite a bit of guess work for me.

 

Any help is greatly appreciated. Apologies if a similar question has been asked before.

0 Likes
Accepted solutions (1)
1,066 Views
9 Replies
Replies (9)
Message 2 of 10

cadffm
Consultant
Consultant

Hi,

 

what call Index is the DXF or AutoLisp GroupCode.

In DXF and AutoLisp object-model objects don't have a length property!

If you need the length you can calculate the length of an object,

or jump into another of vlisp/activeX,

Or use these functions:

setpropertyvalue,getpropertyvalue

to check yourself what properties are available:

(dumpallproperties (car(entsel)))

(getpropertyvalue (car(entsel)) "Length")

 

 

 

Sebastian

Message 3 of 10

samparer
Participant
Participant

Thanks so much @cadffm that works when selecting manually but I am trying to automate and am cycling through all polylines using:

 

(setq ss (ssget "X" '((0 . "LWPOLYLINE"))))

(repeat (setq i (sslength ss))
(setq ent (entget (ssname ss (setq i (1- i)))))

 

and when trying to use:

 

(setq len (getpropertyvalue (car(ent)) "Length"))

 

I get a value of Nil from len, am I missing something obvious?

0 Likes
Message 4 of 10

rkmcswain
Mentor
Mentor

Close, but you need to convert the lisp entity to a vla-object

 

(vla-get-length (vlax-ename->vla-object (car (entsel))))

R.K. McSwain     | CADpanacea | on twitter
Message 5 of 10

cadffm
Consultant
Consultant

Hi.

open your help[F1], read about getpropertyvalue, see that this function want to get en ENAME

 

Your (ent) is a mistake, try it in commandline

Command:(ent)

Nothing senseful, or?

 

(getpropertyvalue ent "Length")

Or

(getpropertyvalue (ssname ss (setq i (1- i))) "Length")

looks better

 

 

BTW: What McSwain posted above is the other objectmodel what I wrote about (vlisp/activex).

You are new in Lisp, so I prefer you learn one of both worlds first (dxf/autolisp), then the other one (vlisp/activex).

Sebastian

Message 6 of 10

ВeekeeCZ
Consultant
Consultant
Accepted solution

@samparer wrote:

Thanks so much @cadffm that works when selecting manually but I am trying to automate and am cycling through all polylines using:

 

(setq ss (ssget "X" '((0 . "LWPOLYLINE"))))

(repeat (setq i (sslength ss))
(setq ent (entget (ssname ss (setq i (1- i)))))

 

and when trying to use:

 

(setq len (getpropertyvalue (car(ent)) "Length"))

 

I get a value of Nil from len, am I missing something obvious?


 

The correct syntax is just (setq len (getpropertyvalue ent "Length"))

 

That car portion probably comes from (entsel) which returns a list of (ent point) and you need to use car to get the first element of that list - ent. But (ssname) returns ent directly. Blue parents are simply wrong. Getproipertyvalue needs just ename, not a definition list.

 

Spoiler - entire code.

 

(defun c:PLength ( / ss len i ent)
  
  (if (and (setq ss (ssget "X" (list '(0 . "LWPOLYLINE") (cons 410 (getvar 'ctab)))))
	   (setq len 0)
	   )
    (repeat (setq i (sslength ss))
      (setq ent (ssname ss (setq i (1- i))))
      (setq len (+ len (getpropertyvalue ent "Length")))))

  (if len (princ (strcat "Overall length is: " (rtos len))))
  (princ)
  )

 

Message 7 of 10

Kent1Cooper
Consultant
Consultant

@samparer wrote:

.... what the index is for getting the length of a "LWPOLYLINE" (if there is one). .... is there any tips on finding these index's? .....


As others have implied, there isn't an entry in entity data for length -- it's only a result of the geometry of an object, determined by calculation from pieces of information that are stored in the list.

 

[The DXF codes are also in AutoCAD's Help system, listed >here<, though I haven't compared whether that source is any better or more comprehensive than AfraLisp's.]

 

IN CASE you need to do this with other kinds of objects, be aware that not everything that has length has a "Length" property.  For a Circle, it's "Circumference".  For an Ellipse or a Spline, it's not there at all, either as a VLA property or in the (getpropertyvalue) approach.  For an Arc, the VLA property is "ArcLength" but there isn't a (getpropertyvalue).  BUT there is a universal way of getting the length that can be used on all these as well as on things that have a "Length" property per se [Lines, Polylines].  If 'ent' is either an entity name or a VLA-object conversion of one, do this:

 

(vlax-curve-getDistAtParam ent (vlax-curve-getEndParam ent))

 

[Don't use  ...getDistAtPoint  and  ...getEndPoint , because for closed objects that returns 0.]

Kent Cooper, AIA
Message 8 of 10

calderg1000
Mentor
Mentor

Regards @samparer 

Here you go, complementing your code and using only native lisp

(defun c:lpol (/ ss ent lp)
  (setq ss (ssget "X" '((0 . "LWPOLYLINE"))))
  (repeat (setq i (sslength ss))
    (setq ent (ssname ss (setq i (1- i))))
    (vl-cmdf "area" "o" ent)
    (setq lp (cons (getvar 'perimeter) lp))
    (princ lp)
    (princ)
  )
)

 


Carlos Calderon G
EESignature
>Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.

0 Likes
Message 9 of 10

Kent1Cooper
Consultant
Consultant

@samparer wrote:

.... that works when selecting manually but I am trying to automate and am cycling through all polylines....


I think some people are getting ahead of the game.  One suggestion would report the total of the lengths of multiple selected Polylines, another would put those lengths into a list.  You haven't said what you intend to do with the lengths, but whatever that is, do you need help with that processing part, or are you just looking for how to get lengths of Polylines, and given that, you already know what you need to do with them?

Kent Cooper, AIA
0 Likes
Message 10 of 10

Sea-Haven
Mentor
Mentor

If your using Bricscad getproperty is not supported.

 

This can be a handy tool returns properties available for most objects.

 

Most times saved as dumpit.lsp for obvious reason.

;;;===================================================================; 
;;; DumpIt                                                            ; 
;;;-------------------------------------------------------------------; 
;;; Dump all methods and properties for selected objects              ; 
;;;===================================================================; 
(defun C:Dumpit ( / ent) 
  (while (setq ent (entsel)) 
    (vlax-Dump-Object 
      (vlax-Ename->Vla-Object (car ent)) 
    ) 
  ) 
  (princ) 
)

 

0 Likes