Emmanuel Delay Posted January 4, 2022 Share Posted January 4, 2022 An example, this is the result of (setq ent (entget (car (eltsel "\nSelect object: ")))) ((-1 . <Entity name: 1770492fe00>) (0 . "POLYLINE") (330 . <Entity name: 176be833f00>) (5 . "BBD8") (100 . "AcDbEntity") (67 . 0) (410 . "Model") (8 . "0") (100 . "AcDb3dPolyline") (66 . 1) (10 0.0 0.0 0.0) ... (assoc 100 ent) will return (100 . "AcDbEntity"). How do I get that second one, the (100 . "AcDb3dPolyline") ? Quote Link to comment Share on other sites More sharing options...
Steven P Posted January 4, 2022 Share Posted January 4, 2022 reverse the list, do the assoc on that? So long as there are only two '100's that should do it Quote Link to comment Share on other sites More sharing options...
Emmanuel Delay Posted January 4, 2022 Author Share Posted January 4, 2022 Ah yes, that's an idea. Is there also any obvious solution in case there's more than 2? Quote Link to comment Share on other sites More sharing options...
tombu Posted January 4, 2022 Share Posted January 4, 2022 This will return the entity list from the second one on: (member (assoc 100 (cdr (member (assoc 100 ent) ent))) ent) You could save and repeat until none remain. 2 Quote Link to comment Share on other sites More sharing options...
Emmanuel Delay Posted January 4, 2022 Author Share Posted January 4, 2022 Ah yes, that's it. I'll use that one. Quote Link to comment Share on other sites More sharing options...
dan20047 Posted January 4, 2022 Share Posted January 4, 2022 Here is my utility function for multiple associations, credit Tony Tanzillo 1999. ;;;========================================================================= ;;; massoc ;;; ;;; get multiple items from an association list (instead of just 1st one) ;;; ;;; From: Tony Tanzillo (tony.tanzillo@worldnet.att.net) ;;; Subject: Re: extracting multiple assoc from list ;;; Newsgroups: autodesk.autocad.customization ;;; Date: 1999/09/29 ;;; ;;; revised by Dan, 2017 ;;; to add option for key to be a list of assoc codes, '(10 11), or just a single ;;;========================================================================= (defun massoc (key alist / x nlist) (if (not (= 'LIST (type key))) (setq key (list key)) ) (foreach y key (foreach x alist (if (eq y (car x)) (setq nlist (cons (cdr x) nlist)) ) ) ) (reverse nlist) ) ;end defun 1 Quote Link to comment Share on other sites More sharing options...
mhupp Posted January 4, 2022 Share Posted January 4, 2022 (edited) Basically the same thing just condensed down a little more. ;(cdrs 10 (entget (car (entsel "\nSelect a polyline: ")))) ;returns something like this: ;((259.943 -252.219) (214.182 -140.305) (254.223 -92.925) (215.0 -21.0386) ; (253.406 41.8621) (215.817 112.115)) ;Michal Puckett (defun cdrs (key lst / pair rtn) (while (setq pair (assoc key lst)) (setq rtn (cons (cdr pair) rtn) lst (cdr (member pair lst)) ) ) (reverse rtn) ) Edited January 4, 2022 by mhupp 1 Quote Link to comment Share on other sites More sharing options...
ronjonp Posted January 4, 2022 Share Posted January 4, 2022 Another one commonly used to pull point lists .. modified for 100 code: (mapcar 'cdr (vl-remove-if '(lambda (x) (/= 100 (car x))) elist)) 2 1 Quote Link to comment Share on other sites More sharing options...
dan20047 Posted January 4, 2022 Share Posted January 4, 2022 ancient history for extra credit https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/massoc-cdrs-amp-c/td-p/841943 1 Quote Link to comment Share on other sites More sharing options...
Emmanuel Delay Posted January 5, 2022 Author Share Posted January 5, 2022 Right. So, depending on what I need I will make dedicated functions. For example: selecting all 2D polylines: ... (if (assocm (entget ent) 100 "AcDb2dPolyline" ) (selectAll2DPolylines) ) ;; (defun assocm ( lst key val / pair rtn) (while (setq pair (assoc key lst)) (if (= val (cdr pair)) (setq rtn T) ) (setq lst (cdr (member pair lst))) ) rtn ) To find all endpoints of a LWPOLYLINE I might use Michal Puckett's cdrs ... Quote Link to comment Share on other sites More sharing options...
ronjonp Posted January 5, 2022 Share Posted January 5, 2022 2 hours ago, Emmanuel Delay said: To find all endpoints of a LWPOLYLINE I might use Michal Puckett's cdrs ... (vlax-curve-getendpoint ename) 1 Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted January 5, 2022 Share Posted January 5, 2022 Here are some more examples, along with a quick performance comparison. 5 1 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.