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
 Any way to loop over sub nodes of a tree variable?
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic Lock Topic Edit Topic Delete Topic New Topic Reply to Topic

Atedge

18 Posts

Posted - 05/08/2021 :  12:05:31 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 2021b (64-bit) 9.8.5.201
Operating System: Windows 10 20H2 (19042.928)
I've searched over labtalk documents and found that because of Tree not an Object, there are no methods for tree type variables, but both String and Datasets type have their Object Methods.
So is there any way to loop over a tree variable, or just list the sibling nodes so I can assign the output to a String Array then loop over it? For example:


tree root;
root.a1.b1.key="A";
root.a1.b2.key="B";
root.a1.b3.key="C";
root.a2.b4.key="D";
root.a2.b5.key="E";

I wanna get the value of the key corresponding to a? and b? in the tree, then I have to set three string arrays, and do two-level nested loops with a if/Switch condition like:

StringArray ary1,ary2,ary3;
ary1.Append("a1 a2");
ary2.Append("b1 b2 b3");
ary3.Append("b4 b5");

loop (ii,1,ary1.GetSize()) 
{
	string nn$,ax$=ary1.GetAt(ii)$;
	switch (ii)
	{
	case 1:
		nn$=2;
		break;
	case 2:
		nn$=3;
		break;
	}
	loop (jj,1,ary%(nn$).GetSize())
	{
		string bx$=ary%(nn$).GetAt(jj)$;
		string keyvalue$=root.%(ax$).%(bx$).key$;
		keyvalue$=;
	}
}

If there is a way to loop over a tree variable's sibling nodes at that level, the code will be more concise without that many ntermediate variables and conditional check.

YimingChen

1669 Posts

Posted - 05/10/2021 :  09:45:43 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
You will need to create an Origin C function which is callable from Labtalk. Check the page below on looping treenodes in Origin C.

https://www.originlab.com/doc/OriginC/ref/TreeNode-Children#Examples

James
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