Cancel
Showing results for 
Search instead for 
Did you mean: 
Highlighted

Teamcenter SOA: Folders traversal

Hello All,

 

I'm developing internal NXOpen application for NX managed mode.

NX 11, Teamcenter 11, Windows Server 2008 R2 Sp1.

 

I'm truing to get folder by path fron Home folder.

Sometimes it works well, but sometimes suddenly it stops work and fails without any explaination (I tried to cover it in try {} ).

I found out it crashes when my program meets Item instead of Folder on:

wo->get_object_type()

wo is WorkspaceObject. I also found out that I can call all methods of the root base class ModelObject, but not any other parent class' methods. For example it works well:

wo->getType()->getName()

which returns me "Item"

 

I absolutely dont have idea what is it... My code is below. Please help me...

 

 

#include <windows.h>
#include <stdio.h>

#include <teamcenter/soa/client/Connection.hxx>
#include <teamcenter/services/core/SessionService.hxx>
#include <teamcenter/services/core/_2007_01/Session.hxx>
#include <teamcenter/soa/client/model/Folder.hxx>
#include <teamcenter/soa/client/model/WorkspaceObject.hxx>

using namespace std;
using ::Teamcenter::Services::Core::SessionService;
using ::Teamcenter::Soa::Client::Model::WorkspaceObject;
using ::Teamcenter::Services::Core::_2007_01::Session;
using ::Teamcenter::Soa::Client::Model::Folder;

/* Recursive tree traversal to find folder */
Folder* _getFolder(Folder* folder, list<string> &path) {
	for (size_t i = 0; i < folder->count_contents(); i++)
	{
		WorkspaceObject* wo = folder->get_contents_at(i);
		if (wo->get_object_type() == "Folder") {
			Folder* f = dynamic_cast<Folder*>(wo);
			if (f->get_object_name() == path.front()) {
				path.pop_front();
				if (path.size() == 0) {	return f; }
				else {	return _getFolder(f, path); }
			}
		}
	}
	return NULL;
};

Folder* getFolder(Teamcenter::Soa::Client::Connection* tcSoaConnection, list<string> &path) {
	SessionService* sessionService = SessionService::getService(tcSoaConnection);
	Session::GetTCSessionInfoResponse sessionInfo = sessionService->getTCSessionInfo();
	Folder* folder = sessionInfo.user->get_home_folder();
	return _getFolder(folder, path);
}

 

 

3 REPLIES 3

Re: Teamcenter SOA: Folders traversal

Gears Esteemed Contributor Gears Esteemed Contributor
Gears Esteemed Contributor

Why does the folder path matter to you?

 

Note folders in TC are mere database constructs, folders do NOT "contain" items like they do in an OS.

They can be convenient for organization (e.g. when loading all the CAM templates into TC), but are not required.

 

Item "ABC123" could be in 6 different TC folders (copy -> paste -> paste -> paste...) - theya re all the SAME item (assuming you don't allow duplicate IDs... which assumes you CAN allow duplicate IDs... and is something I would suggest you NEVER do!)

 

Depending on how your TC is set up, you can have multiple folders with the same name, each containing different items.

 

You can ALWAYS access items *directly*, without knowing what folder(s) they are in.

 

I *believe* the only time folders may matter is for "admin" type objects (file -> new?, or whatever?) that should be in certain folders in the "InfoDBA" account's home folder...

Ken Akerboom Sr CAx Systems Engr, Moog, Inc.
Production: NX10.0.3.5 MP16/TC11.2
I'd rather be e-steamed than e-diseaseled


Re: Teamcenter SOA: Folders traversal

Ahh.. I know it.
But I have to put some created Item into folder. Just for representation, for see it in My Teamcenter. This is required for my task.

Re: Teamcenter SOA: Folders traversal

Solution:

 

Befor calling any properties of the object (pointer) you have to request this properties:

 

ServiceData sd = dmService->getProperties( { reinterpret_cast<ModelObject*>(wo) }, { "object_type", "object_name" });

after that you can call wo->get_object_type() or wo->get_object_name()