Miller87 Posted April 28, 2015 Share Posted April 28, 2015 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 Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted April 28, 2015 Share Posted April 28, 2015 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 Quote Link to comment Share on other sites More sharing options...
tombu Posted April 28, 2015 Share Posted April 28, 2015 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? Quote Link to comment Share on other sites More sharing options...
Miller87 Posted April 28, 2015 Author Share Posted April 28, 2015 After trying and trying again finally another rough sleepless 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. Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted April 28, 2015 Share Posted April 28, 2015 Good effort Miller! 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 Quote Link to comment Share on other sites More sharing options...
Miller87 Posted April 29, 2015 Author Share Posted April 29, 2015 Thanks Master Lee Mac! I wil treasure your notes. Miller Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted April 29, 2015 Share Posted April 29, 2015 You're most welcome Miller Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.