Code Red > AutoLISP (Vanilla / Visual)
How to extract data from this list?
HasanCAD:
Need some Help in extracting data from a list
I have this list
--- Code - Auto/Visual Lisp: ---( ("cable01" "M1" "E1") ("cable02" "M1" "E2") ("cable03" "M1" "E3") ("cable04" "E1" "M4") ("cable05" "E2" "M5") ("cable06" "E2" "M1"))
So How to extract cable# (first item in list ) if I asked for cable which connected to a machine E1
And sort if there is more than one cable.
For example I asked for E1
The lisp filter cables number in Mtext in raws (even in second or third item)
cable01, M1
cable04, M4
For example I asked for M1
cable01, E1
cable02, E2
cable06, E2
cable03, E3
Thanks in advance
kdub_nz:
How are you currently getting the data results ? Post code ?
What result did you expect in the samples you have shown ?
Added:
Is the data format consistantly shaped ??
Marc'Antonio Alessi:
Maybe rebuild the list is one option:
--- Code: ---(setq #List
'(
("cable01" "M1" "E1")
("cable02" "M1" "E2")
("cable03" "M1" "E3")
("cable04" "E1" "M4")
("cable05" "E2" "M5")
("cable06" "E2" "M1")
))
(defun TestAssoc (KeyVal DatLst / AscLst)
(foreach ForElm DatLst
(setq AscLst (cons (cons (cadr ForElm) (car ForElm)) (cons (cons (caddr ForElm) (car ForElm)) AscLst)))
)
(Cdrs KeyVal AscLst)
)
; Orginal by M. Puckett > Cdrs
(defun Cdrs (DxfKey ImpLst / TmpLst OutLst)
(while (setq TmpLst (assoc DxfKey ImpLst))
(setq OutLst (cons (cdr TmpLst) OutLst)
ImpLst (cdr (member TmpLst ImpLst))
)
)
(reverse OutLst)
)
(TestAssoc "E1" #List) =>("cable04" "cable01")
(TestAssoc "M1" #List) =>("cable06" "cable03" "cable02" "cable01")
--- End code ---
kpblc:
Maybe something like this?
--- Code - Auto/Visual Lisp: ---(defun t1 (data-list name / res) (foreach item data-list (cond ((= (cadr item) name) (setq res (cons (list (car item) (caddr item)) res))) ((= (caddr item) name) (setq res (cons (list (car item) (cadr item)) res))) ) ;_ end of cond ) ;_ end of foreach (reverse res) ) ;_ end of defun Results are:
--- Code - Auto/Visual Lisp: ---_$ (t1 '(("cable01" "M1" "E1") ("cable02" "M1" "E2") ("cable03" "M1" "E3") ("cable04" "E1" "M4") ("cable05" "E2" "M5") ("cable06" "E2" "M1") ) "E2")(("cable02" "M1") ("cable05" "M5") ("cable06" "M1"))_$ (t1 '(("cable01" "M1" "E1") ("cable02" "M1" "E2") ("cable03" "M1" "E3") ("cable04" "E1" "M4") ("cable05" "E2" "M5") ("cable06" "E2" "M1") ) "E1")(("cable01" "M1") ("cable04" "M4"))
Grrr1337:
--- Code - Auto/Visual Lisp: ---(defun f ( k aL ) (apply 'append (mapcar '(lambda (x) (if (member k (cdr x)) (list (vl-remove k x)))) aL)))
--- Code - Auto/Visual Lisp: ---;|For example I asked for E1 The lisp filter cables number in Mtext in raws (even in second or third item)cable01, M1cable04, M4|;(f "E1" '( ("cable01" "M1" "E1") ("cable02" "M1" "E2") ("cable03" "M1" "E3") ("cable04" "E1" "M4") ("cable05" "E2" "M5") ("cable06" "E2" "M1") ))>> (("cable01" "M1") ("cable04" "M4"))
--- Code - Auto/Visual Lisp: ---;|For example I asked for M1cable01, E1cable02, E2cable06, E2cable03, E3|;(f "M1" '( ("cable01" "M1" "E1") ("cable02" "M1" "E2") ("cable03" "M1" "E3") ("cable04" "E1" "M4") ("cable05" "E2" "M5") ("cable06" "E2" "M1") ))>> (("cable01" "E1") ("cable02" "E2") ("cable03" "E3") ("cable06" "E2"))
Navigation
[0] Message Index
[#] Next page
Go to full version