The Origin Forum
File Exchange
Try Origin for Free
The Origin Forum
Home | Profile | Register | Active Topics | Members | Search | FAQ | Send File to Tech support
Username:
Password:
Save Password
Forgot your Password? | Admin Options

 All Forums
 Origin Forum for Programming
 LabTalk Forum
 XML Import via Origin C function
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic Lock Topic Edit Topic Delete Topic New Topic Reply to Topic

corei5

18 Posts

Posted - 01/25/2019 :  3:00:13 PM  Show Profile  Edit Topic  Reply with Quote  View user's IP address  Delete Topic
Origin Ver. and Service Release (Select Help-->About Origin): OriginPro 2018b b9.5.5.409
Operating System: Win 10 64-bit

I would like to import an XML file as a tree variable in Labtalk but I'm not able to access the tree variable I've made with an Origin C function. I have created the following Origin C function to import the XML:


void XML_load(string filename)
{
Tree trLoad(filename);
}


I can compile this code successfully and can run the C function in Labtalk with the following Labtalk script:

XML_load("C:\\Test.xml")

I would like to access the new tree variable "trLoad" in Labtalk but haven't any success. I'm new to programming (i.e., object oriented programming, etc.) which explains my difficulties with this relatively easy task. Please help.

Thanks!

Chris D

428 Posts

Posted - 01/25/2019 :  4:28:42 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Hi,

You may use Project::AddTree within your Origin C function to create a project-level Tree variable accessible from LabTalk using the name you assign the Tree to.

See:
https://www.originlab.com/doc/OriginC/ref/Project-AddTree

I'm not sure how well LabTalk will be able to deal with your particular XML though.

Note: it IS a project level variable and will be saved with the project. But this way works to get you the Tree.

I hope this helps!


Thanks,
Chris Drozdowski
Originlab Technical Support

Edited by - Chris D on 01/25/2019 4:29:53 PM
Go to Top of Page

corei5

18 Posts

Posted - 01/25/2019 :  4:59:06 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Thanks Chris!

So would my new Origin C function look like this?

void XML_load(string filename)
{
Tree trLoad(filename);
int TestTree = Project.AddTree(trLoad);
}

I must not have a clear understanding with Project.AddTree because I'm getting compile errors with the above function :(
Go to Top of Page

corei5

18 Posts

Posted - 01/25/2019 :  5:27:22 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
I think I have it now. The Origin C function should look like this:

void XML_load(string filename, string treename)
{
Tree trLoad(filename);
Project.AddTree(treename, trLoad);

}

where treename is the name of my new project level Labtalk tree and filename is the XML file I wish to import.

Then my Labtalk script would look like this:

XML_load("C:\\Test.xml", "NameOfMyLabtalkNewTree")
Go to Top of Page
  Previous Topic Topic Next Topic Lock Topic Edit Topic Delete Topic New Topic Reply to Topic
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
The Origin Forum © 2020 Originlab Corporation Go To Top Of Page
Snitz Forums 2000