Getting the contents of a SDBTreeNode?
Moderators: Gurus, Addon Administrators
Getting the contents of a SDBTreeNode?
I am connecting to MediaMonkey through the COM interface like this: SDBA = new SongsDB.SDBApplication();
Now, I would like to navigate through the nodes of the main tree, but I can't figure out how to get deeper than one layer. For instance, SDBA.MainTree.Node_Album gives me the album node, but how can I find the child nodes of that? And if I finally reach the bottom of the hierarchy, how do I find the tracks that are listed when this node is selected?
I am aware that I can find albums using better functions than this, but my goal isn't the albums, that's just an example. I am trying to replicate the entire tree structure, and find songs located inside a tree node.
Any suggestions?
Now, I would like to navigate through the nodes of the main tree, but I can't figure out how to get deeper than one layer. For instance, SDBA.MainTree.Node_Album gives me the album node, but how can I find the child nodes of that? And if I finally reach the bottom of the hierarchy, how do I find the tracks that are listed when this node is selected?
I am aware that I can find albums using better functions than this, but my goal isn't the albums, that's just an example. I am trying to replicate the entire tree structure, and find songs located inside a tree node.
Any suggestions?
Re: Getting the contents of a SDBTreeNode?
There are various methods you can use to traverse the tree, including FirstChildNode, LastChildNode, NextNode and NextSiblingNode, depending on exactly what you're trying to do.
Once you have the right node, you can use the RelatedObjectID property to get the ID of the album/artist/whatever and then use an SQL command from there.
Once you have the right node, you can use the RelatedObjectID property to get the ID of the album/artist/whatever and then use an SQL command from there.
Download my scripts at my own MediaMonkey fansite.
All the code for my website and scripts is safely backed up immediately and for free using Dropbox.
All the code for my website and scripts is safely backed up immediately and for free using Dropbox.
Re: Getting the contents of a SDBTreeNode?
Thanks, but I'd actually tried that, but without any luck. Here's what I've got so far:
Unfortunately, this is what I get as output from get_Node_Album_InCollection(1): (And yes, I know that a collection with ID=1 exists, I've gotten it by enumerating SDBA.Collections.)
As you can see, every value of the variable "node" is null or false, except "HasChildren", which is true. When I try to get the first children node of "node", I get a node exactly like the image, but with "Unknown" instead of "Album".
Any ideas?
Code: Select all
//This is supposed to fetch the node for albums in Collection 1, right?
var node = _controller.SDBA.MainTree.get_Node_Album_InCollection(1);
if (node.HasChildren) // Just checking ...
{
// Getting the first child node, which I guess should be an album node.
var curr = _controller.SDBA.MainTree.get_FirstChildNode(node);
while (curr != null)
{
//Fetch the album from the database using the RelatedObjectID.
yield return GetAlbum(curr.RelatedObjectID);
//Continue with the next sibling node, which I guess is the next album.
curr = _controller.SDBA.MainTree.get_NextSiblingNode(curr);
}
}
As you can see, every value of the variable "node" is null or false, except "HasChildren", which is true. When I try to get the first children node of "node", I get a node exactly like the image, but with "Unknown" instead of "Album".
Any ideas?
Re: Getting the contents of a SDBTreeNode?
I'm not sure what language you're using, but are you supposed to have "get_" in front of all the methods?
Download my scripts at my own MediaMonkey fansite.
All the code for my website and scripts is safely backed up immediately and for free using Dropbox.
All the code for my website and scripts is safely backed up immediately and for free using Dropbox.
Re: Getting the contents of a SDBTreeNode?
That's C#, and yes, that's how the methods show up in the Intellisense (the code completition feature of Visual Studio). There are also indexed properties, allowing me to write it like this instead:
But there's no difference. I guess one of them is just an overload for the other.
Just to be clear; does the Node_Album_InCollection[id] work as I think? It does give me a node that has all the albums in the given collection as children, right? And to get those children, I need to use MainTree.FirstChildNode[node], and then continue with MainTree.NextSiblingNode[] to get the rest of them? But if so, why don't I get anything?
Code: Select all
//Note the square brackets, and no "get_"
var node = _controller.SDBA.MainTree.Node_Album_InCollection[1];
Just to be clear; does the Node_Album_InCollection[id] work as I think? It does give me a node that has all the albums in the given collection as children, right? And to get those children, I need to use MainTree.FirstChildNode[node], and then continue with MainTree.NextSiblingNode[] to get the rest of them? But if so, why don't I get anything?
Re: Getting the contents of a SDBTreeNode?
Yes, I've never used the new "InCollection" methods, but assuming they work the same as the deprecated pre-collection methods, that is how it should work. You may need to expand the node before trying to get the children though, by setting Expanded = True.
Download my scripts at my own MediaMonkey fansite.
All the code for my website and scripts is safely backed up immediately and for free using Dropbox.
All the code for my website and scripts is safely backed up immediately and for free using Dropbox.
Re: Getting the contents of a SDBTreeNode?
Thanks for helping me, but unfortunately that was not the solution either. On some of the nodes setting Expanded=true changes Expanded to true (but nothing else changes), while on other nodes, nothing happens at all.
Any ideas?
Any ideas?
Re: Getting the contents of a SDBTreeNode?
Nope, not really. This is the code that I have used before for browsing through the tree (eg. in my "Tag Cloud" script)...
Code: Select all
Dim tree : Set tree = SDB.MainTree
Dim node : Set node = tree.Node_Library
node.Expanded = True
Set node = tree.FirstChildNode(node)
Do While ((loop condition) Or (node.Visible = False))
node.Expanded = False
Set node = tree.NextSiblingNode(node)
'do something
Loop
Download my scripts at my own MediaMonkey fansite.
All the code for my website and scripts is safely backed up immediately and for free using Dropbox.
All the code for my website and scripts is safely backed up immediately and for free using Dropbox.
Re: Getting the contents of a SDBTreeNode?
Thanks, I converted that to C# and modified it to print the caption of the node, and recurse deeper into the tree. I got this:
NULL is printed where .HasChildren is true, but FirstChildNode() returns null anyway for some reason. So it seems I cannot browse the tree as thorough as I was hoping; only Classification gives anything useful. Are you able to get more information than this in your script?
Code: Select all
Location
Title
Artist & Album Artist
NULL
Artist
NULL
Actor
NULL
Album Artist
NULL
Composer
NULL
Author
NULL
Producer
NULL
Conductor
NULL
Director
NULL
Album
NULL
Podcast
NULL
Series
NULL
Genre
NULL
Year
NULL
Original Year
NULL
Publisher
NULL
Parental Rating
NULL
Rating
NULL
Classification
Very slow
Slow
Moderate
Fast
Very fast
Files to Edit
Virtual CD
NULL
Previews
NULL
Podcast Directories
NULL
Subscriptions
NULL
Re: Getting the contents of a SDBTreeNode?
Yes, I don't get null, I get SDBTreeNode objects. I'm not sure why this is not working for you.
Download my scripts at my own MediaMonkey fansite.
All the code for my website and scripts is safely backed up immediately and for free using Dropbox.
All the code for my website and scripts is safely backed up immediately and for free using Dropbox.