Jump to content

Recommended Posts

Posted

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.

Posted

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))
)

 

Posted (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 by Roy_043
Posted
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.

Posted

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")

 

Posted

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)

 

Posted
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

Posted
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?

 

Posted (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 by mstb
Posted

Now thats more like it 👍

Clear enough for everyone to understand

 

 

Posted
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)
)

 

 

 

 

Posted (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 by hosneyalaa
Posted
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

  • Thanks 1
Posted

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)

 

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...