Assuming that I haven't missed something blatantly obvious, I created a method that is a little complicated but does create a project-level Tree! Give it a try and see if it does what you need.
It is an Origin C function that accepts a string with the name which you wish to give your tree variable (e.g. "mytree"). It then creates the Tree and sets it to be project-level. The OriginC code is below and a LabTalk example is after that. Read the comments for the OC function to understand what it returns.
In Code Builder, create an Origin C file called "make_proj_level_tree_var.c" in your UFF\OriginC folder and put the following code in the file.
// File name: make_proj_level_tree_var.c
#include <Origin.h>
#pragma labtalk(1)
/*
Function creates a new project-level Tree variable named after string parameter passed into function.
Returns 1 if the new Tree was created and added to the current project.
Returns 0 if there is already a project-level Tree variable with the desired name.
Returns -1 if strTreeName param isn't a valid variable name.
Returns -2 if the project-level Tree simply wasn't created (for another reason).
*/
int make_proj_level_tree_var(string strTreeName)
{
// Make sure the string param isn't empty.
// If empty, return -1.
if (0 == strTreeName.GetLength())
{
return -1;
}
// Make sure desired name is a valid name for a variable.
// If not, return -1.
if (!is_good_C_identifier(strTreeName))
{
return -1;
}
// See if a project-level Tree with the desired name already exists.
// If so, return 0.
TreeNode trTest1;
Project.GetTree(strTreeName, trTest1);
if(trTest1.IsValid())
{
return 0;
}
// Create a new Tree with the desired name and make it project-level.
Tree trNew;
trNew.SetAttribute(STR_LABEL_ATTRIB, strTreeName);
Project.AddTree(strTreeName, trNew);
// Test again to see if the new Tree was created and added to project.
// If not, return -2;
TreeNode trTest2;
Project.GetTree(strTreeName, trTest2);
if(!trTest2.IsValid())
{
return -2;
}
// Finally return 1 indicating sucess.
return 1;
}
LabTalk example:
// Compile the Origin C file
run.LoadOC("%YOriginC\make_proj_level_tree_var.c", 16);
// Now create the project-level Tree var
string strTreeName$ = "mytree";
int nRet = make_proj_level_tree_var(strTreeName$);
if (nRet < 0)
{
// Some sort of error in creating the Tree variable. See function documentation.
}
mytree.test$ = "It Works";
mytree.test$ = ;