03-10-2023 02:42 PM
I am trying to get code to automatically generate a tree for me based on a enum type def. I have chosen "." to show that the text is on a new level. Any ideas on a simple way to do this? On the left is the typeDef. In the middle is the full list of items in the type def. And on the right is what I would like my tree to look like at the end. For this post I manually filled in the tree. I would like the tags to be the second column.
Solved! Go to Solution.
03-11-2023 08:53 AM
You are leaving out a lot of information and we don't even know what your "tyepdef" is (Ring, Enum, etc.), we don't even know why it is a typedef, because that's irrelevant for the problem here.
You just need to parse the item names using the period as delimiter and build the tree, right? Have you looked at the help for the tree control?
Typically, it would help to attach a simplified VI containing the typedef and the tree so we can play. Staring at a picture of a front panel is not convenient for us to help you.
03-11-2023 09:20 AM
Adding the files to the post
03-11-2023 09:23 AM
Adding the files...again
03-11-2023 10:11 AM
Can we assume that the items are sorted (alphabetically and numerically (e.g. 3 before 11, etc.)?
(Please don not maximize the front panel to the screen!)
03-11-2023 03:28 PM
No. They will not always alphabetic order. But they will be grouped with the parent items.
03-13-2023 05:13 AM - edited 03-13-2023 05:15 AM
for each item in the enum
split on the last .
lookup the first part in the item vs treekey map
if not found, create it recursively (add the parent and store the treekey)
add a tree item with the last part as name, and the found key as parent
store the resulting treekey, with full enum string as map key
03-13-2023 06:06 AM - edited 03-13-2023 06:21 AM
Something like this:
Call like this:
As a bonus, you can do this too:
To use an enum:
Or (if the enum is an input to a generic sub vi):
03-13-2023 06:24 AM
Btw. populating the the becomes exponentially slower with the nr of items in the thee.
At some point you might want to hide the tree, populate it and s how it again. Or turn defer panel updates on, populate, turn it off.
03-13-2023 07:20 AM
Thanks for the help on this! Is there anyway that you can save in for LV2019? It looks like you are on 2020 and I am still on 2019 😞