mstb Posted July 5, 2020 Posted July 5, 2020 Hello every body I have a list like this (a b c d e f g h i j) And I have 2 member of list like c and f or h and b. now for example I want (c d e f) for c and f And I want (h i j a b) for h and b Thanks all. Quote
dlanorh Posted July 5, 2020 Posted July 5, 2020 What are a b c ...., variables, letters? Use the (subst) function (subst newitem olditem list) (setq lst '("a" "b" "c" "d" "e" "f" "g" "h" "i" "j")) (subst '("h" "i" "j" "a" "b") "b" lst)==> ("a" ("h" "i" "j" "a" "b") "c" "d" "e" "f" "g" "h" "i" "j") (foreach pr (list '("b" ("h" "i" "j" "a" "b")) '("h" ("h" "i" "j" "a" "b")) '("c" ("c" "d" "e" "f")) '("f" ("c" "d" "e" "f"))) (setq lst (subst (cadr pr) (car pr) lst)) ) Quote
Roy_043 Posted July 5, 2020 Posted July 5, 2020 (edited) The description is not 100% clear. But I think the OP wants a portion of the list defined by a start and end item, where the list must be considered circular. The solution below assumes that list items are unique. ; (get-sublist '("a" "b" "c" "d" "e" "f" "g" "h" "i" "j") "c" "f") => ("c" "d" "e" "f") ; (get-sublist '("a" "b" "c" "d" "e" "f" "g" "h" "i" "j") "h" "b") => ("h" "i" "j" "a" "b") (defun get-sublist (lst sta end / tmpA tmpB) (cond ((not (setq tmpA (member sta lst))) nil ) ((reverse (member end (reverse tmpA)))) ; End after sta. ((setq tmpB (member end (reverse lst))) ; Sta after end. (append tmpA (reverse tmpB)) ) ) ) Edited July 5, 2020 by Roy_043 Quote
mstb Posted July 5, 2020 Author Posted July 5, 2020 2 hours ago, dlanorh said: What are a b c ...., variables, letters? Use the (subst) function (subst newitem olditem list) (setq lst '("a" "b" "c" "d" "e" "f" "g" "h" "i" "j")) (subst '("h" "i" "j" "a" "b") "b" lst)==> ("a" ("h" "i" "j" "a" "b") "c" "d" "e" "f" "g" "h" "i" "j") (foreach pr (list '("b" ("h" "i" "j" "a" "b")) '("h" ("h" "i" "j" "a" "b")) '("c" ("c" "d" "e" "f")) '("f" ("c" "d" "e" "f"))) (setq lst (subst (cadr pr) (car pr) lst)) ) 1 hour ago, Roy_043 said: The description is not 100% clear. But I think the OP wants a portion of the list defined by a start and end item, where the list must be considered circular. The solution below assumes that list items are unique. ; (get-sublist '("a" "b" "c" "d" "e" "f" "g" "h" "i" "j") "c" "f") => ("c" "d" "e" "f") ; (get-sublist '("a" "b" "c" "d" "e" "f" "g" "h" "i" "j") "h" "b") => ("h" "i" "j" "a" "b") (defun get-sublist (lst sta end / tmpA tmpB) (cond ((not (setq tmpA (member sta lst))) nil ) ((reverse (member end (reverse tmpA)))) ; End after sta. ((setq tmpB (member end (reverse lst))) ; Sta after end. (append tmpA (reverse tmpB)) ) ) ) Thanks . These are points . I want to measure part of the sides of a parcel . not All. So I need part of the points list. Quote
Lee Mac Posted July 5, 2020 Posted July 5, 2020 Here's another variation - (defun sub ( a b l / r ) (if (vl-some '(lambda ( x ) (setq r (cons x r)) (= x b)) (member a (append l l))) (reverse r) ) ) _$ (sub "c" "f" '("a" "b" "c" "d" "e" "f" "g" "h" "i" "j")) ("c" "d" "e" "f") _$ (sub "h" "b" '("a" "b" "c" "d" "e" "f" "g" "h" "i" "j")) ("h" "i" "j" "a" "b") Quote
Jonathan Handojo Posted July 5, 2020 Posted July 5, 2020 Duplicates in the list will be a pain to deal with. (setq lst '(a i c d i e f i g h)) ;; Can't have your function return '(f i g h a i) by calling (fnc lst 'f 'i) Quote
mstb Posted July 5, 2020 Author Posted July 5, 2020 56 minutes ago, Lee Mac said: Here's another variation - (defun sub ( a b l / r ) (if (vl-some '(lambda ( x ) (setq r (cons x r)) (= x b)) (member a (append l l))) (reverse r) ) ) _$ (sub "c" "f" '("a" "b" "c" "d" "e" "f" "g" "h" "i" "j")) ("c" "d" "e" "f") _$ (sub "h" "b" '("a" "b" "c" "d" "e" "f" "g" "h" "i" "j")) ("h" "i" "j" "a" "b") 49 minutes ago, Jonathan Handojo said: Duplicates in the list will be a pain to deal with. (setq lst '(a i c d i e f i g h)) ;; Can't have your function return '(f i g h a i) by calling (fnc lst 'f 'i) Thank you very much Quote
pBe Posted July 5, 2020 Posted July 5, 2020 Quote _$ (sub "c" "f" '("a" "b" "c" "d" "e" "f" "g" "h" "i" "j")) ("c" "d" "e" "f") _$ (sub "h" "b" '("a" "b" "c" "d" "e" "f" "g" "h" "i" "j")) ("h" "i" "j" "a" "b") Is that the result you're looking for mstb? Quote
mstb Posted July 5, 2020 Author Posted July 5, 2020 (edited) 22 hours ago, pBe said: Is that the result you're looking for mstb? No , unfortunately It doesn't work for me. my list includes polygon vertices . (setq co-ord (mapcar 'cdr (vl-remove-if-not '(lambda (x) (= (car x) 10)) (entget (car (entsel)))))) (setq p1 (getpoint "Select first point on the polygon") p2 (getpoint "Select second point on the polygon")) Edited July 6, 2020 by mstb Quote
pBe Posted July 5, 2020 Posted July 5, 2020 Now thats more like it Clear enough for everyone to understand Quote
hosneyalaa Posted July 6, 2020 Posted July 6, 2020 On 7/5/2020 at 4:07 PM, mstb said: No , unfortunately It doesn't work for me. my list includes polygon vertices . (setq co-ord (mapcar 'cdr (vl-remove-if-not '(lambda (x) (= (car x) 10)) (entget (car (entsel)))))) (setq p1 (getpoint "Select first point on the polygon") p2 (getpoint "Select second point on the polygon")) HI ALL First, find the position of the first point of the list (setq lst-pt (mapcar (function cdr) (vl-remove-if-not (function (lambda (a) (= (car a) 10))) (entget en)) ) ;_ mapcar lst-bulge (mapcar (function cdr) (vl-remove-if-not (function (lambda (a) (= (car a) 42))) (entget en)) ) ;_ mapcar ) (setq X (CAR P1)) (setq XX (CADR P1)) (setq XS (mapcar 'cAr lst-pt)) (setq XXS(mapcar 'cADr lst-pt)) (setq iPP -1) (setq POISTION-2 (CAR(vl-remove nil (mapcar '(lambda ( XY y ) (setq iPP (1+ iPP)) (if (AND(= (RTOS X 2 2) (RTOS XY 2 2)) (= (RTOS XX 2 2) (RTOS Y 2 2))) iPP)) XS XXS)))) Then make a list rotation from the first point ;;https://www.cadtutor.net/forum/topic/62310-split-one-list-to-quotonequot-list/?fbclid=IwAR3OMb0erY3RkMObq7GH-UDXUWOgxLnAih9jTyzZrMeLEmUTsY3cR-se7Ro (defun foo ( n Lst ) (append (vl-member-if '(lambda (x) (= n x)) Lst) (reverse (cdr (vl-member-if '(lambda (x) (= n x)) (reverse Lst)))) ) ) _$ (foo 3 '(1 5 3 6 8 2 10)) (3 6 8 2 10 1 5) _$ Second, find the position of the Second point of the New list Then ;; (sublst '(1 2 3 4 5 6) 3 2) -> (0 position of the Second point ) ;; https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/split-a-list-in-parts/td-p/1923656 ;; Examples: ;; (sublst '(1 2 3 4 5 6) 3 2) -> (3 4) ;; (sublst '(1 2 3 4 5 6) 3 nil) -> (3 4 5 6) (defun sublst (lst start leng / rslt) (if (not (<= 1 leng (- (length lst) start))) (setq leng (- (length lst) (1- start))) ) (repeat leng (setq rslt (cons (nth (1- start) lst) rslt) start (1+ start) ) ) (reverse rslt) ) Quote
hosneyalaa Posted July 6, 2020 Posted July 6, 2020 (edited) The list and the two points must be FROM polygon vertices OR It should be sort according to the location of the two points of polygon OR Use this to measure a PART of polygon @Lee Mac Thanks for everything http://lee-mac.com/offsetpolysection.html Edited July 6, 2020 by hosneyalaa Quote
mstb Posted July 7, 2020 Author Posted July 7, 2020 14 hours ago, hosneyalaa said: The list and the two points must be FROM polygon vertices OR It should be sort according to the location of the two points of polygon OR Use this to measure a PART of polygon @Lee Mac Thanks for everything http://lee-mac.com/offsetpolysection.html Thank you very much 1 Quote
BIGAL Posted July 7, 2020 Posted July 7, 2020 If I understand correct you have a pline/polygon with vertices pick pt1 on a vertice, pick point 2 on a adjacent vertice, you can get simply by going through the vertices matching xy and you can get vertice number, so would be easy to make the correct new list of all vertices with pt1 as starting the only thing is wether a reverse is needed for Clockwise anticlockwise pline. The starting number would then be automatic. vertices (1 2 3 4 5 6) ignore xyz for now pick 3 4 so (3 4 5 6 1 2) Quote
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.