TheSwamp
Code Red => AutoLISP (Vanilla / Visual) => Topic started by: Dan113 on December 07, 2017, 02:51:31 AM
-
I have the below list, ive been scratching my head with no joy about how to do this.
I need to iterate through the list and create a treemap in opendcl to display the list structure visually. I can then go on to create a dictionary structure to save the data.
The following is just an example but each of the nested lists can have an unspecified number of lists and each with a different depth so i dont think a nested foreach is suitable/possible??
Can someone point me in the right direction....
(setq lst '("P1"
("Data" ("D1")("D2")("D3" ("D3-1" "D3-2" ("X"))))
("Stru" ("Ft1")("Ft2" ("Ft2-1")))
("Rom-A" ("Flr-1" ("East" ("A" "B" "C"))("West" ("A" "B"))("South"("D" "E"))("North" ("A" "F" "G"))))
("Rom-B" ("Flr-1" ("East" ("A" "B" ("C" "T")))("West" ("A" "B"))("North" ("A" ("F") "G"))))
("Rom-C" ("Flr-1" ("East" ("A" "B" "C"))("South"("D" "E"))("North" ("A" "F" "G"))))
)
-
Maybe this thread (https://www.theswamp.org/index.php?topic=53009.msg578156#msg578156) will help.
-
I dont have an assoc list to use as im trying to map the entire tree.
This is the closest ive got so far but it only creates a root and everything after it as a child.
I cant seem to catch the individual lists
(defun C:test ( / map-tree)
(defun map-tree (func tree /)
(cond
((null tree) nil)
((vl-consp tree)
(cons (map-tree func (car tree))
(map-tree func (cdr tree))))
(t (setq chld (func tree chld))))
)
(defun add-child (a b)
(dcl-tree-addchild Test/Form2/TreeControl1 (list (list b a)))
)
(defun c:Test/Form2#OnInitialize (/)
(setq lst '("P1"
("Data" ("D1")("D2")("D3" ("D3-1" "D3-2" ("X"))))
("Stru" ("Ft1")("Ft2" ("Ft2-1")))
("Rom-A" ("Flr-1" ("East" ("A" "B" "C"))("West" ("A" "B"))("South"("D" "E"))("North" ("A" "F" "G"))))
("Rom-B" ("Flr-1" ("East" ("A" "B" ("C" "T")))("West" ("A" "B"))("North" ("A" ("F") "G"))))
("Rom-C" ("Flr-1" ("East" ("A" "B" "C"))("South"("D" "E"))("North" ("A" "F" "G"))))
)
)
(setq chld (dcl-Tree-AddParent Test/Form2/TreeControl1 '(("Test"))))
(map-tree add-child lst)
)
(dcl-Form-Show Test/Form2)
)
-
But what arguments (add-child) should take?
Like for "Data":
"Data" '(("D1")("D2")("D3" ("D3-1" "D3-2" ("X"))))
or
(foreach x '(("D1")("D2")("D3" ("D3-1" "D3-2" ("X")))) (add-child "Data" x))
or
"Data" "P1"
so then for "D1" would be:
"D1" "Data"
Is the mapping order important for (dcl-tree-addchild) ?
I'm pretty sure your problem is solvable, but the guys who can do it might be not familiar with odcl's functions and vice versa.
-
How are you generating / harvesting the source data?
-
The add-child arguments are the parent node and the name of the new child node.
I am obtaining the data from xrecords in dictionaries and I am wanting to display the contents to the user. The data originally comes from xdata attached to lines in a drawing and also user input. I am wanting to add to the xrecords data from the tree but this is only if I can get this to work.
-
i use this
(defun vk_ODCL-FillTree (Control Lst)
(mapcar (function
(lambda (e / p)
(cond ((listp (car e))
(setq p (apply 'dcl_Tree_AddParent (cons Control (car e))))
(cons p (vk_ODCL-FillTreeChildren Control p (cdr e)))
)
(t (apply 'dcl_Tree_AddParent (cons Control e)))
)
)
)
Lst
)
)
(defun vk_ODCL-FillTreeChildren (Control Parent Children)
(mapcar (function
(lambda (c / p)
(cond ((null c) (dcl_Tree_AddChild Control Parent ""))
((listp (car c))
(setq p (apply 'dcl_Tree_AddChild
(cons Control (cons Parent (car c)))
)
)
(cons p (vk_ODCL-FillTreeChildren Control p (cdr c)))
)
(t
(apply 'dcl_Tree_AddChild (cons Control (cons Parent c)))
)
)
)
)
Children
)
)
it will not work with the list you've provided
you'll have to either change the list structure or edit the functions