Perspective dynamic Navigation tree build

Hi,

is there a way to build dinamically the navigation tree in function of a folder structure or tag string into perspective ?

regards

Sure its all in json

image

[
  {
    "label": "Item 1",
    "expanded": true,
    "data": "I am string data for Item 1",
    "items": [
      {
        "label": "Child 1",
        "expanded": false,
        "data": {
          "someKey": "Information here."
        },
        "items": [
          {
            "label": "Grandchild 1",
            "expanded": false,
            "icon": {
              "path": "material/arrow_right",
              "color": "#869DB1",
              "style": {}
            },
            "data": {
              "things": [
                "one potato",
                "two potato",
                "three potato",
                "four",
                "boilem, mash em, put em in a stew"
              ]
            },
            "items": []
          },
          {
            "label": "Grandchild 2",
            "expanded": false,
            "data": 3.14159265359,
            "items": []
          }
        ]
      }
    ]
  },
  {
    "label": "Item 2",
    "expanded": false,
    "data": [
      1,
      2,
      77,
      89,
      123
    ],
    "items": [
      {
        "label": "Child of Item 2",
        "expanded": false,
        "items": [
          {
            "label": "Different Grandchild 1",
            "expanded": false,
            "items": []
          }
        ]
      }
    ]
  }
]

SectionData

[
  {
    "itemPath": "0/0/1",
    "value": 3.14159265359
  }
]

So write a script that makes a Json structure like so…and send it to props.items

Thanks for the answer, i will look this way

Regards

I’m curious if you got this working? I can build a valid JSON string, and send it to props, but it shows up as a string at the root level of the prop to which I have sent it, not as the structure that is defined in the string.

I tried reading out the prop value, it comes in as a PyUnicode string, writing that back to the exact same prop it shows up as the string, not as the structure.

I’ve also tried a couple of flavors of .append, which adds elements to the prop in question, but they are always values rather than objects. Any way to specify (in any method) that you are sending structured objects to the prop and not a string?

Alternatively, any way to resize the prop array on the fly? Would be easy to traverse the properties if they exist, but can’t seem to find a way to say 'items.size = x" (easy enough to get the size using ‘len’, but can’t write it back).

I’ve also tried the JSON approach shown here for tag history bindings, should be similar, and I can’t even get the sample JSON to paste successfully in the key, it shows up in the bound tag as text/string rather than as the structure.

No, i abandoned this idea. since my navigation will stay the same on every project

Just for thoroughness, I did find a way to put items on the tree:

    stylestring = {'classes':'TreeIcon_NoComms'}
	iconstring = {'path':'material/stop','style':stylestring}
	
	taglist=system.tag.browse(path = '[default]*Tag Folder*', filter = {})
	for tag in taglist.getResults():
		itemstring = {'label':tag['name'],"expanded":bool(1),'icon':iconstring,'items':[]}	
		self.getChild("root").getChild("Tree").props.items[0].items.append(itemstring)
		

As long as props.items[0].items exists that will add an entry for each tagname in my list. a couple of notes on things I found:
For things that are JSON true/false you have to use “bool(1)” (for true) or “bool(0)”, if you use the words true/false they will get interpreted as strings.

In my case I created styles and use those classes, but you can also build your style string to include your style items.

I’m currently stuck on adding the bindings in script, that’s the next step (my bindings change the style class to indicate problems with particular entries).

I’d also love a way to get rid of the self.getChild syntax, there ought to be a way, since I am working on the specific component, to use self.props or something similar, but I can’t find it.