TheSwamp
Code Red => AutoLISP (Vanilla / Visual) => Topic started by: civil.eng on May 29, 2021, 04:06:56 AM
-
Hi everyone,
I'm trying to write a function to populate list items in each popuplist :
(defun setpop ()
(setq poplist (list '("popup1" "alist")
'("popup2" "plist")
'("popup3" "plist")
'("popup4" "slist")
)
)
(foreach pop poplist
(start_list (car pop))
(mapcar 'add_list (cadr pop))
(end_list)
)
)
But it gives this error :
; error: bad argument type: listp "alist"
For example "alist" items are :
(setq alist '("Orchard" "Wall" "Pool" "Building"))
-
-
Thank you Tharwat, But I don't want to add all cadr item of list to popup list, I want to populate items of realted list in loop , like:
<popup1 > items of alist
<popup2 > items of plist
...
...
-
Simply replace cadr with car
-
Tharwat, there are several popup lists and lists , and the loop that I have written must populate each list to each popup.
-
(foreach key '
("key1" "key2" "key3") ;; add all keys of your popup_lists )
-
Wrong again, that should be like :
(foreach key '("popup1" "popup2" "popup3") ;; add all keys of your popup_lists
(start_list key)
(mapcar 'add_list (cadr poplist))
(end_list)
)
(cadr poplist) are items of a list like "alist"
(setq alist '("Orchard" "Wall" "Pool" "Building"))
(setq plist '("region1" "region2" "region3"))
(setq slist '("riverNG" "riverTH" "riverCR"))
popup1 > alist
popup2,popup3 > plist
popup3 > slist
-
(defun setpop
(/ poplist
) '("popup2" "plist")
'("popup3" "plist")
'("popup4" "slist")
)
)
)
)
-
Yes this is right, but it shows only item of "(cdr (assoc pop poplist)" , it must show items of each list like "alist"
(setq alist '("Orchard" "Wall" "Pool" "Building"))
(setq plist '("region1" "region2" "region3"))
(setq slist '("riverNG" "riverTH" "riverCR"))
popup1 > alist
popup2,popup3 > plist
popup3 > slist
-
You should have learned a lot for now from all these different scenarios. :grinwink:
Be sure to have the variables 'alist' 'plist' ...etc assigned with list of items to avoid errors and failure.
(defun setpop
(/ poplist
) )
)
)
)
-
Bravo, you did great
-
The current code is processing the list in the following way:
- Obtain a list containing the first elements of the original list
- Iterate over the list of first elements
- Use the first element to obtain each item from the original list
- Add the contents of each item to the popup list tile
Instead, you can iterate over the list in a single pass in the following way:
But it's actually likely to be more efficient to simply do this:
(dclst "popup1" alist)
(dclst "popup2" plist)
(dclst "popup3" plist)
(dclst "popup4" slist)
)
)
-
Woooov, you are fabulous. thank you lee mac