[Solved] Tree control: Child of a child - How to?

Started by Peter2, November 12, 2014, 08:04:14 AM

Previous topic - Next topic

Peter2

Based on the examples of "Tree.lsp" I tried to create a tree "on_initialize"  -> result:  :'( :'(

I'm sure it is simple, but I can not figure it out. Here is the working fragment with "Parent - Child", but I'm not able to create "Parent - Child - Child":

Code (autolisp) Select
    (setq P10 (dcl_Tree_AddParent spdrs_Haupt_tree "Abbruch" 9 -1 9))
    (setq P20 (dcl_Tree_AddParent spdrs_Haupt_tree "Betriebsartenstecker" 10 -1 10))
    (dcl_Tree_AddChild spdrs_Haupt_tree
        (list
            (list P20 "a child" 4 5)
            (list P20 "should be a parent from three children" 4 5)
        )
    )
    (setq P30 (dcl_Tree_AddParent spdrs_Haupt_tree "Kondensator" 10 -1 10))



Other question:
Trees can be created "with lists" and "without lists". It seem to me that there is also another behaviour of the "uParentItems" and "strKey" - right?

Code (autolisp) Select

; mode with lists and setq
    (setq P20 (dcl_Tree_AddParent spdrs_Haupt_tree "Betriebsartenstecker" 10 -1 10))
    (dcl_Tree_AddChild spdrs_Haupt_tree
        (list
            (list P20 "von oben" 4 5)
            (list P20 "von unten" 4 5)
        )
    )
; -------------
; mode withOUT lists and setq
    (dcl_Tree_AddParent spdrs_Haupt_tree "Kontakt hoch" "xx" 10 -1 10)
    (dcl_Tree_AddChild spdrs_Haupt_tree
        '(
            ("xx" "Ãâ€"ffner" "x1" 4 5)
            ("xx" "Ãâ€"ffner angezogen" "x2" 4 5)
        )
    )

Peter
ODCL 8.1.... German, AutoCAD 2017 - 2018, Win 7 x64, Win 10

Fred Tomke

Hi, Peter2,

try this:

Code (autolisp) Select

(dcl_Tree_AddParent control "Parent" "ParentKey" 1 1 1)
(dcl-Tree-AddChild control (list (list "ParentKey" "Child1" "Child1Key" 1 1 1) (list "ParentKey" "Child2" "Child2Key" 1 1 1)
                                 (list "Child1Key" "Child1_1" "Child1_1Key" 1 1 1) (list "Child2Key" "Child2_1" "Child2_1Key" 1 1 1)))


uParentItem is only used in German help ("u" from Hungary notation for usual for not strongly typed arguments).
The parent item value can be a handle of the parent. I've never used that since I had some troubles in ancient ObjectDCL.
I only used strings (AutoCAD entity handle (GC 5)) or even combinations of letters and database key (letters to divide between nodetypes).
I hope the sample above will answer your question or help a little bit.

Regards, Fred
Fred Tomke
Dipl.-Ing. (FH) Landespflege

[ landscaper - landscape developer - digital landscape and urban design]

Fred Tomke

Hi, me again.

Your sample
Code (autolisp) Select

    (dcl_Tree_AddChild spdrs_Haupt_tree
        '(
            ("xx" "Ãâ€"ffner" "x1" 4 5)
            ("xx" "Ãâ€"ffner angezogen" "x2" 4 5)
        )
    )

uses quotes. I remember that somewhere was written, that the argument values should be evaluated before.
Regards, Fred
Fred Tomke
Dipl.-Ing. (FH) Landespflege

[ landscaper - landscape developer - digital landscape and urban design]

Peter2

Hi Fred

thanks.

Your first post shows me that my first code, using the "setq-list-mode"
Code (autolisp) Select
(setq P20 (dcl_Tree_AddParent spdrs_Haupt_tree "Betriebsartenstecker" 10 -1 10))
    (dcl_Tree_AddChild spdrs_Haupt_tree
        (list
            (list P20 "a child" 4 5)

is not able to use "Parent-IDs" and has another behaviour then the "quoted-mode".

Right?

Quote from: Fred Tomke on November 12, 2014, 10:17:55 AM
...Your sample...uses quotes. I remember that somewhere was written, that the argument values should be evaluated before....
?? Hmmm - what's the conclusion of this?
Peter
ODCL 8.1.... German, AutoCAD 2017 - 2018, Win 7 x64, Win 10

roy_043

#4
@ Peter2:
The English Help for dcl_Tree_AddChild is quite clear and answers all of your questions.

To add children to a child you have to either store the handle of the child (from the Help: The return value is the unique handle of the new item if only one child item is added) or supply the 'key' argument when you create the child (see Fred's example). This handle or key can then be used to create the child's children with a subsequent call to dcl_Tree_AddChild.

Your second example uses a list as well. And the fact that you can use use key strings instead of handles is mentioned in the Help: ParentItem [as Handle or String].

@ Fred:
I don't think there is anything to evaluate in the list of Peter2's second example. It can be used without any problem.

Fred Tomke

Quote from: roy_043 on November 12, 2014, 10:52:26 AM
@ Fred:
I don't think there is anything to evaluate in the list of Peter2's second example. It can be used without any problem.

Hi, I've just written what was mentioned in the past: quoted lists may lead into errors. Quoted lists are not evaluated in my memory, but I may be wrong.
If it works for you, then ignore my hint.

Fred
Fred Tomke
Dipl.-Ing. (FH) Landespflege

[ landscaper - landscape developer - digital landscape and urban design]

Peter2

Quote from: Peter2 on November 12, 2014, 08:04:14 AM
...I'm sure it is simple, but I can not figure it out. Here is the working fragment with "Parent - Child", but I'm not able to create "Parent - Child - Child": ...
Looking back to my first question I would say my basic problem was to understand the hierarchy -
Code (autolisp) Select
;"Is every entry which has a child also a parent?"

a) Parent - Parent -  Parent - Child
b) Parent - Child - Child - Child


Now I know that b) is correct, and maybe this hint could be added to the help-file.
Peter
ODCL 8.1.... German, AutoCAD 2017 - 2018, Win 7 x64, Win 10

roy_043

QuoteIs every entry which has a child also a parent?
Yes.

I would say that c) is correct:
c) Parent -> Child/Parent -> Child/Parent -> Child

Peter2

Quote from: roy_043 on November 17, 2014, 04:38:11 AM
I would say that c) is correct:
c) Parent -> Child/Parent -> Child/Parent -> Child
Yes - in the sense of genealogy, but you have to select between "dcl_Tree_AddChild/dcl_Tree_AddParent"  ;)
Peter
ODCL 8.1.... German, AutoCAD 2017 - 2018, Win 7 x64, Win 10

owenwengerd

Maybe the dcl-Tree-AddParent method would be better named dcl-Tree-AddTopLevelParent.
Owen Wengerd (Outside The Box) / ManuSoft

Peter2

Quote from: owenwengerd on November 17, 2014, 07:56:35 AM
Maybe the dcl-Tree-AddParent method would be better named dcl-Tree-AddTopLevelParent.
Or only "dcl-tree-AddTopLevel" without "parent" ..
Peter
ODCL 8.1.... German, AutoCAD 2017 - 2018, Win 7 x64, Win 10