Page 1 of 1

Converting list into rtree

Posted: Wed Feb 09, 2011 8:08 pm
by lumpo
Is it possible to take a list (that is formatted as item & line...TAB & item & cr ...etc...) and somehow convert this into a rTree structure without having to manually rename each node generated from one of the demo scripts??

Re: Converting list into rtree

Posted: Wed Feb 09, 2011 11:03 pm
by wilstrand
Hi Lumpo!

You can do this in many ways. I will give you three examples:

1. Use Drag & Drop!
Just drag the text and drop it into the rTree control. The Engine will take care of the rest!

2. Use Copy & Paste!
Copy and paste by hitting ctrl + v.

3. By script.
Use this script to choose a text file on the hard disk and import it into the rTree control:

Code: Select all

answer file "Please choose a text file!" with "C:/" with filter "Text Files , *.txt" # Choose a directory to start in.
put it into sPath
put "file:" & sPath into sFile
put URL sFile into sFileText
dispatch "delete_nodeData" to control "Tree"
set the treeType of control "Tree"to "textfile"
repeat for each line sLine in sFileText
    dispatch "new_node" to control "Tree"
    put the ID_of_the_last_node of control "Tree" into sIDofLastNode
    put 0 into sCharNum
    repeat for each character sCharacter in sLine
       if sCharacter is not tab then exit repeat
       add 1 to sCharNum
    end repeat
    put character sCharNum + 1 to - 1 of sLine into sName
    set the name_of_node_ID_[sIDofLastNode] of control "Tree" to sName
    put sCharNum into sDepth
    set the depth_of_node_ID_[sIDofLastNode] of control "Tree" to sDepth
end repeat
dispatch "renderTree" to control "Tree"
Please download the latest version (v.1.1.1) from ... 1&Itemid=3 as there was a bug in the drop routine in previous versions.

With my best regards


Re: Converting list into rtree

Posted: Wed Feb 09, 2011 11:17 pm
by lumpo
Thanks Mats
I will try this afternoon.

I just downloaded the WorkBench 1.1.1. However, when the engine has to be embedded in my own project, do I use this rev file or the older one called "rTreeEngine"??


Re: Converting list into rtree

Posted: Wed Feb 09, 2011 11:35 pm
by wilstrand

In the rTree Workbench v.1.1.1 that you downloaded you have a substack called rTreeEngine.rev. Use that stack in your projects as it is the latest version with some new features and bugfixes.

Best regards


Re: Converting list into rtree

Posted: Fri Feb 11, 2011 12:14 am
by lumpo
Thanks for your help thus far MAts - sorry to be dim but.....

I have made the latest rTreeEngine a substack of the mainstack and checked its there after issuing a "start using stack...." command in the startup script. The stacksinuse shows that rTreeengine is going.

However, when I run the script you showed me above nothing happens at all. Firstly it would not see any .txt fields as selectable. By removing the filter it would at least ungreyout the .txt field I had created, and so I could select it. However, following the closure of the ask dialog - nothing happens. I have a field waiting called "Tree" (and no others with similar names).

NExt I tried the drag and drop - this simply put the filepath of the dropped text file into the text content of the tree control.

Hmmm... I must be doing something fundamentally wrong here.

Any suggestions?

Re: Converting list into rtree

Posted: Fri Feb 11, 2011 1:19 am
by wilstrand
Hi Lumpo!

Lets sort this out together! Based on your description of what happens (or not happens) I must first ask if you have set the behavior of your Tree Field? It is actually not nessecary to issue a "start using stack..." for the rTree engine to work but you must set the behavior of each field that you would like to be an rTree to - button "rTreeBehavior" of stack "rTreeEngine" -

I´ll try to explain the Drag & Drop functionality a little better!
You can select the actual text of a .txt file and then drag & drop that text or copy and paste it with ctrl+v. The rTree will then make each line of that text a Node. The name of that node will be the text of each line. If there is a tab in front of the text line the depth of the created node will be 1, two tabs in front will set the depth to 2 and so on.

If you Drag the .txt file itself directly from Windows Explorer (if you are on windows) and drop it on rTree, the engine will create a node with the name set to the name of the .txt file. The created node will also have a property called sourcePath set to the path of the .txt file. If you set the treeType property of the rTree to "filesystem" files and folders dragged from Windows Explorer and dropped on rTree will automatically have data bindings to the hard disk!

Please let me know as soon as possible if this was of any help to you!

All the best


Re: Converting list into rtree

Posted: Fri Feb 11, 2011 3:16 am
by lumpo
whoops! Feel a bit of an idjot (as the Irish say).
I have two fields (one keyed off the other) and I forgot to set the behaviour on the second. Also a small typo was contributing once I got it going. Final code: set the behavior of control "Tree" of cd "Anchorpoints" to the long ID of button "rTreeBehavior" of stack "rTreeEngine" and all's well.

Thanks for your support and apologies for having senile moment!


Re: Converting list into rtree

Posted: Fri Feb 11, 2011 8:19 am
by wilstrand
Glad you solved it! :)