Dayananda Posted November 23, 2019 Share Posted November 23, 2019 ((-1 . <Entity name: 7ff4dca064a0>) (0 . "XRECORD") (330 . <Entity name: 0>) (5 . "2D2") (100 . "AcDbXrecord") (280 . 1) (7 . "Arial") (8 . "A09--T-") (40 . 20.0) (3 . "A1") (300 . "61") (3 . "A2") (300 . "69") (3 . "A3") (300 . "72")) In this list there are association code 3 several times. How can I get absorb the values relevant all values. and next how can I feed back new values to that code using (entmod(subst ( cons 3 ......? Quote Link to comment Share on other sites More sharing options...
hanhphuc Posted November 23, 2019 Share Posted November 23, 2019 check this old thread --> massoc i'd suggest finding nth position (defun foo (i l / c x ls) (setq c 0) (repeat (length l) (setq x (nth (setq c (1+ c)) l)) (if (= (car x) i) (setq ls (cons c ls)) ) ) (reverse ls) ) assum l1 is your list (setq nl (foo 3 l1)) ; nl = nth / position list ;;;(9 11 13) ;; retrieve nth position in l1 (mapcar ''((x)(nth x l1)) nl) ;;;((3 . "A1") (3 . "A2") (3 . "A3")) to replace new item , assume your wanna replace same index 3 with new item '("B1" "B2" "B3") (defun bar (i new x l) (mapcar ''((a b) (setq l (subst (cons i a) (nth b l) l))) new x ) l ) (bar 3 '("B1" "B2" "B3") nl l1) ;((-1 . <Entity name: 7ff4dca064a0>) (0 . "XRECORD") (330 . <Entity name: 0>) (5 . "2D2") (100 . "AcDbXrecord") (280 . 1) (7 . "Arial") (8 . "A09--T-") (40 . 20.0) ;(3 . "B1") (300 . "61") (3 . "B2") (300 . "69") (3 . "B3") (300 . "72")) 1 Quote Link to comment Share on other sites More sharing options...
Grrr Posted November 23, 2019 Share Posted November 23, 2019 Here are some quickly written functions that may be of help - ; (GetInstancesOf (lambda (x)(= 10 (car x))) (entget (car (entsel "\nPick polyline")))) ; >> ((10 1288.07 1710.1) (10 2258.12 2318.01) (10 2529.53 2318.01) (10 3871.5 1865.85) (10 4595.26 2368.25) (10 5032.54 2212.5)) ; tf - test function ; L - list (defun GetInstancesOf ( tf L ) ( (lambda (f tf L) (f tf L)) (lambda (tf L) (if (setq L (vl-member-if 'tf L)) (cons (car L) (f tf (cdr L))) ) ) tf L ) ); defun ; (SubstInstances '((x)(= 10 (car x))) '(0 2) '("Donald" "Trump") (entget (car (entsel "\nPick polyline")))) ; >> ; ((-1 . <Entity name: 76940ffd10>) (0 . "LWPOLYLINE") (330 . <Entity name: 76b2f399f0>) (5 . "269") (100 . "AcDbEntity") ; (67 . 0) (410 . "Model") (8 . "0") (100 . "AcDbPolyline") (90 . 6) (70 . 0) (43 . 0.0) (38 . 0.0) (39 . 0.0) ; "Donald" (40 . 0.0) (41 . 0.0) (42 . 0.0) (91 . 0) ; (10 2258.12 2318.01) (40 . 0.0) (41 . 0.0) (42 . 0.0) (91 . 0) ; "Trump" (40 . 0.0) (41 . 0.0) (42 . 0.0) (91 . 0) ; (10 3871.5 1865.85) (40 . 0.0) (41 . 0.0) (42 . 0.0) (91 . 0) ; (10 4595.26 2368.25) (40 . 0.0) (41 . 0.0) (42 . 0.0) (91 . 0) ; (10 5032.54 2212.5) (40 . 0.0) (41 . 0.0) (42 . 0.0) (91 . 0) (210 0.0 0.0 1.0) ; ) ; sL - source list ; tf - test function ; nL - positions to subst ; aL - list of new items (defun SubstInstances ( tf nL aL sL / i ) (setq i -1) (mapcar (function (lambda (x / itm) (cond ( (not (tf x)) x) ( (not aL) x) ( (member (setq i (1+ i)) nL) (setq itm (car aL)) (setq aL (cdr aL)) itm) (x) ); cond ); lambda ); function sL ); mapcar ); defun And heres some test function (tested on a LWPOLYLINE, since it has multiple dxf 10 values in its elist and its a graphical entity which is suitable for a preview during testing) - (defun C:test ( / enx vL nL p p2 ) (and (setq enx (car (entsel "\nPick a polyline: "))) (setq enx (entget enx)) (member '(0 . "LWPOLYLINE") enx) (setq vL (GetInstancesOf '((x)(= 10 (car x))) enx)) (setq nL ('((f n) (reverse (f (1- n)))) '((n) (if (> n -1) (cons n (f (1- n))))) (length vL))) (progn (foreach n nL ; use 'nL' or a custom list like: '(0 2 5 12) (and (setq p2 (nth n vL)) (setq p (getpoint (cdr p2) (strcat "\nSpecify new " (itoa (1+ n)) (cond ( (nth n '("st" "nd" "rd" "th")) ) ("th") ) " vertex of the polyline: " ) ) ) (setq enx (SubstInstances '((x)(= 10 (car x))) (list n) (list (cons 10 p)) enx)) ; update within the iteration for a real-time preview (entmod enx) ); and ); foreach (princ "\nPress anything to restore the shape") (grread) (entmod (SubstInstances '((x)(= 10 (car x))) nL vL enx)) ); progn ) (princ) ); defun 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.