How to access an adapter returned from user code

Ask general questions here.
mjonsson
Posts: 2
Joined: Mon Jul 01, 2019 5:17 pm

How to access an adapter returned from user code

Post by mjonsson » Mon Jul 01, 2019 5:27 pm

Hi,

The scenario is as follows:
I have created usercode to extract the correct TreeItem object from rawtext information. Now I want to return the TreeItem adapter from the usercode and execute a right-click operation on it outside of code. The returned TreeItem adapter is assigned to a variable, but no part of the repository. It seems I can only perform actions on repository items outside of code. How do I perform an action on the returned adapter object if it is not part of the repository?

Here is the usercode. The GetTreeItem function takes the rawtext regex as input, finds the TreeItem mapped to the rawtext element and returns the mapped TreeItem object. Problem is, how do I now perform actions on this returned TreeItem object from the UI?

Code: Select all

        private void GatherTreeItems(List<TreeItem> treeItemList, TreeItem treeItem)
        {
        	treeItemList.Add(treeItem);
        	
        	if (treeItem.Expanded)
        	{
	        	foreach (var childElem in treeItem.Children)
	        	{
	        		var childItem = childElem.Element.As<TreeItem>();
		        	GatherTreeItems(treeItemList, childItem);
	        	}
        	}
        }

        private TreeItem GetTreeItem(string treeLabel)
        {
        	List<RawText> rawTextList = new List<RawText>();
        	List<TreeItem> treeItemList = new List<TreeItem>();

        	var rawText = repo.Teamcenter.Self.FindSingle<RawText>(".//element[@instance='3']/element[@instance='1']/element[@instance='2']/element[@instance='0']//tree[@class='SysTreeView32']/rawtext[@rawtext~'" + treeLabel + "']");
        	var treeChildren = Tree.FromElement(rawText.Parent.Element).Children;
        	
       		foreach (var child in treeChildren)
        	{
       			if (child.Element.Role == Role.TreeItem)
        		{
       				GatherTreeItems(treeItemList, child.Element.As<TreeItem>());
        		}
       			else if (child.Element.Role == Role.Unknown && child.Element.FlavorName == "rawtext")
        		{
       				rawTextList.Add(child.As<RawText>());
        		}
        	}
       		
       		int index = rawTextList.IndexOf(rawTextList.Where(x => x.Row == rawText.Row).SingleOrDefault());
       		return treeItemList[index];
        }
I have a feeling I might have missed a fundamental piece here. Appreciate all help!

User avatar
Support Team
Site Admin
Site Admin
Posts: 11963
Joined: Fri Jul 07, 2006 4:30 pm
Location: Graz, Austria

Re: How to access an adapter returned from user code

Post by Support Team » Wed Jul 03, 2019 9:33 am

Hi,
"Now I want to return the TreeItem adapter from the usercode and execute a right-click operation on it outside of code"
This is not possible. You can't create or modify existing repo elements to be available to your UI within Ranorex Studio.

Sincerely,
Robert
.
Image

mjonsson
Posts: 2
Joined: Mon Jul 01, 2019 5:17 pm

Re: How to access an adapter returned from user code

Post by mjonsson » Thu Jul 04, 2019 8:25 am

So, the workaround I have done is to return the Location into a return variable and then use the location for further operations.

It would be nice to be able to return an Adapter into a variable and then perform operations on that variable instead of choosing Adapter from the repository. Alternatively, add repository items from user code.