Jump to content

Filter LWPOLYLINE using SSGET with AREA is possible?


Miller87

Recommended Posts

I was wondering if there was a simple way ,in fews lines of code, to adding to a selection a group of polyline with equal area.

For example when we want to select closed LWPOLYLINE and store in"poly" we wrote:

(setq poly (ssget  "_A" '((0 . "LWPOLYLINE") (-4 . "&=") (70 . 1))))

 

Or a similar simple approach?

Thanks

Link to comment
Share on other sites

Since the polyline area is not stored in the DXF data for an LWPOLYLINE entity, you cannot filter polylines by area using an ssget filter list; instead, you would need to iterate over a selection of all candidate polylines, and remove those which do not meet the area criteria.

 

Lee

Link to comment
Share on other sites

The area would not be part of an entity list, but it would be an object property so it would be possible with lisp. With AutoCAD's accuracy odds are pretty slim you would find another one with the same area. Make sure they are closed, an area can be found even for polylines that aren't closed. What would you use this for?

Link to comment
Share on other sites

After trying and trying again finally another rough sleepless :ouch: routine.

Just change the "areavalue" for selecting the correct polyline in function of Areas.

 

(defun c:POLY (/)
(vl-load-com)
 (setq areavalue 10000.0)
 (setq counter 0)
 (setq sset (ssget  "X" '((0 . "LWPOLYLINE") (-4 . "&=") (70 . 1))))
 	(repeat (sslength sset)
 	(setq item (ssname sset counter))
 	;conversion enames -> vla OBJECT
 	(setq item (vlax-ename->vla-object item))
 	;READ THE AREA VALUE
 	(setq readarea (vlax-get-property item 'area ))
		(if (/= readarea areavalue)
	 ;conversion vla OBJECT -> enames
	(setq item (vlax-vla-object->ename item))
  		(ssdel item sset)
    		)	
(setq counter (1+ counter))
 	)
(princ)
)

 

tombu: defun for another lisp I work on.

Sure, now they're coming more refined solutions.

This is my first time I try to use VLAOBJECT. :)

Link to comment
Share on other sites

Good effort Miller! :thumbsup:

 

This would be the solution I would propose:

(defun c:polybyarea ( / ent idx sel tar )
   
   (setq tar 10000.0) ;; Target area value

   (if (setq sel (ssget "_X" '((0 . "LWPOLYLINE") (-4 . "&=") (70 . 1))))
       (repeat (setq idx (sslength sel))
           (if (not (equal tar (vlax-curve-getarea (setq ent (ssname sel (setq idx (1- idx))))) 1e-6))
               (ssdel ent sel)
           )
       )
   )
   (sssetfirst nil sel)
   (princ)
)
(vl-load-com) (princ)

A few notes:

 

  • You can avoid the inefficient conversion to a vla-object by using the vlax-curve-getarea function which will accept an ename argument.

 

  • When comparing doubles (reals) always use the equal function with some tolerance, as such values will rarely ever be exactly equal as a consequence of how they are represented in memory.

I hope this helps!

 

Lee

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...